Hi everyone,
I have a main assembly that contains 2 sub-assemblies. Each one of these sub-assemblies contains the same component among others. I would like to get the name of that component so that I can suppress it or not depending on the design, or selecting one of its configurations. I like to use the GetComponentByName command for ease of my excel VBA program reading. For some reason, I am not able to get the name correctly. I have tried "component's name-instance@sub-assembly's name-instance" in the GetComponentByName command without any success. Same thing for sub-assembly's name-instance/component's name-instance... I realized that when the component is assembled only once in the whole assembly (no matter where...but only once!), I can get the component's name withe a basic GetComponentByName ("component's name-instance").
Anybody could help me?
Greg. Can I call you Greg? Buddy. Pal.
It don't work. You're doing it wrong. There is no correct syntax for using GetComponentByName to get non-top-level components. You can't get there from here. Do not pass GO. Do not collect $200.
The fact that it does work for you sometimes when there's only one instance of your subassembly is irrelevant. The Help states that GetComponentByName is only intended for top level components.
If you want to keep doing it wrong, by all means pursue the dream of using GetComponentByName. You shall overcome! (Except you won't.)
Alternately, if you want to do it right, add a few more lines.
Dim aComps As Variant
Dim i As Long
aComps = Part.GetComponents(False)
For i = 0 To UBound(aComps)
Set swComp = aComps(i)
If swComp.Name2 = "[name of top-level component]-[instance number]/[name of child component]-[instance number]" Then Exit For
Next i
But once again... What do I know. I've only been writing SolidWorks code for 15 years.