Rotating Component in assembly around one of it's own axis

Rotating Component in assembly around one of it's own axis

Daan_M
Collaborator Collaborator
816 Views
7 Replies
Message 1 of 8

Rotating Component in assembly around one of it's own axis

Daan_M
Collaborator
Collaborator

 

Hi, I've got Component A in my assembly, which i want to rotate x degrees around it's own Y-Axis. I found the following which i think need

 

 

oCurrentOccurrence.Transformation.SetToRotation()

 

 

As input i need the the angle of rotation(variable), a workaxis(Y-axis of component), and a point (not sure what the point is for). I found a post of @WCrihfield describing i need to create a proxy to acces the components Work-Axis/Point so i did the following:

 

 

		Dim oCurrentOccurrence As ComponentOccurrence = oACD.Occurrences.Item(5)
		Dim oAngle = 90

		Dim oPoint As WorkPoint = oCurrentOccurrence.Definition.WorkPoints.Item(1)
		Dim oAxis As WorkAxis = oCurrentOccurrence.Definition.WorkAxes.Item(1)
		
		Dim oPointProxy As WorkPointProxy = Nothing
		Dim oAxisProxy As WorkAxisProxy = Nothing
		
		oCurrentOccurrence.CreateGeometryProxy(oPoint, oPointProxy)
		oCurrentOccurrence.CreateGeometryProxy(oAxis, oAxisProxy)
		
		oCurrentOccurrence.Transformation.SetToRotation(oAngle, oAxis, oPoint)

 

 

 

It throws an error on line 13

 

NOTES

 

  • Before this the component is placed in the assembly with '.AddUsingiMates' so this means there are contraints applied to the component. Once it is placed these contrains can be ignored.
  • To be clear, i need the component to rotate around it's own Y-Axis. NOT the Y-Axis of the assembly.
0 Likes
Accepted solutions (1)
817 Views
7 Replies
Replies (7)
Message 2 of 8

Andrii_Humeniuk
Advisor
Advisor

Hi @Daan_M . I see you're trying to use WorkAxis for the SetToRotation method, but you actually need to use Vector.
The line (13) that gives an error should look like this:

oCurrentOccurrence.Transformation.SetToRotation(oAngle, oAxisProxy.Line.Direction.AsVector(), oPointProxy)

 

 

I haven't tested it, but it seems you also need to use Point instead of WorkPoint.

oCurrentOccurrence.Transformation.SetToRotation(oAngle, oAxisProxy.Line.Direction.AsVector(), oPointProxy.Point)

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 3 of 8

Daan_M
Collaborator
Collaborator

Hi @Andrii_Humeniuk Thank you for the reply.

 

The code runs without error when i use your second suggestion:

 

oCurrentOccurrence.Transformation.SetToRotation(oAngle, oAxisProxy.Line.Direction.AsVector(), oPointProxy.Point)

 

 

Unfortunately I see no result, the component has not rotated in any way. Maybe the contrains from 'AddUsingiMates()' play a role?

 

Marked red = The component

Blue arrow = points to Y-Axis of the component

 

Daan_M_0-1702988629477.png

 

The updated code:

 

 

		Dim oCurrentOccurrence As ComponentOccurrence = oACD.Occurrences.Item(5)
		Dim oAngle = 45
		
		MsgBox(oacd.Occurrences.Item(5).Name)
		Dim oPoint As WorkPoint = oCurrentOccurrence.Definition.WorkPoints.Item(1)
		Dim oAxis As WorkAxis = oCurrentOccurrence.Definition.WorkAxes.Item(1)
		
		Dim oPointProxy As WorkPointProxy = Nothing
		Dim oAxisProxy As WorkAxisProxy = Nothing
		
		oCurrentOccurrence.CreateGeometryProxy(oPoint, oPointProxy)
		oCurrentOccurrence.CreateGeometryProxy(oAxis, oAxisProxy)
		
		oCurrentOccurrence.Transformation.SetToRotation(oAngle, oAxisProxy.Line.Direction.AsVector(), oPointProxy.Point)

 

 

 

0 Likes
Message 4 of 8

Andrii_Humeniuk
Advisor
Advisor

If the constraint is in the plane of rotation then yes, you cannot rotate it, you need to suppress the constraint or delete it and create a new one in other planes.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 5 of 8

Daan_M
Collaborator
Collaborator

@Andrii_Humeniuk Ok i put in some code to delete the contraints, but the component still has not rotated.

 

Maybe i am doing something wrong defining the workpoint and workaxis. Right now i use '.WorkAxes.Item(1)' and '.Workpoints.Item(1) but i'm not even sure what (1) is. I want to rotate around the components Y-Axis and im not sure what the point is for. Are these things in the component by Default or do i need to define these placing them myself in the partfile as Axis and workpoint?

 

Updated code

 

 

		oACD.Occurrences.AddUsingiMates(oFullPath, False)
		
		'DELETE CONSTRAINTS
		
		Dim oCurrentOccurrence As ComponentOccurrence = oACD.Occurrences.Item(5)
		For Each OCS In oCurrentOccurrence.Constraints
		OCS.Delete
		Next
		
		'ROTATION
		
		Dim oAngle = 45
	
		Dim oPoint As WorkPoint = oCurrentOccurrence.Definition.WorkPoints.Item(1)
		Dim oAxis As WorkAxis = oCurrentOccurrence.Definition.WorkAxes.Item(1)
		
		Dim oPointProxy As WorkPointProxy = Nothing
		Dim oAxisProxy As WorkAxisProxy = Nothing
		
		oCurrentOccurrence.CreateGeometryProxy(oPoint, oPointProxy)
		oCurrentOccurrence.CreateGeometryProxy(oAxis, oAxisProxy)
		
		oCurrentOccurrence.Transformation.SetToRotation(oAngle, oAxisProxy.Line.Direction.AsVector(), oPointProxy.Point)

 

 

 

 

0 Likes
Message 6 of 8

Andrii_Humeniuk
Advisor
Advisor

The Y-axis is numbered 2. The X-axis is numbered 1.

Andrii_Humeniuk_0-1702991696511.png

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 7 of 8

Daan_M
Collaborator
Collaborator

@Andrii_Humeniuk Still no result

 

Made a clean test file, please see the attached Assembly and Partfile.

Run the code in the assembly called 'Rotate', i get no result in any direction.

0 Likes
Message 8 of 8

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Try this:

 

Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oACD As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oOcc As ComponentOccurrence = oACD.Occurrences.Item(1)

Dim oAngle as Double = 3.14159265358979 / 4

Dim oPoint As WorkPoint = oOcc.Definition.WorkPoints("Work Point1")
Dim oAxis As WorkAxis = oOcc.Definition.WorkAxes("Work Axis1")
		
Dim oPointProxy As WorkPointProxy
Dim oAxisProxy As WorkAxisProxy
		
call oOcc.CreateGeometryProxy(oPoint, oPointProxy)
Call oOcc.CreateGeometryProxy(oAxis, oAxisProxy)
Dim oTransform As Matrix = oOcc.Transformation

Call oTransform.SetToRotation(oAngle, oAxisProxy.Line.Direction.AsVector(), oPointProxy.Point)

oOcc.Transformation = oTransform

If it does not move, try changing the degree.

Also keep in mind that the Inventor understands radians as degrees.

 

 

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature