Just rotate part when placing it

Just rotate part when placing it

TechInventor20
Advocate Advocate
1,002 Views
7 Replies
Message 1 of 8

Just rotate part when placing it

TechInventor20
Advocate
Advocate

Hello,


I know this is a common question and there are many good solutions available, but I need something a bit smaller then suggested in the topic below.

 

https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/ilogic-place-a-part-and-define-rotation...

 

I got the code below and I would like to rotate my part just 180° around the y-axis.

I thought it would be very nice to just change the last part to;

oMatrix.SetTranslation(oTG.CreateVector(oX/10, oY/10, oZ/10, 0, PI, 0))

But this wouldn't work unfortunatly..

	Dim oAsmCompDef As AssemblyComponentDefinition
	oAsmCompDef = ThisDoc.Document.ComponentDefinition
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oMatrix As Matrix = oTG.CreateMatrix
	Dim oOccurrence As ComponentOccurrence
	
			If Bodem = 3 Or Bodem = 4 Then
				Part_hight = 4
			Else
				Part_hight =  4 + Romp_aantal
			End If
			
	Bodem_0punt = GoExcel.CellValue(Datasheet, Blad, "O" & Part_hight)
		MsgBox(Bodem_0punt & " 2 " & Romp_aantal)
'get user input - units are cm
oX = 0
oY = 0
oZ = Bodem_0punt
'placement co-ordinates in mm's
oMatrix.SetTranslation(oTG.CreateVector(oX/10, oY/10, oZ/10))
oOccurrence = oAsmCompDef.Occurrences.Add(Part_name, oMatrix)
oOccurrence.Grounded = True 

 

If someone has a quick and simple code then you would save me lots of time...

0 Likes
Accepted solutions (1)
1,003 Views
7 Replies
Replies (7)
Message 2 of 8

TechInventor20
Advocate
Advocate
Accepted solution

Found the solution in this topic below;

 

https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/settorotation-question/td-p/2488976

 

oMatrix.SetToRotation( 180 *(PI/180), oTG.CreateVector(0, 1, 0), oTG.CreatePoint(0, 0, 0))

 

0 Likes
Message 3 of 8

Robert.Egel7SPMT
Explorer
Explorer

After you placed the data, is it somehow possible to get the rotation data?

0 Likes
Message 4 of 8

TechInventor20
Advocate
Advocate

This is the code I used for a part that needs to be rotated inside a assembly

 

 

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisDoc.Document.ComponentDefinition
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oMatrix As Matrix = oTG.CreateMatrix
Dim oOccurrence As ComponentOccurrence
' Get the current transformation matrix from the occurrence.
        
oTransform = oComp.Transformation ' Move the occurrence honoring any existing constraints.
oMatrix.SetToRotation( 180 *(PI/180), oTG.CreateVector(0, 1, 0), oTG.CreatePoint(0, 0, 0))
oComp.Transformation = oTransform

 

0 Likes
Message 5 of 8

TechInventor20
Advocate
Advocate

Play a little with it and then it will work. I don't remember exactly how it works, because it is inside a huge code, so I deleted some of the coding aroud it.

0 Likes
Message 6 of 8

Robert.Egel7SPMT
Explorer
Explorer

Hi 🙂

 

Thank you for the reply. What I need is a possibility to get the e.g. rx-value after it was placed.

 

For the Translation it is kind of easy, here I get the X-translation relative to the Overall Center Point:

oPosCylinder.Translation.X;

 

Is there something similar for the rotation-values?

 

Greetings!

0 Likes
Message 7 of 8

TechInventor20
Advocate
Advocate

can't find that either.. 

@johnsonshiue Could you look at this, i saw you kinda answer this question before.

 

0 Likes
Message 8 of 8

Robert.Egel7SPMT
Explorer
Explorer

Hello together,

@johnsonshiue : Can you help me out here? This'd be amazing 🙂

0 Likes