Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro help - How to open a part from an assy?

Status
Not open for further replies.

MrMiller

Aerospace
Jan 30, 2004
54
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
 
Replies continue below

Recommended for you

I can only assume you are not using 2004.
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.
 
I'm very aware of the right click option....this macro will be doing much more than just opening the part. There is a series of autoclicks, field entries, and if/then statements after opening the part. Opening the part in this manner is a small part of the entire macro program.

 
I'm crashing before the activateDoc2 statement. I'm crashing on this line and get this error

Set owningComponent = selComp.GetComponent

Error Statement
Object doesn't support this property or method.
 
>>Set selComp = swSelMgr.GetSelectedObjectsComponent2(1)

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

 
Thanks rocheey -

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)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor