Class ThisRule
Sub Main
' File path to use
oPath = "path and part"
'get user input - units are cm
oX = -RobotFrameWidth/2-UprightBoxWidth
oY = 2504
oZ = ( RobotFrameDepth / 2 ul ) - 240
oXr = 0
oYr = 90
oZr = 0
oRotateOrder = "X,Y,Z"
If B1C = None Then
GoTo B2C1
Else oWhere = "B1C2"
End If
'[ Place component
Start:
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oOccurrence As ComponentOccurrence
'placement co-ordinates in mm's
oOccurrence = oAsmCompDef.Occurrences.Add(oPath, CreateMatrixRotate(oX, oY, oZ, _
oXr, oYr, oZr, oRotateOrder))
oOccurrence.Grounded = True
'zoom all
ThisApplication.ActiveView.Fit
']
End Sub
Function CreateMatrixRotate(X As Double, Y As Double, Z As Double, _
XAngleDeg As Double, YAngleDeg As Double, ZAngleDeg As Double, oRotateOrder As String) As Matrix
Dim XAngle As Double = XAngleDeg * (Math.PI / 180)
Dim YAngle As Double = YAngleDeg * (Math.PI / 180)
Dim ZAngle As Double = ZAngleDeg * (Math.PI / 180)
Dim oTg As Inventor.TransientGeometry = ThisApplication.TransientGeometry
Dim oMatrix As Matrix = oTg.CreateMatrix
'ROTATE MATRIX
Dim oFirstAxis As String = oRotateOrder.Split(",")(0)
Dim oSecondAxis As String = oRotateOrder.Split(",")(1)
Dim oThirdAxis As String = oRotateOrder.Split(",")(2)
If oFirstAxis = "X"
RotateAroundX(oMatrix, XAngle)
ElseIf oFirstAxis = "Y"
RotateAroundY(oMatrix, YAngle)
ElseIf oFirstAxis = "Z"
RotateAroundZ(oMatrix, ZAngle)
End If
If oSecondAxis = "X"
RotateAroundX(oMatrix, XAngle)
ElseIf oSecondAxis = "Y"
RotateAroundY(oMatrix, YAngle)
ElseIf oSecondAxis = "Z"
RotateAroundZ(oMatrix, ZAngle)
End If
If oThirdAxis = "X"
RotateAroundX(oMatrix, XAngle)
ElseIf oThirdAxis = "Y"
RotateAroundY(oMatrix, YAngle)
ElseIf oThirdAxis = "Z"
RotateAroundZ(oMatrix, ZAngle)
End If
'--------------------------------------------
'Translate Matrix
Dim oTranslateVector As Vector = oTg.CreateVector(X/10,Y/10,Z/10)
oMatrix.SetTranslation(oTranslateVector, False)
Return oMatrix
End Function
Sub RotateAroundX(oMatrix As Matrix, rotationAngle As Double)
Dim oRotateMatrix As Matrix = ThisApplication.TransientGeometry.CreateMatrix
oRotateMatrix.Cell(1, 1) = 1
oRotateMatrix.Cell(1, 2) = 0
oRotateMatrix.Cell(1, 3) = 0
oRotateMatrix.Cell(2, 1) = 0
oRotateMatrix.Cell(2, 2) = Math.Cos(rotationAngle)
oRotateMatrix.Cell(2, 3) = - Math.Sin(rotationAngle)
oRotateMatrix.Cell(3, 1) = 0
oRotateMatrix.Cell(3, 2) = Math.Sin(rotationAngle)
oRotateMatrix.Cell(3, 3) = Math.Cos(rotationAngle)
oMatrix.TransformBy(oRotateMatrix)
End Sub
Sub RotateAroundY(oMatrix As Matrix, rotationAngle As Double)
Dim oRotateMatrix As Matrix = ThisApplication.TransientGeometry.CreateMatrix
oRotateMatrix.Cell(1, 1) = Math.Cos(rotationAngle)
oRotateMatrix.Cell(1, 2) = 0
oRotateMatrix.Cell(1, 3) = Math.Sin(rotationAngle)
oRotateMatrix.Cell(2, 1) = 0
oRotateMatrix.Cell(2, 2) = 1
oRotateMatrix.Cell(2, 3) = 0
oRotateMatrix.Cell(3, 1) = - Math.Sin(rotationAngle)
oRotateMatrix.Cell(3, 2) = 0
oRotateMatrix.Cell(3, 3) = Math.Cos(rotationAngle)
oMatrix.TransformBy(oRotateMatrix)
End Sub
Sub RotateAroundZ(oMatrix As Inventor.Matrix, rotationAngle As Double)
Dim oRotateMatrix As Matrix = ThisApplication.TransientGeometry.CreateMatrix
oRotateMatrix.Cell(1, 1) = Math.Cos(rotationAngle)
oRotateMatrix.Cell(1, 2) = - Math.Sin(rotationAngle)
oRotateMatrix.Cell(1, 3) = 0
oRotateMatrix.Cell(2, 1) = Math.Sin(rotationAngle)
oRotateMatrix.Cell(2, 2) = Math.Cos(rotationAngle)
oRotateMatrix.Cell(2, 3) = 0
oRotateMatrix.Cell(3, 1) = 0
oRotateMatrix.Cell(3, 2) = 0
oRotateMatrix.Cell(3, 3) = 1
oMatrix.TransformBy(oRotateMatrix)
GoTo oWhere
End Sub
End Class
'Place second cabinet
B1C2:
oZ = -( RobotFrameDepth / 2 ul ) - 240
oYr = - 90
oWhere = "B2C1"
GoTo Start
B2C1:
etc etc

Inventor Certified Professional