Create plane using cylindrical face inside an assembly

Create plane using cylindrical face inside an assembly

dialunau
Advocate Advocate
1,206 Views
8 Replies
Message 1 of 9

Create plane using cylindrical face inside an assembly

dialunau
Advocate
Advocate

I am trying to create a plane using an axis of a curved face. The code works fine when I run it inside a part, but it crashes when I attempt to do it inside an assembly. My code looks like this:

 

Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oCurFace As Face = ThisApplication.CommandManager.Pick(kPartFaceCylindricalFilter, "Select the cylinder face")
Dim oPlanFace As Face = ThisApplication.CommandManager.Pick(kPartFacePlanarFilter, "Select a face or plane paralell to the new plane")
Dim oAxis As WorkAxis = oDef.WorkAxes.AddByRevolvedFace(oCurFace)

oDef.WorkPlanes.AddByLinePlaneAndAngle(oAxis, oPlanFace, 0)

 

The code crashes in line 5 when I try to get the axis of the curved face. My assumption is that Inventor can't get the axis of the face since it is inside the part and not at the assembly level.

 

Does anyone have a solution for this?

Thanks in advance.

0 Likes
1,207 Views
8 Replies
Replies (8)
Message 2 of 9

WCrihfield
Mentor
Mentor

Hi @dialunau.  When you use the Pick command within an assembly, you should already be selecting the top level proxy of the geometry you select, so I don't think it is a context issue.  Can you create that WorkPlane using those same inputs, in that same order manually?  This might actually be a restricted method to use by code within an assembly, because the online help for that method does mention that.

WorkPlanes.AddByLinePlaneAndAngle Method 

You may have to use the WorkPlanes.AddFixed method instead, but that one requires different inputs.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 9

dialunau
Advocate
Advocate

Hello,

I tried to create the plane manually using the same inputs, but Inventor doesn't recognize the axis of the curved face as a valid line for the plane creation, only geometry edges and sketched lines work for the plane creation features.

 

I want to create a plane in the middle of the cylindrical face using its axis and a planar face, so I would rather not use the addfixed method since it would require more defining the middle point of the curved surface, as well as defining the x and y axes for the planar face I pick.

0 Likes
Message 4 of 9

J-Camper
Advisor
Advisor

@dialunau,

 

@WCrihfield  was saying that Inventor's API restricts plane creation inside Assemblies to only the .AddFixed Method.  None of the other methods will work inside an assembly by design.

 

You can create the fixed plane with your two inputs pretty easily, but it will not act like a workplane added through the UI, will not adapt as components move. This could be faked with a more complex rule that "tags" the entities with attributes and setup a rule to run on some event trigger to update the fixed plane

 

Here is an easy way to get the fixed plane from your same inputs:

Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition

Dim oCurFace As Face = ThisApplication.CommandManager.Pick(kPartFaceCylindricalFilter, "Select the cylinder face")
Dim oPlanFace As Face = ThisApplication.CommandManager.Pick(kPartFacePlanarFilter, "Select a face or plane paralell to the new plane")

Dim oBasePoint As Point = oCurFace.Geometry.BasePoint
Dim Yaxis As UnitVector = oCurFace.Geometry.AxisVector
Dim Zaxis As UnitVector = oPlanFace.Geometry.Normal
Dim Xaxis As UnitVector = Zaxis.CrossProduct(Yaxis)

oDef.WorkPlanes.AddFixed(oBasePoint, Xaxis, Yaxis)

 

0 Likes
Message 5 of 9

tim11_manhhieu
Advocate
Advocate

Hi, if I want to create an axis of a cylindrical surface of a part in an assembly environment, how do I do that?

 

Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oCurFace As Face = ThisApplication.CommandManager.Pick(kPartFaceCylindricalFilter, "Select the cylinder face")

Dim oAxis As WorkAxis = oDef.WorkAxes.AddByRevolvedFace(oCurFace)
0 Likes
Message 6 of 9

