pyroclasm
Computer
- May 17, 2005
- 24
Hey Guys,
I'm working with SW2006. I created a macro on a button in SolidWork to traverse through already open documents, while collecting info on them. My form is actually a lot more complicated than this one, but this form illustrates my problem the easiest. My problem is that when I press the Next command button on my form, if an Assembly is open, it will open ALL the components of that Assembly, making them all visible. I don't want that, I want only the open/visible documents to be traversed. I know Assembly components are open in memory but aren't visible. If I have 3 part, 1 drawing, and 1 Assembly document, then when I traverse through and get to that Assembly, BOOM...all of its components are visible and instead of traversing through 5 documents, I'm traversing through hundreds.
On my form I have 2 Labels, 2 TextBoxes (txtTitle, txtType), and 1 Command Button (btnNext).
EXAMPLE OF MY FORM:
---------------------------------------------------------------
| MY FORM |
---------------------------------------------------------------
| |
|ACTIVE COMPONENT: Example.SLDPRT |
| |
|TYPE: Part (SLDPRT) |
| ___________________ _ |
| | GET NEXT COMPONENT | |
| ------------------------------- |
| |
----------------------------------------------------------------
I'm working with SW2006. I created a macro on a button in SolidWork to traverse through already open documents, while collecting info on them. My form is actually a lot more complicated than this one, but this form illustrates my problem the easiest. My problem is that when I press the Next command button on my form, if an Assembly is open, it will open ALL the components of that Assembly, making them all visible. I don't want that, I want only the open/visible documents to be traversed. I know Assembly components are open in memory but aren't visible. If I have 3 part, 1 drawing, and 1 Assembly document, then when I traverse through and get to that Assembly, BOOM...all of its components are visible and instead of traversing through 5 documents, I'm traversing through hundreds.
On my form I have 2 Labels, 2 TextBoxes (txtTitle, txtType), and 1 Command Button (btnNext).
EXAMPLE OF MY FORM:
---------------------------------------------------------------
| MY FORM |
---------------------------------------------------------------
| |
|ACTIVE COMPONENT: Example.SLDPRT |
| |
|TYPE: Part (SLDPRT) |
| ___________________ _ |
| | GET NEXT COMPONENT | |
| ------------------------------- |
| |
----------------------------------------------------------------
Code:
'GLOBAL VARIABLES
Dim swApp As SldWorks.SldWorks
Dim swModelDoc As SldWorks.ModelDoc2
Dim strDocType(1 To 3) As String
'END GLOBAL VARIABLES
Private Sub btnNext_Click()
Set swModelDoc = swModelDoc.GetNext
'check if there is a next document
If swModelDoc Is Nothing Then
'If no more documents, start from first document again.
Set swModelDoc = swApp.GetFirstDocument
swDocUpdate
Else 'display next document
swDocUpdate
End If
End Sub
Private Sub UserForm_initialize()
checkActiveDocType
End Sub
Sub checkActiveDocType()
'get SolidWorks
Set swApp = Application.SldWorks
'get first document
Set swModelDoc = swApp.GetFirstDocument
'check for active doc
If swModelDoc Is Nothing Then
MsgBox "No active documents."
'no sense to go on - end macro
End
End If
'initilize doc types
strDocType(1) = "Part (SLDPRT)"
strDocType(2) = "Assembly (SLDASM)"
strDocType(3) = "Drawing (SLDDRW)"
'display first document
swDocUpdate
End Sub
Sub swDocUpdate()
Dim ActivateErrors As Long
'make document active
swApp.ActivateDoc2 swModelDoc.GetTitle, True, ActivateErrors
'add check of ActivateErrors here
'get doc type
txtType.Text = strDocType(swModelDoc.GetType)
'get doc title
txtTitle.Text = swModelDoc.GetTitle
End Sub