Macro help - How to open a part from an assy?
Macro help - How to open a part from an assy?
(OP)
Does anyone know the code to open a part from an assembly by selecting the part under the assembly tree. This is the code I have now and it doesn't work. I have this similar code to open the part by selecting a face, edge or vertex and it works for those selected items.
If (selType = swSelCOMPONENTS) Then
Set selComp = swSelMgr.GetSelectedObjectsComponent2(1)
Set owningComponent = selComp.GetComponent
strmodel = owningComponent.GetPathName
Set swModel = swApp.ActivateDoc2(strmodel, True, 0)
strModelName = owningComponent.Name
End If
If (selType = swSelCOMPONENTS) Then
Set selComp = swSelMgr.GetSelectedObjectsComponent2(1)
Set owningComponent = selComp.GetComponent
strmodel = owningComponent.GetPathName
Set swModel = swApp.ActivateDoc2(strmodel, True, 0)
strModelName = owningComponent.Name
End If






RE: Macro help - How to open a part from an assy?
If you are then all you have to do is RMB click on the part, in the tree or in the graphics area doesn't matter. You should see a list of options and open part will be one of them.
RE: Macro help - How to open a part from an assy?
RE: Macro help - How to open a part from an assy?
RE: Macro help - How to open a part from an assy?
Set owningComponent = selComp.GetComponent
Error Statement
Object doesn't support this property or method.
RE: Macro help - How to open a part from an assy?
Assuming you dimmed "selComp" as a component or component2,
just use "GetSelectedObjects"- are you trying to the the component of a component ?
>> Set owningComponent = selComp.GetComponent
>> strmodel = owningComponent.GetPathName
>>Set swModel = swApp.ActivateDoc2(strmodel, True, 0)
If any of the instances of the component are NOT suppressed
in the assembly, and it is not loaded lightweight, then the model is already loaded.
Just use Component.GetModelDoc to get the Model Object
>>strModelName = owningComponent.Name
RE: Macro help - How to open a part from an assy?
Here is what I ended up doing and it works. I think I had this before but it wasn't working becuase my test part was lightweight. Once I put the setsuppression(2)line in it worked fine every time.
Set selComp = swSelMgr.GetSelectedObjectsComponent2(1)
selComp.SetSuppression (2)
strmodel = selComp.GetPathName
Set swModel = swApp.ActivateDoc2(strmodel, True, 0)