Quantcast
Channel: Manufacturing DevBlog
Viewing all articles
Browse latest Browse all 531

Set transform of derived part in part document

$
0
0

By Adam Nagy

In theory you should be able to just move a derived part component inside the host part document using DerivedPartTransformDef.SetTransformation(). This does change the transformation of the DerivedPartTransformDef object but not the derived component itself. You can solve this issue by assigning the modified DerivedPartTransformDef object back to DerivedPartComponent.Definition:

Sub ChangeTranformation()
  Dim oApp As Inventor.Application
  Set oApp = ThisApplication
  Dim oDoc As PartDocument
  Set oDoc = oApp.ActiveDocument
  Dim oCD As PartComponentDefinition
  Set oCD = oDoc.ComponentDefinition
  Dim oFeat As PartFeature
  Set oFeat = oCD.Features(1)
  If oFeat.Type = kReferenceFeatureObject Then
    Dim oRef As ReferenceFeature
    Set oRef = oFeat
    Debug.Print oRef.name & "   " & oRef.Type

    Dim oRefComps As ReferenceComponents
    Set oRefComps = oCD.ReferenceComponents
   
    Dim oDeComp As DerivedPartComponent
    Set oDeComp = oRefComps.DerivedPartComponents(1)

    Dim oTrDef As DerivedPartTransformDef
    Set oTrDef = oDeComp.Definition
   
    Dim oMat As Matrix
    Call oTrDef.GetTransformation(oMat, False)
  
    Dim oGeom As TransientGeometry
    Set oGeom = ThisApplication.TransientGeometry
  
    Dim oMatDelta As Matrix
    Set oMatDelta = oGeom.CreateMatrix
  
    Dim oVect As Vector
    Set oVect = oGeom.CreateVector(2, 0, 0)
  
    Call oMatDelta.SetTranslation(oVect, False)
    Call oMat.PostMultiplyBy(oMatDelta)
  
    ' SetTransformation has no affect ...
    Call oTrDef.SetTransformation(oMat, False)' ... until you assign it back ...
    oDeComp.Definition = oTrDef' Updating the doc should not do any harm,' but might not be needed
    oDoc.Update

  End If

End Sub

DerivedPart

 


Viewing all articles
Browse latest Browse all 531

Trending Articles