Message 1 of 3

Not applicable
06-28-2020
11:35 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to be able to place a component or move an existing component to a given position and rotation.
My code:
Function PlaceComponentAtCoordinates(SpecificComponentName As String, ComponentPath As String, RotationX As Double, RotationY As Double, Distance As Double)
Dim Pos_Matrix As DocumentUnitsMatrix = ThisAssembly.Geometry.Matrix(RotationX, 0, 0, Distance,
0, RotationY, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1)
If Not ComponentExists(SpecificComponentName) Then
' This works fine
Components.Add(SpecificComponentName, ComponentPath, Pos_Matrix, grounded := True)
Else
Dim oOccurrence As ComponentOccurrence = Component.InventorComponent(SpecificComponentName)
' This doesn't work
oOccurrence.SetTransformWithoutConstraints(Pos_Matrix)
End If
End Function
' Input parameter: Component name
' Returns: True if component exists. False if it doesn't exist.
Function ComponentExists(ComponentName As String) As Boolean
[...]
End Function
Placing the component using Pos_Matrix works fine, but changing the position doesn't, because "Unable to cast object of type 'Autodesk.iLogic.Types.DocumentUnitsMatrix' to type 'Inventor.Matrix'."
oOccurrence.SetTransformWithoutConstraints(Pos_Matrix)
How can I solve it?
Solved! Go to Solution.