Hi API gurus,
I was creating this tiny VBA code that transverse through all the parts in assembly (Current active, opened assembly) and make them as virtual components.
If there is sub assembly inside the main assembly, it'll make it as virtual component and the loop through it to make its parts virtual.
I was able to make the pars and sub-assemblies in first layer as virtual components.
I'm having having trouble to set the components in layer 2,3++ that belong to sub-assemblies as virtual components.
But my function can loop through it.
Any help will be highly appreciated
<p>Option Explicit</p><p></p><p></p><p>Dim swApp As SldWorks.SldWorks</p><p>Dim swAssembly As SldWorks.AssemblyDoc</p><p>Dim swModel As SldWorks.ModelDoc2</p><p>Dim swConfig As SldWorks.Configuration</p><p>Dim swRootComp As SldWorks.Component2</p><p></p><p></p><p>Dim n As Long</p><p></p><p></p><p></p><p></p><p>Sub TraverseComponent(swComp As SldWorks.Component2)</p><p> Dim vChildComp As Variant</p><p> Dim swChildComp As SldWorks.Component2</p><p> Dim swCompModel As ModelDoc2</p><p> Dim swCompConfig As SldWorks.Configuration</p><p> Dim sPadStr As String</p><p> Dim i As Long</p><p> Dim stat As Boolean</p><p> </p><p> vChildComp = swComp.GetChildren</p><p> For i = 0 To UBound(vChildComp)</p><p> Set swChildComp = vChildComp(i)</p><p> </p><p> Set swCompModel = swChildComp.GetModelDoc2</p><p> 'Debug.Print swChildComp.Name</p><p> If swCompModel.Extension.ToolboxPartType = 0 Then</p><p> stat = swChildComp.MakeVirtual</p><p> Debug.Print swChildComp.Name</p><p> End If</p><p> </p><p> TraverseComponent swChildComp</p><p> </p><p> </p><p> </p><p> Next i</p><p>End Sub</p><p></p><p></p><p>Sub main()</p><p> </p><p> Dim swApp As SldWorks.SldWorks</p><p> Dim swModel As SldWorks.ModelDoc2</p><p> Dim swAssy As SldWorks.AssemblyDoc</p><p> Dim swConf As SldWorks.Configuration</p><p> Dim swRootComp As SldWorks.Component2</p><p> Dim i As Long</p><p> </p><p> Set swApp = CreateObject("SldWorks.Application")</p><p> Set swModel = swApp.ActiveDoc</p><p> Set swConf = swModel.GetActiveConfiguration</p><p> Set swRootComp = swConf.GetRootComponent3(True)</p><p> </p><p> TraverseComponent swRootComp</p><p> </p><p>End Sub</p>Thanks,
SolidworksApi macros