SolidWorks API: translate assembly face selection to part document context

I want to build a SolidWorks macro that works from a pre-selection made in an assembly. The user first selects one or more faces on assembly components. The macro then iterates through that selection, opens each corresponding part document individually, and reselects the same face within the context of the now-open part document, so it can be used as a sketch plane.

What if the selected edge is not suitable for the sketch?

normally it will always be suitable for the sketch, but in case it is not we can just skip that face

So… Are you saying that you just want to hit a button and all the parts just open at the same time, each one with a face selected, and ready for the user to switch to that document and start a sketch?

Or are you wanting the macro to go one-by-one, opening one part, selecting the face, starting a sketch, and then waiting for the user to sketch something? Make a feature? Whatever? Before somehow indicating to the macro that it needs to proceed to the next component from the assembly?

There’s anywhere from a 5x to 15x multiplier on macro complexity between these two workflows….

the macro will open each part one by one, make the sketch (I made that part from the record macro function), save and close the part. Then go to the next part selected

So you want the macro to make the sketch, right? Like no user interaction from the start of the macro until it’s completely done processing all the selected components?

yes exactly,

The way I would approach:

Load up a couple of arrays/collections/dictionaries with the selected faces and their components (getselectedobject6 and getselectedobjectscomponent)

Iterate through the collections, opening each document using ActivateDoc on the component’s GetPathName.

Use GetCorresponding in the opened ModelDoc to get a pointer to the Face2 in the part that corresponds to the Face2 you saved earlier

Select the Face2 using Select4 and insert your sketch.

thank you, I was just looking at the collection method, I think it is the right method to use.