- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
Solved! Go to Solution.