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"
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.