Trying to rotate an assembly occurance

Trying to rotate an assembly occurance

breinkemeyer
Enthusiast Enthusiast
528 Views
3 Replies
Message 1 of 4

Trying to rotate an assembly occurance

breinkemeyer
Enthusiast
Enthusiast

I'm trying to rotate the end shaft in the drawing 90° along the X axis.  this is my code.  instead of rotating the shaft is moved to the opposite end.  What am I missing?

 

AssemblyDocument oDoc;
AssemblyComponentDefinition oCompDef;
ComponentOccurrence oCC;
Matrix oTransform;

oDoc = (AssemblyDocument)oInventorApp.ActiveDocument;
oCompDef = oDoc.ComponentDefinition;
int i = oCompDef.Occurrences.Count;
oCC = oCompDef.Occurrences[i];
oCC.Grounded = false;
oTransform = oCC.Transformation;
oTransform.SetToRotation(90.0 * DtoR, oITransGeo.CreateVector(1, 0, 0), oITransGeo.CreatePoint(1024.7, 0, 0));
oCC.Transformation = oTransform;
oCC.Grounded = true;

 

2023-02-28_8-04-23.png

0 Likes
Accepted solutions (2)
529 Views
3 Replies
Replies (3)
Message 2 of 4

Koekepeerke
Advocate
Advocate
Accepted solution

hello @breinkemeyer, it might be possible that you're not using the right axis to rotate around you could try adjusting your vector. you also should get the coördinates of the occurrence pre rotation so you can move the shaft back after rotation since rotating might reset the position to origin. this would look something like this (my code is VB.net:

rotatie = rotatiehoek * (Math.PI / 180)

Dim occ As ComponentOccurrence
occ = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Selecteer component")

Dim currentpos As Matrix = occ.Transformation

Dim centerpoint As WorkPoint = occ.Definition.Workpoints.item(1)
Dim centerproxy As WorkPointProxy : Call occ.CreateGeometryProxy(centerpoint, centerproxy)

Dim Xcoor As Double = Round(centerproxy.Point.X)
Dim Ycoor As Double = Round(centerproxy.Point.Y) 
Dim Zcoor As Double = Round(centerproxy.Point.Z*10)

Dim oPosition As Matrix = ThisApplication.TransientGeometry.CreateMatrix()

Call oPosition.SetToRotation(rotatie, ThisApplication.TransientGeometry.CreateVector(0, 0, 1), ThisApplication.TransientGeometry.CreatePoint(0, 0, 0))

Call currentpos.TransformBy(oPosition)
Call occ.SetTransformWithoutConstraints(currentpos)

Call currentpos.SetTranslation(ThisApplication.TransientGeometry.CreateVector(Xcoor, Ycoor, Zcoor/10))	
Call occ.SetTransformWithoutConstraints(currentpos)

occ.Grounded = True

I hope this might help!

Regards,

Jeremy

 

0 Likes
Message 3 of 4

JelteDeJong
Mentor
Mentor
Accepted solution

Just an other solution where i was working on:

AssemblyDocument oDoc = (AssemblyDocument)ThisApplication.ActiveDocument;
AssemblyComponentDefinition oCompDef = oDoc.ComponentDefinition;
int i = oCompDef.Occurrences.Count;
ComponentOccurrence oCC = oCompDef.Occurrences[i];
oCC.Grounded = false;

var orgMatrix = oCC.Transformation;
var rotationMatrix = oITransGeo.CreateMatrix();
rotationMatrix.SetToRotation(90.0 * DtoR, oITransGeo.CreateVector(1, 0, 0), oITransGeo.CreatePoint(1024.7, 0, 0));

var newMatrix = oITransGeo.CreateMatrix();
newMatrix.TransformBy(orgMatrix);
newMatrix.TransformBy(rotationMatrix);

oCC.Transformation = newMatrix;
oCC.Grounded = true;

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 4 of 4

breinkemeyer
Enthusiast
Enthusiast

That did the trick, thanks so much!  

0 Likes