cadnutcase
Mechanical
- Apr 27, 2005
- 101
I am giving a shot at this API stuff and so far really like it but I am having a hard time with the following.
I want to open up each part file no matter how deep an a assembly file. Run a special macro that I have, and then close the file.
I am using the traverse assembly macro out of the help section, and I put a line in there for I want to open the part file (I think it is in the right place).
What am I missing here?
'Make All Assembly Components Visible Example (VB)
'This example shows how to make all assembly components visible.
'---------------------------------------
'
' Preconditions: An assembly document is open.
'
' Postconditions: Any hidden assembly components are made visible.
'
'---------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swPart As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Dim Indent As Long
Sub TraverseComponent(swComp As SldWorks.Component2, nLevel As Long)
Dim vChildCompArr As Variant
Dim vChildComp As Variant
Dim swChildComp As SldWorks.Component2
Dim swCompConfig As SldWorks.Configuration
Dim sPadStr As String
Dim i As Long
For i = 0 To nLevel - 1
sPadStr = sPadStr + " "
Next i
vChildCompArr = swComp.GetChildren
For Each vChildComp In vChildCompArr
Set swChildComp = vChildComp
Debug.Print sPadStr & swChildComp.Name2 & " <" & swChildComp.ReferencedConfiguration & ">"
' Right here is where I want to open the part file and run my other macro
TraverseComponent swChildComp, nLevel + 1
Next
End Sub
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssy As SldWorks.AssemblyDoc
Dim swConf As SldWorks.Configuration
Dim swRootComp As SldWorks.Component2
Dim bRet As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swConf = swModel.GetActiveConfiguration
Set swRootComp = swConf.GetRootComponent
Debug.Print "File = " & swModel.GetPathName
TraverseComponent swRootComp, 1
End Sub
I want to open up each part file no matter how deep an a assembly file. Run a special macro that I have, and then close the file.
I am using the traverse assembly macro out of the help section, and I put a line in there for I want to open the part file (I think it is in the right place).
What am I missing here?
'Make All Assembly Components Visible Example (VB)
'This example shows how to make all assembly components visible.
'---------------------------------------
'
' Preconditions: An assembly document is open.
'
' Postconditions: Any hidden assembly components are made visible.
'
'---------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swPart As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Dim Indent As Long
Sub TraverseComponent(swComp As SldWorks.Component2, nLevel As Long)
Dim vChildCompArr As Variant
Dim vChildComp As Variant
Dim swChildComp As SldWorks.Component2
Dim swCompConfig As SldWorks.Configuration
Dim sPadStr As String
Dim i As Long
For i = 0 To nLevel - 1
sPadStr = sPadStr + " "
Next i
vChildCompArr = swComp.GetChildren
For Each vChildComp In vChildCompArr
Set swChildComp = vChildComp
Debug.Print sPadStr & swChildComp.Name2 & " <" & swChildComp.ReferencedConfiguration & ">"
' Right here is where I want to open the part file and run my other macro
TraverseComponent swChildComp, nLevel + 1
Next
End Sub
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssy As SldWorks.AssemblyDoc
Dim swConf As SldWorks.Configuration
Dim swRootComp As SldWorks.Component2
Dim bRet As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swConf = swModel.GetActiveConfiguration
Set swRootComp = swConf.GetRootComponent
Debug.Print "File = " & swModel.GetPathName
TraverseComponent swRootComp, 1
End Sub