Hi Drew Miller,
I tried using the macro recorder and got some code that I stripped down and slightly modified to what is needed.
The code requires a assembly name with Assem1 and a virtual part with name Part1^Assem1. In the virtual part there is an existing sketch with name Sketch1. Note that the SelectByID2 uses the instance of the component as well for selection, hence the added -1 to the virtual part name.
Hope this helps you to get forward. There might be other options as going down the road with the IModelDoc2 for the virtual part, but this looks to be a quite straight forward way.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim boolstatus As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
boolstatus = swModel.Extension.SelectByID2("Sketch1@Part1^Assem1-1@Assem1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
Dim skSegment As Object
Set skSegment = swModel.SketchManager.CreateCircle(-0#, 0#, 0#, 0.00634, 0.013022, 0#)
Thanks, that worked. I was making it more difficult than necessary- I was thinking that you needed to edit the modeldoc2 of the part, but you are actually editing the modeldoc2 of the assembly after the in context part is activated.
Found this in the api help:
'Re: GetEditTarget: This method is useful when the user is performing an in-context edit of a part component because the currently active document returned from ISldWorks::ActiveDoc might not be the document that the user is editing. For example, the user can use in-context editing to modify an assembly component. The active document is the assembly, but this method returns the IModelDoc2 for the component being edited.
'The IModelDoc2 object returned by this method might be that of the assembly if no part is being in-place edited. In other words, this method returns a valid pointer (non-NULL) even when user is not editing a part in-context.
'You can use the IModelDoc2 object returned by this method to determine which assembly component is being edited in-context. In general, you should not use this IModelDoc2 object for feature creation within the component part. Feature creation typically requires the IModelDoc2 of the active document. During feature creation, SolidWorks automatically determines whether the feature should be created and owned by the active assembly, or if it is an in-context edit in which the feature should be created and owned by the component part.
Appreciate your help