Get the axis of a cylinder part

Get the axis of a cylinder part

dialunau
Advocate Advocate
706 Views
2 Replies
Message 1 of 3

Get the axis of a cylinder part

dialunau
Advocate
Advocate

Hello, I've been trying to get the axis of a cylinder inside an insert constraint. The problem is that ilogic doesn't recognize the axis of the cylinder as a work feature, so I can't get access to it with the method I'm trying to use.

Does anyone know how to solve this?

My code looks like this:

Dim oAssy As AssemblyDocument = ThisApplication.ActiveDocument

Dim oDef As AssemblyComponentDefinition
oDef = oAssy.ComponentDefinition

Dim oCons As AssemblyConstraint
oCons = oDef.Constraints.Item("Insert:1")

Dim oEnt As Object
oEnt = oCons.EntityOne

Dim oAxis As WorkAxis

If (TypeOf oEnt Is WorkAxis) = True Then
	oAxis = oEnt
	MsgBox("Entity one is the cylinder axis")
End If

 

0 Likes
Accepted solutions (1)
707 Views
2 Replies
Replies (2)
Message 2 of 3

J-Camper
Advisor
Advisor

I think InsertConstraint Entities are Circular Edges, so you could look through it's connected Faces to find a Face with Cylinder Geometry to get a UnitVector, but the Entity won't be a WorkAxisObject.  Another way to get the UnitVector is to look at the Geometry instead of the Entity.  This gives you Assembly oriented center point and normal UnitVector for the input Entity.  

 

I have a quick example below which creates a Fixed Workaxis [Only method currently supported in Assembly Environment] based on input 1 for a given InsertConstraint:

Dim AsmDef As AssemblyComponentDefinition = TryCast(ThisApplication.ActiveDocument.ComponentDefinition, AssemblyComponentDefinition)
If IsNothing(AsmDef) Then Logger.Trace("Not run in Assembly Environment") : Exit Sub

Dim i As Integer = 2
Dim InCon As InsertConstraint = TryCast(AsmDef.Constraints.Item(i), InsertConstraint)
If IsNothing(InCon) Then Logger.Trace("Constraint #" & i & " is not an Insert Constraint") : Exit Sub

'Logger.Trace(CType(InCon.EntityOne.Type, ObjectTypeEnum).ToString)

Dim circle1 As Circle = TryCast(InCon.GeometryOne, Circle)
If IsNothing(circle1) Then Logger.Trace("Geometry is not a Circle") : Exit Sub
	
Dim circle1Center As Point = circle1.Center
Dim circle1Normal As UnitVector = circle1.Normal

Dim Occurrence1Axis As WorkAxis = AsmDef.WorkAxes.AddFixed(circle1Center, circle1Normal, False)

 

I'm not sure what you want to do with this information, but if you have any questions or would like any more assistance, let me know.

Message 3 of 3

gcoombridge
Advisor
Advisor
Accepted solution

JCamper beat me to it but here is your code reworked to confirm entityone is an edge:

Dim oAssy As AssemblyDocument = ThisApplication.ActiveDocument

Dim oDef As AssemblyComponentDefinition
oDef = oAssy.ComponentDefinition

Dim oCons As AssemblyConstraint
oCons = oDef.Constraints.Item("Insert:1")

Dim oEnt As Object
oEnt = oCons.EntityOne

Dim oEdge As Edge

If (TypeOf oEnt Is Edge) = True Then
	oEdge = oEnt
	MsgBox("Entity one is the cylinder axis")
Else
	msgbox("Nothing")
End If

 

Use iLogic Copy? Please consider voting for this long overdue idea (not mine):https://forums.autodesk.com/t5/inventor-ideas/string-replace-for-ilogic-design-copy/idi-p/3821399