부품을 x,y,z 배치하는 구문을 포럼에서 답을 해주셨고 응용해서 사용했습니다.
이후 바로 배치된 부품의 회전이 필요했습니다.
하기 구문을 좀 편집했더니...원하는 대로 X,Y,Z 배치하고 회전 값을 주어서 위치도 잡았습니다.
참고하세요,~~
Class ThisRule
Sub Main
' File path to use
oPath = "PATH HERE"
'[ Place component
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oOccurrence As ComponentOccurrence
'get user input - units are cm
oX = InputBox("Enter the X co-ordinate, in mm.", "iLogic", "0")
oY = InputBox("Enter the Y co-ordinate, in mm.", "iLogic", "0")
oZ = InputBox("Enter the Z co-ordinate, in mm.", "iLogic", "0")
oXr = InputBox("Enter the X rotation, in deg.", "iLogic", "0")
oYr = InputBox("Enter the Y rotation, in deg.", "iLogic", "0")
oZr = InputBox("Enter the Z rotation, in deg.", "iLogic", "0")
oRotateOrder = InputBox("Enter Rotationorder, in form A,B,C.", "iLogic", "X,Y,Z")
'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)
End Sub
End Class
https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-place-a-part-and-define-rotation/m...
줌인테크 Techanical Support Engineer