Adding WorkPlane With Refrence to Face Using API C#

Adding WorkPlane With Refrence to Face Using API C#

hariharanhZXJ8L
Contributor Contributor
792 Views
6 Replies
Message 1 of 7

Adding WorkPlane With Refrence to Face Using API C#

hariharanhZXJ8L
Contributor
Contributor

Hello Guys,

I am facing the Problem on Creating Work Plane on Assembly with reference to Face Object. 

can you please someone to help me to resolve the Issue ?

Here is my code :

 

 

WorkPlanes oPlanes = docDef.WorkPlanes
Face oFace = InventorApp.CommandManager.Pick(SelectionFilterEnum.kAllPlanarEntities, "Please Select the Face for - AssyRefRight");
WorkPlane plane = oPlanes.AddByPlaneAndOffset(oFace, 3);
plane.AutoResize = true;
plane.Name = "AssyRefRight";

 

 

Thanks

HARI

0 Likes
Accepted solutions (1)
793 Views
6 Replies
Replies (6)
Message 2 of 7

vpeuvion
Advocate
Advocate

Hello, what is your problem? The code looks correct to me.

I tested it quickly on iLogic and it works.

 

Sub main
Dim oDoc As PartDocument = ThisApplication.ActiveDocument Dim docDef As PartComponentDefinition = oDoc.ComponentDefinition Dim oPlanes As WorkPlanes = docDef.WorkPlanes Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPlanarEntities, "Please Select the Face for - AssyRefRight") Dim plane As WorkPlane = oPlanes.AddByPlaneAndOffset(oFace, 3) plane.AutoResize = True plane.Name = "AssyRefRight" End Sub

 

vpeuvion_0-1671782607939.png

Vincent.

 

0 Likes
Message 3 of 7

hariharanhZXJ8L
Contributor
Contributor

For Part Doc It seems Working Good, I need to create plane in Assembly Doc.
It seems "AddByPlaneAndOffset" Is not working, do you have any other solution to create Work Planes in Assembly with reference to Face ?

0 Likes
Message 4 of 7

vpeuvion
Advocate
Advocate

Sorry, I hadn't seen that your question was about assemblies. AddByPlaneAndOffset does not work for assemblies. This post should be able to help you.

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/create-work-planes-in-assembly-ilogi...

Vincent.

0 Likes
Message 5 of 7

vpeuvion
Advocate
Advocate

This should work for your case (tested on iLogic):

Sub Main
    Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
    Dim oAsmCompDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
	Dim oFace As FaceProxy = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPlanarEntities, "Please Select the Face for - AssyRefRight")
	Dim oWPlane As WorkPlane
	oWPlane = AddWorkPlaneInAssemblyOffset(oFace, 3)
	oWPlane.Name = "AssyRefRight"
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

 

vpeuvion_0-1671786927069.png

Vincent.

Message 6 of 7

hariharanhZXJ8L
Contributor
Contributor

how do you decide the unit vector direction ?

In your Example you have created the plane normal to XY direction

 

	oXaxis = ThisApplication.TransientGeometry.CreateUnitVector(1#, 0#, 0#)
	oYaxis = ThisApplication.TransientGeometry.CreateUnitVector(0#, 1#, 0#)

 

what if I select the face  normal to YZ ?

In this case the output is not good.

 

Thanks

HARI

0 Likes
Message 7 of 7

vpeuvion
Advocate
Advocate
Accepted solution

Hi.
Have you tested the code on iLogic?
The plane is still created relative to the XY plane but is repositioned by the constraint that is applied to it next.
I did some tests on my side, the plane created is parallel to the selected face every time.

Vincent.