Select XY plane of activeeditobject

Select XY plane of activeeditobject

CadUser46
Collaborator Collaborator
1,194 Views
2 Replies
Message 1 of 3

Select XY plane of activeeditobject

CadUser46
Collaborator
Collaborator

This works as expected when i have just a part file open but when it's a child that is the activeedit within an assembly it does not  select the workplane of the child.

 

I have tried activedocument.selectset and activeobject.selectset but neither works.  I dont think im understanding which object currently controls the select set in this instance.

 

Public Sub CreateSketch()
    
    'Get a hook to the application.
    Dim invApp As Inventor.Application: Set invApp = ThisApplication
    
    '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

    'Check for features.  If there are any features the exit from the sub.
    If odoc.ComponentDefinition.Features.Count > 0 Then Exit Sub
    
    'Lookat XY Plane  
    Dim oWP As WorkPlane: Set oWP = odoc.ComponentDefinition.WorkPlanes("XY Plane")
    odoc.SelectSet.Clear
    odoc.SelectSet.Select oWP
    invApp.CommandManager.ControlDefinitions.Item("AppLookAtCmd").Execute
    odoc.SelectSet.Clear
        
    'Create a sketch on XY, name it and make it ready for use.
    Dim oSketch As PlanarSketch: Set oSketch = odoc.ComponentDefinition.Sketches.Add(odoc.ComponentDefinition.WorkPlanes("XY Plane"), False)
    'oSketch.Name = "Sketch" & CStr(oDoc.ComponentDefinition.Sketches.Count)
    oSketch.Edit
    
    'Project the origin centre point.  Even having the App Options set will not create it.
    Dim oOriginSketchPoint As SketchPoint: Set oOriginSketchPoint = oSketch.AddByProjectingEntity(odoc.ComponentDefinition.WorkPoints("Center Point"))
    
    'Activate the model browser.
    odoc.BrowserPanes("Model").Activate

End Sub

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes
Accepted solutions (1)
1,195 Views
2 Replies
Replies (2)
Message 2 of 3

wayne.brill
Collaborator
Collaborator
Accepted solution

Hi,

 

I am able to recreate the behavior as you descirbe. A solution is to use a WorkPlaneProxy and select that at the assembly level. Below is a VBA example I used to test it.

 

I also created this DevBlog post:

http://adndevblog.typepad.com/manufacturing/2016/02/need-to-use-a-proxy-for-commands-when-editing-a-...

 

 


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
    oAsm.SelectSet.Select oWorkPlaneProxy
     
    ' Run the command it will use the selected work plane (a proxy
    ThisApplication.CommandManager.ControlDefinitions.Item("AppLookAtCmd").Execute

End Sub

 

Thanks,

Wayne

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 3 of 3

CadUser46
Collaborator
Collaborator

Thanks Wayne.  I like to ask the tricky questions 🙂  Just got around to confirming it now.


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes