Adding work planes in an Assembly document

By Vladimir Ananyev

Issue

I need to create a work plane in the Assembly document. I have tried using AddByPlaneAndOffset and other methods however an error occurs. Is there a way to add a work plane programmatically to the assembly document?

Solution

The only add method that is supported for work features in the assembly document is the AddFixed (this is true for all work feature types). The resulting work plane will return an AssemblyWorkPlaneDef definition. Work plane position can be changed by assembly constraints. We do not currently support (and there are currently no plans to support) the other methods in assembly.

This VBA example creates a work plane on the same plane as the YZ plane in the second part placed in the assembly.

Public Sub AddWorkPlaneInAssembly()
   
    Dim oAsmDoc As AssemblyDocument
    Set oAsmDoc = ThisApplication.ActiveDocument
   
    Dim oAsmCompDef As AssemblyComponentDefinition
    Set oAsmCompDef = oAsmDoc.ComponentDefinition
   
    Dim oOcc As ComponentOccurrence
    Set oOcc = oAsmCompDef.Occurrences(2)
   
    Dim oPartDef As PartComponentDefinition
    Set oPartDef = oOcc.Definition
   
    Dim oWrkPlane1 As WorkPlane
    Set oWrkPlane1 = oPartDef.WorkPlanes(1)
   
    Dim oWrkPlane1Proxy As WorkPlaneProxy
    Call oOcc.CreateGeometryProxy( _

           oWrkPlane1, oWrkPlane1Proxy)
    Dim oOriginPnt As Point
    Dim oXaxis As UnitVector
    Dim oYaxis As UnitVector
    Call oWrkPlane1Proxy.GetPosition( _

           oOriginPnt, oXaxis, oYaxis)
   
    Dim oWrkPlane As WorkPlane
    Set oWrkPlane = oAsmCompDef.WorkPlanes _

         .AddFixed(oOriginPnt, oXaxis, oYaxis)
End Sub

 

 

VB .NET:

 

Public Sub AddWorkPlaneInAssembly()

 

   Dim oAsmDoc As AssemblyDocument _

      = m_inventorApp.ActiveDocument

 

   Dim oAsmCompDef As AssemblyComponentDefinition _

      = oAsmDoc.ComponentDefinition

 

   Dim oOcc As ComponentOccurrence _

         = oAsmCompDef.Occurrences(2)

 

   Dim oPartDef As PartComponentDefinition _

         = oOcc.Definition

 

   Dim oWrkPlane1 As WorkPlane _

         = oPartDef.WorkPlanes(1)

 

   Dim oWrkPlane1Proxy As WorkPlaneProxy = Nothing

   Call oOcc.CreateGeometryProxy( _

          oWrkPlane1, oWrkPlane1Proxy)

 

   Dim oOriginPnt As Inventor.Point = Nothing

   Dim oXaxis As UnitVector = Nothing

   Dim oYaxis As UnitVector = Nothing

   Call oWrkPlane1Proxy.GetPosition( _

          oOriginPnt, oXaxis, oYaxis)

 

   Dim oWrkPlane As WorkPlane _

        = oAsmCompDef.WorkPlanes.AddFixed _

            (oOriginPnt, oXaxis, oYaxis) 

End Sub

 

<

p style=”line-height: normal;margin: 0cm 0cm 0pt” class=”MsoNormal”> 


Comments

One response to “Adding work planes in an Assembly document”

  1. Hi Vladimir – very interesting. Do you think it is possible to select a component in an assembly and place all mid planes (means between all 3 faces) automatically? Is it possible as well to select one or more components and do same? Thanks for your support.

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading