Rotate UCS twice

Rotate UCS twice

rikard.nilsson
Collaborator Collaborator
764 Views
3 Replies
Message 1 of 4

Rotate UCS twice

rikard.nilsson
Collaborator
Collaborator

Hi!

 

In the attached file you will find a Rule that rotates an UCS.
The problem I have is that it only rotates once even if I run the rule multiple times.

 

I really would like to know why? and if there is a way to rotate it more than one time.

 

Regards

Rikard

 

Here is the code..

 

	Dim pdoc As PartDocument = ThisDoc.Document
	Dim pdef As PartComponentDefinition = pdoc.ComponentDefinition
	
	Dim otg As TransientGeometry = ThisApplication.TransientGeometry


	Dim oUCS As UserCoordinateSystem = pdef.UserCoordinateSystems.Item("UCS1")
	Dim oUCSDef As UserCoordinateSystemDefinition = oUCS.Definition
	
	Dim oMatrix As Matrix = otg.CreateMatrix()
	oMatrix = oUCSDef.Transformation


	Dim vectest1 As Vector = otg.CreateVector(oMatrix.Cell(1, 2), oMatrix.Cell(2, 2), oMatrix.Cell(3, 2))
	oMatrix.SetToRotation(-PI/10, otg.CreateVector(1, 0, 0), otg.CreatePoint(0, 0, 0))

	Dim vectest2 As Vector = otg.CreateVector(oMatrix.Cell(1, 2), oMatrix.Cell(2, 2), oMatrix.Cell(3, 2))
	MessageBox.Show(vectest1.AngleTo(vectest2), "Test")


	oUCSDef.Transformation = oMatrix
	InventorVb.DocumentUpdate()

 

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

DRoam
Mentor
Mentor
Accepted solution

I think your code is just setting the rotation to "-PI/10". Where it says "-PI/10", it needs to say something like:

 

CurrentAngle - PI/10

I'm not very good with CS transformations so I'm not sure how you would get CurrentAngle, but I think doing that would fix the issue.

0 Likes
Message 3 of 4

rikard.nilsson
Collaborator
Collaborator

Thanks!

 

It feels a little bit strange.. For me SetToRotation should be just to take a matrix and rotate it with some degrees.

But I understand what you mean and have changed the code to work with your suggestion.

 

/Rikard

0 Likes
Message 4 of 4

DRoam
Mentor
Mentor

Yeah, I see what you mean. But I think "SetToRotation" is meant to be provided with some absolute rotation angle (around an axis), and it will Set the matrix To that absolute Rotation. Hence the name.

 

But I agree it would make sense to have a new "RotateBy" method, which we could provide with a relative rotation angle (around an axis), and it would Rotate the matrix By that relative amount. You could maybe create a request for that in the Ideas forum if you think it would be useful.

 

Either way, glad you got it working. If you wouldn't mind, could you post your working code? I'd like to see how you got the current angle of the UCS.

0 Likes