Need to use a Proxy for commands when editing a part in an assembly

By Wayne Brill

In the VBA example below a work plane in a part document is accessed and then the AppLookAtCmd is run. (changes the view to look directly at that WorkPlane)

To get AppLookAtCmd to use that WorkPlane it needs to be selected using the SelectSet of the assembly. (not the part) To get the WorkPlane in the assembly space use a WorkPlaneProxy. To create the WorkPlaneProxy use the ActiveOccurrence property of the assembly to get the occurrence of the part that is being edited and then use the CreateGeometryProxy method of the occurrence.   

Before running this example place a part in an assembly and then right click on the part in the Model browser and select Edit.

<

p style=”font-size: 9pt;font-family: arial;background: #eeeeee;color: black;line-height: 140%”>Public Sub selectionTest()
     ‘Get the object currently being edited.
    Dim ActiveObject As Object
    Set ActiveObject = ThisApplication.ActiveEditObject
   
    ‘Determine if a the object being edited is a document
    If Not TypeOf ActiveObject Is PartDocument Then
        Exit Sub
    Else
       Dim oDoc As Inventor.PartDocument
       Set oDoc = ActiveObject
    End If
   
    ‘Get the XY Plane of the part being edited
    Dim oWorkPlane As WorkPlane
    Set oWorkPlane = oDoc.ComponentDefinition.WorkPlanes(“XY Plane”)
     
   ‘Get the active document (an assembly)
    Dim oAsm As AssemblyDocument
    Set oAsm = ThisApplication.ActiveDocument
   
    ‘ The part that is being edited will be an occurrence
    Dim oOccurrence As ComponentOccurrence
    Set oOccurrence = oAsm.ComponentDefinition.ActiveOccurrence
   
    ‘ create a WorkPlaneProxy from the work plane in the part
    Dim oWorkPlaneProxy As WorkPlaneProxy
    oOccurrence.CreateGeometryProxy oWorkPlane, oWorkPlaneProxy
   
   ‘ Select the WorkPlaneProxy in the assembly
    oAsm.SelectSet.Select oWorkPlaneProxy
    
    ‘ Run the command it will use the work plane (a WorkPlaneProxy)
    ThisApplication.CommandManager.ControlDefinitions.Item(“AppLookAtCmd”).Execute
End Sub


Comments

One response to “Need to use a Proxy for commands when editing a part in an assembly”

  1. Hi, this is very important things you are saying on appllock assembly. This is code which is i am looking for on internet.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading