Transformation of SurfaceBody Copy does not work

Transformation of SurfaceBody Copy does not work

ga42bon
Contributor Contributor
921 Views
2 Replies
Message 1 of 3

Transformation of SurfaceBody Copy does not work

ga42bon
Contributor
Contributor

Hello everyone,

 

I want to select a face of a part and copy it to a new part document. It shall be added to the new document with a certain transformation.

I adapted my code from the Inventor Help Website (https://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-8B91A087-4399-4327-A97E-B65F482CBD9B).

Everything works perfectly besides the transformation. Even though I set a transformation matrix including a translation and a rotation, the added surface in the new document is located the same as in the source document with the source part.

I can rotate and translate the surface manually to my desired location (YZ plane in the positive quadrant).

How can I make the transformation work automatically with the Inventor API?

 

This is my code right now:

 

Private Sub CopySelectedFace()

   Dim oSourcePartDoc As PartDocument = g_inventorApplication.ActiveDocument

   ' Get the selected face.
   Dim oFace As Face = g_inventorApplication.CommandManager._
          Pick(SelectionFilterEnum.kPartFaceFilter, "Select a face!")

   ' Copy the face as a transient B-Rep face.
   Dim oNewBody As SurfaceBody = g_inventorApplication._
                                  TransientBRep.Copy(oFace)

   ' Create a new part.
   Dim oTargetPartDoc As PartDocument = g_inventorApplication.Documents._
                      Add(DocumentTypeEnum.kPartDocumentObject,_ 
                      g_inventorApplication.FileManager._
                      GetTemplateFile(DocumentTypeEnum.kPartDocumentObject))

   ' Set a reference to the transient geometry object.
   Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry
   Dim oTrans As Matrix = oTG.CreateMatrix
   Call oTrans.Translation.AddVector_
                         (oTG.CreateVector(1, 1, 1,)) ' arbitrary translation
   Call oTrans.SetToRotation(1.57, oTG.CreateVector(1, 0, 0),_
                          oTG.CreatePoint(0, 0, 0)) 'arbitrary rotation

   ' Create a non-parametric base feature using the face.
   Dim oNPFeature As NonParametricBaseFeature = oTargetPartDoc._
                              ComponentDefinition.Features._
                              NonParametricBaseFeatures.Add(oNewBody, oTrans)

   ' Move feature to YZ plane
   Dim oCompDef As PartComponentDefinition = oTargetPartDoc._
                                              ComponentDefinition

End Sub

 

 

I have attachet three screenshots to illustrate my problem. The first one shows an example of an object to copy the face from. The second screenshot shows the result of the code sample above. The third one shows the result after manually rotating and moving the surface to the desired location.

I hope, there is a way to get to the result of the third screenshot automatically. 

0 Likes
Accepted solutions (1)
922 Views
2 Replies
Replies (2)
Message 2 of 3

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

Try to transform the SurfaceBody before adding as NonParametricBaseFeature

g_inventorApplication.TransientBRep.Transform(oNewBody, oTrans)

' Create a non-parametric base feature using the face.
Dim oNPFeature As NonParametricBaseFeature = oTargetPartDoc._
                              ComponentDefinition.Features._
                              NonParametricBaseFeatures.Add(oNewBody)

R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 3 of 3

ga42bon
Contributor
Contributor

Hello @Ralf_Krieg,

Thank you again for this perfect and easy solution to my problem!

Transforming the SurfaceBody before adding it as a NonParametricBaseFeature does the job.

0 Likes