[Solidworks API] Parent assembly name as in BOM

Hello

I have some knowledge of VBA but I'm new to the Solidworks API and I have to modify a colleague's macro, launched in a drawing with a selected component.

Here's what seems to me to be the problem with the code:

swEnt = swSelMgr.GetSelectedObject5(iSel)

swSelComp = swEnt.GetComponent

swSelModel = swSelComp.GetModelDoc

Name = swSelModel. GetTitle

Name then contains the name of the selected part, where I would like to return the name of its parent assembly, as solid does very well for the BOM.

I specify that the code works when the configurations of the assembly are set as follows:

Viewing child components used as subassembly: "show"

and that we want to modify it so that it also works when we set to "hide"

 

Thank you for any help you can give me! 

Wrong answer...

Please put the code in full, it's easier to understand even if in the text you only talk about a part.

But indeed this is not the part that concerns your request. (You get the name of the selected part in the assembly)

The full code is several thousand lines long, but this part is independent, I just cut a few previous lines that deal with multiple selections. 

Just after the copied passage, we compare the value of the variable name with each designation in the nomenclature. And of course, since the BOM only shows the name of the parent assembly, everything stops. 

If I understand your answer sbadenis correctly, as long as the child components are hidden in the configuration of my assembly, no method applied to swSelModel will be able to "go up" to properties of the parent? 

I was looking for a kind of swSelModel."GetParent", which would allow me to fall back to the properties of the upper assembly as in my nomenclature. 

When the children are shown in the config properties, when I click on the same part of the MEP, it returns the name of the parent assembly.

I didn't specify it, but the property is not directly checked in the property tab, we drive the value of $JAMAIS_DEVELOPPER_IN_NOMENCLATURE by the part family.  It's Y or N from what I see in the API help; There doesn't seem to be a value to switch to "promote", which I haven't tested as a result. 

 

 

 

 

If you want a 'GetParent':

 

http://help.solidworks.com/2018/english/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IComponent2~GetParent.html

1 Like

Thank you mandrake!  I tested but it doesn't progress. 

Set swParentComp = swSelComp.GetParent

Set swSelModel2 = swParentComp.GetModelDoc

 Name = swSelModel2.GetTitle

But name still contains the name of the part, as if the GetParent didn't exist (it doesn't return NULL though) 

 

What if you go directly to Name = swParentComp.GetTitle ?

 

You have all the component/parent info here you should be able to find what you are looking for, there is also the configuration management.

http://help.solidworks.com/2018/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.iconfiguration~getrootcomponent3.html

1 Like

Thanks Mandragore, I ended up getting the GetParent to work, in one step:

Name = swSelComp.GetParent.GetModelDoc.GetTitle

The first part alone, swSelComp.GetParent, was a problem for me, probably because of type declaration issues.

 

Perfect! Personally, I avoid using selection before an action. The software knows where it is in theory, it avoids unnecessary lines I think. 

 

Finally I haven't done a lot of APIs on solidworks I mostly do reassembly or some file management. I don't read or write for the nomenclatures.