Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Guthery1
575 Views, 7 Replies

Create a plane at an angle with i-Logic

I've been trying to get this piece of code to work:

oDef = ThisDoc.Document.ComponentDefinition
Dim oWPlane As WorkPlane
Dim oAxis As WorkAxes
oAxis = oDef.WorkAxes
oWPlane = oDef.WorkPlanes.AddByLinePlaneAndAngle(oDef.WorkPlanes("XY Plane"), oAxis("Y Axis"), 45)
oWPlane.Name = "Plane_Name"

I found it on these forums but it doesn't seem to work in 2023 Inventor.  Does anyone know what needs to be adjusted to make it function now? 

JhoelForshav
in reply to: Guthery1

@Guthery1 

You've put in the axis and the plane in the wrong order...

This should work:

Dim oDef = ThisDoc.Document.ComponentDefinition
Dim oWPlane As WorkPlane
Dim oAxis As WorkAxes
oAxis = oDef.WorkAxes
oWPlane = oDef.WorkPlanes.AddByLinePlaneAndAngle(oAxis("Y Axis"), oDef.WorkPlanes("XY Plane"), 45)
oWPlane.Name = "Plane_Name"
Guthery1
in reply to: JhoelForshav

@JhoelForshav 

 

I had already tried flipping it around but ended up with an "Unspecified error" in line 5 of the code.

 

Guthery1_0-1683719175876.png

Guthery1_1-1683719199550.png

I know it's not much to go on, which is why I came looking for help.  I know this should be easily doable but for some reason, it isn't.

 

Andrii_Humeniuk
in reply to: Guthery1

Hi @Guthery1 . Unfortunately, this method does not work for assemblies.

2023-05-10 153044.png

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Guthery1
in reply to: Andrii_Humeniuk

Any ideas on how we can make it work?  I find it hard to believe that Autodesk made it so you can't create a plane with i-Logic in an assembly but left the ability to make planes other ways with i-Logic.

Andrii_Humeniuk
in reply to: Guthery1

You can create a fixed plane, here is an example:

Dim oDef As AssemblyComponentDefinition = ThisDoc.Document.ComponentDefinition
Dim oWPlane As WorkPlane
Dim oAxis As WorkAxes
oAxis = oDef.WorkAxes
Dim oOriginPnt As Point
Dim oXaxis As UnitVector
Dim oYaxis As UnitVector
oOriginPnt = ThisApplication.TransientGeometry.CreatePoint(0, 0, 0)
oXaxis = ThisApplication.TransientGeometry.CreateUnitVector(1, 0, 1) '45 deg
oYaxis = ThisApplication.TransientGeometry.CreateUnitVector(0, 1, 0)
oWPlane = oDef.WorkPlanes.AddFixed(oOriginPnt, oXaxis, oYaxis)
oWPlane.Name = "Plane_Name"

 

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

@Guthery1 

If you look at what actually happens when you create a plane by line, plane and angle in an assembly, it adds a plane and then it adds a mate constraint to the line and an angle constraint to the plane. You can write your own function to mimic this behaviour.

See example below:

 

 

Sub Main
	Dim yAxis As WorkAxis = ThisDoc.Document.ComponentDefinition.WorkAxes("Y Axis")
	Dim YZPlane As WorkPlane = ThisDoc.Document.ComponentDefinition.WorkPlanes("YZ Plane")
	Dim oWPlane As WorkPlane = AddPlaneByLinePlaneAndAngle(yAxis, YZPlane, 45)
	oWPlane.Name = "Plane_Name"
End Sub

Function AddPlaneByLinePlaneAndAngle(_line As Object, _plane As Object, _angle As Double) As WorkPlane
	Dim oAsm As AssemblyDocument = ThisDoc.Document
	Dim oDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
	Dim oOriginPnt As Point
	Dim oXaxis As UnitVector
	Dim oYaxis As UnitVector
	oOriginPnt = ThisApplication.TransientGeometry.CreatePoint(0#, 0#, 0#)
	oXaxis = ThisApplication.TransientGeometry.CreateUnitVector(1#, 0#, 0#)
	oYaxis = ThisApplication.TransientGeometry.CreateUnitVector(0#, 1#, 0#)
	Dim oPlane As WorkPlane = oDef.WorkPlanes.AddFixed(oOriginPnt, oXaxis, oYaxis)
	oPlane.AutoResize = True
	oDef.Constraints.AddMateConstraint(_line, oPlane, 0, InferredTypeEnum.kInferredLine, InferredTypeEnum.kNoInference)
	Dim oAngleConstraint As AngleConstraint = oDef.Constraints.AddAngleConstraint(_plane, oPlane, 0, AngleConstraintSolutionTypeEnum.kDirectedSolution)
	oAngleConstraint.Angle.Expression = _angle.ToString
	oPlane.AutoResize = False
	ThisDoc.Document.Update
	Return oPlane
End Function
Guthery1
in reply to: JhoelForshav

That worked perfectly!  Thank you for the help.