Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create Work Planes in Assembly iLogic

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
will_roe
1920 Views, 5 Replies

Create Work Planes in Assembly iLogic

will_roe
Enthusiast
Enthusiast

Hi,

 

I currently want to use iLogic to create offset planes from the origin in an assembly. Is this possible? If not what's the next easiest option?

 

I use the below code in .ipt without issues and don't know enough about iLogic to know why this doesn't work 😥

 

oDef = ThisDoc.Document.ComponentDefinition
Dim oWPlane As WorkPlane
oWPlane = oDef.WorkPlanes.AddByPlaneAndOffset(oDef.WorkPlanes("XY Plane"), 20 mm) 
oWPname = "My_New_Work_Plane"

 

Any help much appreciated.

0 Likes

Create Work Planes in Assembly iLogic

Hi,

 

I currently want to use iLogic to create offset planes from the origin in an assembly. Is this possible? If not what's the next easiest option?

 

I use the below code in .ipt without issues and don't know enough about iLogic to know why this doesn't work 😥

 

oDef = ThisDoc.Document.ComponentDefinition
Dim oWPlane As WorkPlane
oWPlane = oDef.WorkPlanes.AddByPlaneAndOffset(oDef.WorkPlanes("XY Plane"), 20 mm) 
oWPname = "My_New_Work_Plane"

 

Any help much appreciated.

5 REPLIES 5
Message 2 of 6
A.Acheson
in reply to: will_roe

A.Acheson
Mentor
Mentor

@will_roe 

A work backward’s approach could work here. Create the offset plane as normal and then enter your rule and find the offset plane and use capture snippet. This will allow you to create the ilogic required. 

http://www.inventortales.com/2013/03/using-capture-current-state-with.html?m=1

 

On further investigation your above code will only work to create a workplane but not offset it. The below link shows you how. You could also search the API help to get the most current example of this as it may have been changed since 2018.

https://forums.autodesk.com/t5/inventor-customization/create-a-plane-with-offset-using-inventor-api/...

 

What inventor version have you got?

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes

@will_roe 

A work backward’s approach could work here. Create the offset plane as normal and then enter your rule and find the offset plane and use capture snippet. This will allow you to create the ilogic required. 

http://www.inventortales.com/2013/03/using-capture-current-state-with.html?m=1

 

On further investigation your above code will only work to create a workplane but not offset it. The below link shows you how. You could also search the API help to get the most current example of this as it may have been changed since 2018.

https://forums.autodesk.com/t5/inventor-customization/create-a-plane-with-offset-using-inventor-api/...

 

What inventor version have you got?

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 6
JhoelForshav
in reply to: will_roe

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @will_roe 

The only way to add a workplane in assembly environment by iLogic/API is to add a fixed plane. For example AddPlaneAndOffset doesn't work. If you have a look at a workplane created that way (manually) in an assembly, you'll see that a plane is created and then constrained with a Flush constraint with offset.

You can do this by code, but not using AddByPlaneAndOffset.

 

Try this 🙂

Sub Main
	oDef = ThisDoc.Document.ComponentDefinition
	Dim oWPlane As WorkPlane
	oWPlane = AddWorkPlaneInAssemblyOffset(oDef.WorkPlanes("XY Plane"), 20)
	oWPlane.Name = "My_New_Work_Plane"
End Sub

Function AddWorkPlaneInAssemblyOffset(oFace As Object, oOffset As Double) As WorkPlane
	Dim uOM As UnitsOfMeasure = ThisDoc.Document.UnitsOfMeasure
	Dim oAsm As AssemblyDocument = ThisApplication.ActiveDocument
	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.AddFlushConstraint(oFace, oPlane, uOM.ConvertUnits(oOffset, uOM.LengthUnits, UnitsTypeEnum.kDatabaseLengthUnits))
	oPlane.AutoResize = False
	Return oPlane
End Function

 

Hi @will_roe 

The only way to add a workplane in assembly environment by iLogic/API is to add a fixed plane. For example AddPlaneAndOffset doesn't work. If you have a look at a workplane created that way (manually) in an assembly, you'll see that a plane is created and then constrained with a Flush constraint with offset.

You can do this by code, but not using AddByPlaneAndOffset.

 

Try this 🙂

Sub Main
	oDef = ThisDoc.Document.ComponentDefinition
	Dim oWPlane As WorkPlane
	oWPlane = AddWorkPlaneInAssemblyOffset(oDef.WorkPlanes("XY Plane"), 20)
	oWPlane.Name = "My_New_Work_Plane"
End Sub

Function AddWorkPlaneInAssemblyOffset(oFace As Object, oOffset As Double) As WorkPlane
	Dim uOM As UnitsOfMeasure = ThisDoc.Document.UnitsOfMeasure
	Dim oAsm As AssemblyDocument = ThisApplication.ActiveDocument
	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.AddFlushConstraint(oFace, oPlane, uOM.ConvertUnits(oOffset, uOM.LengthUnits, UnitsTypeEnum.kDatabaseLengthUnits))
	oPlane.AutoResize = False
	Return oPlane
End Function

 

Message 4 of 6
will_roe
in reply to: JhoelForshav

will_roe
Enthusiast
Enthusiast

This was exactly what I was looking for! Much appreciated! 

0 Likes

This was exactly what I was looking for! Much appreciated! 

Message 5 of 6
sam
Advocate
in reply to: will_roe

sam
Advocate
Advocate

@JhoelForshav please don't mind me asking what is the reason behind not allowing to add a plane by AddByPlaneAndOffset in an assembly?

@JhoelForshav please don't mind me asking what is the reason behind not allowing to add a plane by AddByPlaneAndOffset in an assembly?

Message 6 of 6
sam
Advocate
in reply to: will_roe

sam
Advocate
Advocate

@JhoelForshav Thanks for this code, was able to tweak it to work with my existing VBA code after few glitches. 

0 Likes

@JhoelForshav Thanks for this code, was able to tweak it to work with my existing VBA code after few glitches. 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report