WCrihfield
Mentor
Mentor

Hi @tim11_manhhieu.  Here is one possible example for creating a WorkAxis for a cylindrical part face in an assembly.  This assumes that you wanted the WorkAxis to be created within the active assembly, not within the part.  As stated above, we can only create work features in an assembly as 'fixed'.  But we can 'update' those fixed work features in an assembly by code, if needed.  I just tested this, and it worked just fine for me, so I hope it will work OK for you also, and is what you wanted.

Dim oInvApp As Inventor.Application = ThisApplication
Dim oADoc As Inventor.AssemblyDocument = TryCast(oInvApp.ActiveDocument, Inventor.AssemblyDocument)
If oADoc Is Nothing Then Return
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oCylFace As Inventor.Face = oInvApp.CommandManager.Pick(SelectionFilterEnum.kPartFaceCylindricalFilter, "Pick Cylindrical Face")
If oCylFace Is Nothing Then Return
Dim oCyl As Inventor.Cylinder = oCylFace.Geometry
Dim oWAxes As Inventor.WorkAxes = oADef.WorkAxes
Dim oWAxis As Inventor.WorkAxis = oWAxes.AddFixed(oCyl.BasePoint, oCyl.AxisVector, False)
oADoc.Update2(True)

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 9

tim11_manhhieu
Advocate
Advocate

Thank  you for your code.

I'm struggling with the AddByRevolvedFace method,

and if I use the AddFixed method, I don't know where to find the arguments.

 

0 Likes
Message 8 of 9

WCrihfield
Mentor
Mentor

The WorkAxes.AddByRevolvedFace method will only work when creating a WorkAxis in the context of a part, but will not work when creating one in the context of an assembly.  The online documentation for that method (and most other similar methods) tell us this.  So, when we are creating a WorkAxis in the context of an assembly, the only option we have is the WorkAxes.AddFixed method.  The AddFixed method wants us to specify an Inventor.Point type object, then an Inventor.UnitVector object.  When we have selected a face using the 'Pick' function and the 'SelectionFilterEnum.kPartFaceCylindricalFilter' selection filter, and confirmed that we actually picked something, then we can be confident that the face we selected is cylindrical in shape.  Keep in mind that if we are using the Pick function while an assembly is the active document, the face will be a FaceProxy instead of a regular Face, but in this case, we actually want to be working with the proxy, so that the WorkAxis will be created in the correct location within the context of the assembly.  When we have a cylindrical face, then its 'Geometry' property should return an Inventor.Cylinder type object.  But if not sure about that, you can always check the Face.SurfaceType property's value, which will be a variation of the SurfaceTypeEnum.  So, we can create a Cylinder Type variable, then set its value with that Face.Geometry property, then use that variable to access the properties of that Cylinder object.  The 3 main properties of a Cylinder are its BasePoint which has an Inventor.Point type value, its AxisVector which has a UnitVector type value, and its Radius which has a Double type value.  Two of those (BasePoint & AxisVector) we can use as inputs into that WorkAxes.AddFixed method.  Since the WorkAxis is being created as 'Fixed', it will not move or update if/when the component with the cylindrical face moves.  As mentioned before, we can later run a rule that will find that cylindrical face again, then find that existing fixed WorkAxis, get its 'definition', then attempt to change its location and direction to be the same as the cylindrical face, but we can not change how the WorkAxis is 'defined' to be truly 'associative' to that cylindrical face so that it will move with it.  I have attempted to use the WorkAxis.SetByRevolvedFace method on the pre-existing fixed WorkAxis before to associate it with a cylindrical face after the fact, but it would always throw an error instead of work, because it is in the context of an assembly.  If you do not want to use the center axis of a cylinder as the input for the AddFixed method, you can attempt to create the UnitVector from scratch instead, using the TransientGeometry.CreateUnitVector method instead.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 9 of 9

tim11_manhhieu
Advocate
Advocate

Your explanations are always detailed and easy to understand.

Appreciate.

0 Likes