SelectByID2 : retrieve ID from selected component

I am using selectByID2 to add mates in the top level assembly. I select two entites in the graphics area or model tree and get their component using

swEntity := SelMgr.GetSelectedObject6(1, 0)
swComponentA := swEntity.GetComponent
'or  
swComponentA := SelMgr.GetSelectedObject6(1, 0)

swEntity := SelMgr.GetSelectedObject6(2, 0)
swComponentB := swEntity.GetComponent
'or  
swComponentB := SelMgr.GetSelectedObject6(2, 0)

Then I use selectByID2 to grab each primary plane from the two components and add a mate between them.

Currently I am hard coding the format of the ID because this macro is used on assemblies where the file structure is known. Now I want to generalize my program for any assembly structure.
How can I build or get the ID of swComponentA with respect to the top assembly for use in SelectByID2? The macro recorder gives something like this

boolstatus = Part.Extension.SelectByID2("Right Plane@HMC-ADPT1200-NB-1-1@HMC-ADPT1200-1/HMC-PLCD-539-3@HMC-ADPT1200-NB-1", "PLANE", -9.84228209404137E-05, 1.09972117172674E-04, -0.154934245329059, True, 0, Nothing, 0)

Eventually I want to be able to specify a feature in swComponentA to use during mating in a loop.
Example: myFeature would be all three primary planes.

id = myFeature & "@HMC-ADPT1200-NB-1-1@HMC-ADPT1200-1/HMC-PLCD-539-3@HMC-ADPT1200-NB-1"

Hi colt

I would look at selecting directly with the appropriate method.

Here’s some code I wrote the other day that mates a component plane to an assembly plane and then mates the component origin to a sketch point - not a selectbyid2 in sight :wink:
image.png
I’m still a bit new to this but I believe you need to make sure that you have the correct object.
Artem has a great post on this https://www.codestack.net/solidworks-api/document/selection/
You should also check out this one https://www.codestack.net/solidworks-api/document/assembly/context/

I have to agree with Rob that SelectByID2 is the least robust way to make a selection.

This has always been a helpful site for me since Artem has put together so many useful examples:
https://www.codestack.net/solidworks-api/document/selection/

If only the macro recorder spit out code that was that useful