AnsweredAssumed Answered

How can i transform a Temporary body twice or more

Question asked by Lenny Yang on Apr 28, 2019
Latest reply on May 2, 2019 by Lenny Yang

hello every body,

I can transform a Temporary body at the first time when i use "IBody2 Interface : ApplyTransform Method (IBody2)".but i can't transform more than twice.

I know that I can copy again when i want to transform it at the second time,But this is too inefficient.

 

here is the code:==========================================================

' Preconditions:

' Just open a assembly and select a single body part.

 

 

Option Explicit

Sub main()

    Dim swApp As SldWorks.SldWorks

    Dim swModel As SldWorks.ModelDoc2

    Dim Body As SldWorks.Body2

    Dim BodyCopy As SldWorks.Body2

    Dim status As Boolean

    Dim Component As SldWorks.Component2

    Dim MathUtility As SldWorks.MathUtility

     

    Dim MathXform1 As SldWorks.MathTransform

    Dim Xform1(15) As Double

    Dim vXform1 As Variant

    Xform1(0) = 0#

    Xform1(1) = 1#

    Xform1(2) = 0#

    Xform1(3) = 0#

    Xform1(4) = 0#

    Xform1(5) = 1#

    Xform1(6) = 1#

    Xform1(7) = 0#

    Xform1(8) = 0#

    Xform1(9) = 0.15

    Xform1(10) = 0#

    Xform1(11) = 0#

    Xform1(12) = 1#

    Xform1(13) = 0#

    Xform1(14) = 0#

    Xform1(15) = 0#

    vXform1 = Xform1

     

    Dim MathXform2 As SldWorks.MathTransform

    Dim Xform2(15) As Double

    Dim vXform2 As Variant

    Xform2(0) = 1#

    Xform2(1) = 0#

    Xform2(2) = 0#

    Xform2(3) = 0#

    Xform2(4) = 1#

    Xform2(5) = 0#

    Xform2(6) = 0#

    Xform2(7) = 0#

    Xform2(8) = 1#

    Xform2(9) = 0.15

    Xform2(10) = 0#

    Xform2(11) = 0#

    Xform2(12) = 1#

    Xform2(13) = 0#

    Xform2(14) = 0#

    Xform2(15) = 0#

    vXform2 = Xform2

     

 

 

    Dim retval As Long

    Dim fileName As String

    Dim errors As Long

    Dim warnings As Long

 

 

    Set swApp = Application.SldWorks

    Set MathUtility = swApp.GetMathUtility

    Set MathXform1 = MathUtility.CreateTransform(vXform1)

    Set MathXform2 = MathUtility.CreateTransform(vXform2)

    Set swModel = swApp.ActiveDoc

    Dim swSelMgr As SldWorks.SelectionMgr

    Set swSelMgr = swModel.SelectionManager

    Set Component = swSelMgr.GetSelectedObjectsComponent4(1, -1)

     

    Set Body = Component.GetBody

    Set BodyCopy = Body.Copy

    BodyCopy.ApplyTransform MathXform1

    'Display temporary body

    retval = BodyCopy.Display3(Component, 255, swTempBodySelectable)

    Debug.Print "Temporary body displayed (0 = success)? " & retval

     

    'Here transform the Temporary second time use "ApplyTransform" function.But it does not work

    BodyCopy.ApplyTransform MathXform2

    'Display temporary body

    retval = BodyCopy.Display3(Component, 100, swTempBodySelectable)

    Debug.Print "Temporary body displayed (0 = success)? " & retval

     

    swModel.ViewZoomtofit2

     

End Sub

 

here is the code:==========================================================

Outcomes