Dim oTG As TransientGeometry
Dim X As Double: Dim Y As Double: Dim Z As Double
Dim X_rot As Double: Dim Y_rot As Double: Dim Z_rot As Double
Dim PI As Double
Dim oMatrix As matrix
Dim oMatrix_rot As matrix
Sub rotation_v2()
Dim PI As Double: PI = Atn(1) * 4
Dim oCD As AssemblyComponentDefinition
Set oCD = ThisApplication.ActiveDocument.ComponentDefinition
Dim oOcc_1 As ComponentOccurrence
Set oOcc_1 = oCD.Occurrences.ItemByName("1")
Dim oOcc_2 As ComponentOccurrence
Set oOcc_2 = oCD.Occurrences.ItemByName("2")
Set oTG = ThisApplication.TransientGeometry
PI = Atn(1) * 4
Call Rotate_func(oOcc_1, 0, PI / 4, PI / 4)
Call Rotate_func(oOcc_2, 0, PI / 4, PI / 4)
End Sub
Sub Rotate_func(occ As ComponentOccurrence, X_rot As Double, Y_rot As Double, Z_rot As Double)
Set oMatrix = oTG.CreateMatrix
Set oMatrix_rot = oTG.CreateMatrix
Call oMatrix.SetToRotation(X_rot, oTG.CreateVector(1, 0, 0), oTG.CreatePoint(0, 0, 0))
Call oMatrix_rot.TransformBy(oMatrix)
Call oMatrix.SetToRotation(Y_rot, oTG.CreateVector(0, 1, 0), oTG.CreatePoint(0, 0, 0))
Call oMatrix_rot.TransformBy(oMatrix)
Call oMatrix.SetToRotation(Z_rot, oTG.CreateVector(0, 0, 1), oTG.CreatePoint(0, 0, 0))
Call oMatrix_rot.TransformBy(oMatrix)
Set oMatrix = occ.Transformation
Call oMatrix.PreMultiplyBy(oMatrix_rot)
occ.Transformation = oMatrix
End Sub
Sub Start_pos()
Dim oCD As AssemblyComponentDefinition
Set oCD = ThisApplication.ActiveDocument.ComponentDefinition
Dim oOcc_1 As ComponentOccurrence
Set oOcc_1 = oCD.Occurrences.ItemByName("1")
Dim oOcc_2 As ComponentOccurrence
Set oOcc_2 = oCD.Occurrences.ItemByName("2")
Set oTG = ThisApplication.TransientGeometry
PI = Atn(1) * 4
X = 0: Y = 1000: Z = 0
X_rot = PI / 2: Y_rot = 0: Z_rot = PI
Call Transform(oOcc_1, X, Y, Z, X_rot, Y_rot, Z_rot)
X = 0: Y = 1200: Z = 200
X_rot = 0: Y_rot = PI: Z_rot = 0
Call Transform(oOcc_2, X, Y, Z, X_rot, Y_rot, Z_rot)
End Sub
Sub Transform(occ As ComponentOccurrence, X As Double, Y As Double, Z As Double, X_rot As Double, Y_rot As Double, Z_rot As Double)
Set oMatrix_rot = oTG.CreateMatrix
Set oMatrix = oTG.CreateMatrix
Call oMatrix_rot.SetToRotation(X_rot, oTG.CreateVector(1, 0, 0), oTG.CreatePoint(0, 0, 0))
Call oMatrix.TransformBy(oMatrix_rot)
Call oMatrix_rot.SetToRotation(Y_rot, oTG.CreateVector(0, 1, 0), oTG.CreatePoint(0, 0, 0))
Call oMatrix.TransformBy(oMatrix_rot)
Call oMatrix_rot.SetToRotation(Z_rot, oTG.CreateVector(0, 0, 1), oTG.CreatePoint(0, 0, 0))
Call oMatrix.TransformBy(oMatrix_rot)
Call oMatrix.SetTranslation(oTG.CreateVector(X / 10, Y / 10, Z / 10))
Call occ.SetTransformWithoutConstraints(oMatrix)
End Sub