iLogic: use DocumentUnitsMatrix to reposition existing component

iLogic: use DocumentUnitsMatrix to reposition existing component

Anonymous
Not applicable
416 Views
2 Replies
Message 1 of 3

iLogic: use DocumentUnitsMatrix to reposition existing component

Anonymous
Not applicable

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?

0 Likes
Accepted solutions (1)
417 Views
2 Replies
Replies (2)
Message 2 of 3

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

SetTransformWithoutConstraints takes an argument of type Matrix. Therefore we'll have to convert your DocumentUnitsMatrix to Matrix. I havn't tried it but I'm pretty sure this will do 🙂

 

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)
		oOccurrence.SetTransformWithoutConstraints(Pos_Matrix.InDatabaseUnits)
	End If
End Function

DocumentUnitsMatrix.InDatabaseUnits returns an object of type Matrix 🙂

Message 3 of 3

Anonymous
Not applicable

It worked perfectly, thanks! 😄