Create a plane at an angle with i-Logic

Create a plane at an angle with i-Logic

Guthery1
Enthusiast Enthusiast
746 Views
7 Replies
Message 1 of 8

Create a plane at an angle with i-Logic

Guthery1
Enthusiast
Enthusiast

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? 

0 Likes
Accepted solutions (1)
747 Views
7 Replies
Replies (7)
Message 2 of 8

JhoelForshav
Mentor
Mentor

@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"
0 Likes
Message 3 of 8

Guthery1
Enthusiast
Enthusiast

@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.

 

0 Likes
Message 4 of 8

Andrii_Humeniuk
Advisor
Advisor

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

0 Likes
Message 5 of 8

Guthery1
Enthusiast
Enthusiast

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.

0 Likes
Message 6 of 8

Andrii_Humeniuk
Advisor
Advisor

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

0 Likes
Message 7 of 8

JhoelForshav
Mentor
Mentor
Accepted solution

@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
Message 8 of 8

Guthery1
Enthusiast
Enthusiast

That worked perfectly!  Thank you for the help.