dogarila
Mechanical
- Oct 28, 2001
- 594
This is what I am trying to do:
1) Open a drawing in SW.
2) Run a macro/program
3) The macro will determine the solid model used to create the drawing, will load and activate the model, will read the
custom properties from the model, will reactivate the drawing and will write the custom properties into the drawing.
I have difficulties in opening the model. The code I wrote looks like this:
Dim swApp As Object
Dim Part As Object
Dim retval As Boolean
Dim view0 As Object
Dim view1 As Object
Dim Part1 As Object
Set swApp = CreateObject("SldWorks.Application"
Set Part = swApp.ActiveDoc
'Form1.Height = 4400
If Part Is Nothing Then
msg = "A SolidWorks document needs to be loaded!"
Style = vbExclamation ' Error style dialog
Titlemsg = "Model Properties" ' Define title
Call MsgBox(msg, Style, Titlemsg) ' Display error message
returnOK = False
swApp.Visible = True
End ' If no model currently loaded, then exit
Else
docType = Part.GetType
End If
.....................
.....................
.....................
If (docType = swDocDRAWING) Then
'If doc is drawing then activate model and read properties from there
dwgdoc = Part.GetTitle()
Set view0 = Part.GetFirstView()
Set view1 = view0.GetNextView()
modelname = view1.GetReferencedModelName()
'this is the line where I get a type mismatch error
retval1 = swApp.ActivateDoc2(modelname, True, Error)
Set Part1 = swApp.ActiveDoc
.........................
.........................
.........................
'reactivate drawing
Part = swApp.ActivateDoc2(dwgdoc, True, Error)
Else
.........................
.........................
.........................
End If
I used ........ for lines that are not related to this problem.
The SolidWorks API help for the line with type mismatch problem says:
=========================================================
Description
This function activates a document which has already been loaded. This file becomes the active document and this method returns a pointer to that document object.
Syntax (OLE Automation)
retval = SldWorks.ActivateDoc2 ( name, silent, &errors )
Input:
(BSTR) name
Name of document to activate
Input:
(BOOL) silent
True if dialogs and warning messages should be avoided, False if dialogs and warning messages should be displayed to the user.
Output:
(long) errors
Status of the document activate operation, refer to the swActivateDocError_e enumeration. If no errors or warnings were encountered, this value will be set to 0.
Return:
(LPDISPATCH) retval
Pointer to a dispatch object, the document
==========================================================
What do I have to do to get this program running?
Andrew (Netshop21)
1) Open a drawing in SW.
2) Run a macro/program
3) The macro will determine the solid model used to create the drawing, will load and activate the model, will read the
custom properties from the model, will reactivate the drawing and will write the custom properties into the drawing.
I have difficulties in opening the model. The code I wrote looks like this:
Dim swApp As Object
Dim Part As Object
Dim retval As Boolean
Dim view0 As Object
Dim view1 As Object
Dim Part1 As Object
Set swApp = CreateObject("SldWorks.Application"
Set Part = swApp.ActiveDoc
'Form1.Height = 4400
If Part Is Nothing Then
msg = "A SolidWorks document needs to be loaded!"
Style = vbExclamation ' Error style dialog
Titlemsg = "Model Properties" ' Define title
Call MsgBox(msg, Style, Titlemsg) ' Display error message
returnOK = False
swApp.Visible = True
End ' If no model currently loaded, then exit
Else
docType = Part.GetType
End If
.....................
.....................
.....................
If (docType = swDocDRAWING) Then
'If doc is drawing then activate model and read properties from there
dwgdoc = Part.GetTitle()
Set view0 = Part.GetFirstView()
Set view1 = view0.GetNextView()
modelname = view1.GetReferencedModelName()
'this is the line where I get a type mismatch error
retval1 = swApp.ActivateDoc2(modelname, True, Error)
Set Part1 = swApp.ActiveDoc
.........................
.........................
.........................
'reactivate drawing
Part = swApp.ActivateDoc2(dwgdoc, True, Error)
Else
.........................
.........................
.........................
End If
I used ........ for lines that are not related to this problem.
The SolidWorks API help for the line with type mismatch problem says:
=========================================================
Description
This function activates a document which has already been loaded. This file becomes the active document and this method returns a pointer to that document object.
Syntax (OLE Automation)
retval = SldWorks.ActivateDoc2 ( name, silent, &errors )
Input:
(BSTR) name
Name of document to activate
Input:
(BOOL) silent
True if dialogs and warning messages should be avoided, False if dialogs and warning messages should be displayed to the user.
Output:
(long) errors
Status of the document activate operation, refer to the swActivateDocError_e enumeration. If no errors or warnings were encountered, this value will be set to 0.
Return:
(LPDISPATCH) retval
Pointer to a dispatch object, the document
==========================================================
What do I have to do to get this program running?
Andrew (Netshop21)