Constrain a part to an assembly level work axis

Top  Previous  Next

Here's how to create a workaxis at assembly level and constrain it to a hole.






This is the VB version, when I have time I'll do the C# version


Imports System.Runtime.InteropServices

Imports Inventor



Class MainWindow

   ' For this to work you need a part open in the assembly and the part needs to have a t least one hole in it

   Private Sub Button_Click(sender As Object, e As RoutedEventArgs)


       Dim ThisApp As Inventor.Application

       Dim oCylGeom As Cylinder

       Dim oWAxis As WorkAxis


       ' To get this you need .NET framework, not just .NET

       ThisApp = Marshal.GetActiveObject("Inventor.application")


       If ThisApp.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then

           MsgBox("An Assembly Document must be active for this to work. Exiting.", vbOKOnly + vbCritical, "WRONG DOCUMENT TYPE")

           Exit Sub

       End If



       Dim oADoc As AssemblyDocument = ThisApp.ActiveDocument

       Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition

       Dim oComp As ComponentOccurrence = oADef.Occurrences.Item(1)

       Dim oPDoc As PartDocument = oComp.Definition.Document

       Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition

       If oPDef.Features.HoleFeatures.Count = 0 Then

           MsgBox("No holes")

           Exit Sub

       End If


       Dim oHole As HoleFeature = oPDef.Features.HoleFeatures.Item(1)


       'oHole.HoleCenterPoints 'could likely use these too

       Dim oCylFace As Face = oHole.SideFaces.Item(1)

       If oCylFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then

           Dim oCylFaceProxy As FaceProxy = Nothing

           oComp.CreateGeometryProxy(oCylFace, oCylFaceProxy)

           oCylGeom = oCylFaceProxy.Geometry

           Dim oPoint As Inventor.Point = oCylGeom.BasePoint

           Dim oAxis As UnitVector = oCylGeom.AxisVector

           oWAxis = oADef.WorkAxes.AddFixed(oPoint, oAxis, False)

           oWAxis.Name = "ASM_WORK_AXIS"


           Dim oMConst1 As MateConstraint = oADef.Constraints.AddMateConstraint2(oWAxis, oCylFaceProxy, 0, InferredTypeEnum.kInferredLine, InferredTypeEnum.kInferredLine, MateConstraintSolutionTypeEnum.kAlignedSolutionType)

           oMConst1.Name = "ASM_WORK_AXIS_CONSTRAINT"



           MsgBox("Hole's first side face was not a Cylinder. Exiting.", , "")

           Exit Sub

       End If


   End Sub

End Class



So that workaxis is at assembly level but constrainted to a hole in a part. You can constrain further things to that workaxis...






Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)