Message 1 of 5
How to Rotate an Assembly around its own Axis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
I have an assembly that I want to rotate around its Z-axis by 90 degrees. I’ve written an iLogic code that rotates each component, but I’m facing an issue: some components are rotating while others are not.
What could be the possible reason for this behavior? Are there any changes or improvements I should make to the code?
Any suggestions would be highly appreciated.
Best regards,
Muddassir
Dim dPi As Double
dPi = Math.PI ' Define π (Pi)
Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
Dim oTransMatrix As Matrix
oTransMatrix = oTG.CreateMatrix
oTransMatrix.SetToRotation(90 * (dPi / 180), oTG.CreateVector(0, 0, 1), oTG.CreatePoint(0, 0, 0))
Dim matrixString As String = "Matrix Values:" & vbCrLf
For row As Integer = 1 To 3
For col As Integer = 1 To 3
matrixString &= Math.Round(oTransMatrix.Cell(row, col), 3).ToString() & vbTab
Next
matrixString &= vbCrLf
Next
MessageBox.Show(matrixString)
Dim i As Integer = 1
Dim oOcc As ComponentOccurrence
For Each oOcc In oAsmDoc.ComponentDefinition.Occurrences
If oOcc.Suppressed = False Then
Dim oMatrix As Matrix
oMatrix = oOcc.Transformation
If oOcc.Grounded Then
oOcc.Grounded = False
End If
oMatrix.PreMultiplyBy(oTransMatrix)
i += 1
oOcc.Transformation = oMatrix
Logger.Error("ROTATED :: " & oOcc.Name)
Dim matrixString1 As String = "Matrix Values:" & vbCrLf
For row As Integer = 1 To 3
For col As Integer = 1 To 3
matrixString1 &= Math.Round(oMatrix.Cell(row, col), 3).ToString() & vbTab
Next
matrixString1 &= vbCrLf
Next
Logger.Info(matrixString1)
End If
Next
Logger.Info(i)