Is it possible to set absolute location and rotation of existing element?

Is it possible to set absolute location and rotation of existing element?

ottosson_mathias
Advocate Advocate
2,742 Views
7 Replies
Message 1 of 8

Is it possible to set absolute location and rotation of existing element?

ottosson_mathias
Advocate
Advocate

I have an element that I want to move to a new position and rotate to a specified rotation.

 

Can this be done without first needing to calculate the difference in position and rotation? Now if I use ElementTransformUtils.MoveElement I just move the element relative to current position. I want to just specify the rotation and the position in absolute values.

 

I would like for it to be as simple as this mock code

 

myElement.Position= new XYZ(1000, 200, 0);
myElement.Rotation = 15; // degrees or whatever...

 

 

Are there any utilities that I'm not aware of that makes this easier?

 

Thanks!

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

Anonymous
Not applicable
Accepted solution

Sorry if I am wrong but maybe you can check if that works:

(element.Location as LocationPoint).Point=your value

0 Likes
Message 3 of 8

ottosson_mathias
Advocate
Advocate

Thanks!

 

That solved the moving part. So obvious when you say it, why didn't I think of that 😄

 

I wish it was just as simple to set the object rotation as well, but LocationPoint.Rotation seems to only expose a getter and no setter which means you can't have the same approach for rotation...

 

Any ideas?

0 Likes
Message 4 of 8

TripleM-Dev.net
Advisor
Advisor

Hi,

 

You mean this? RotateElement Method

 

- Michel

0 Likes
Message 5 of 8

Anonymous
Not applicable

This is how I rotate if I have to rotate on Z axis:

1. Get the locationPoint of element (var point);

2. Axis of rotation:var rotationLine= Line.CreateeUnbound(point,XYZ.BasisZ);

ElementTransformUtils.RotateElement(document, element.Id, rotationLine, 1);

Accept the solution if it solved your problem

 

 

0 Likes
Message 6 of 8

ottosson_mathias
Advocate
Advocate

That doesn't work. Using your rotate solution will only rotate the object more for every time I call the method. I want to just SET the rotation to a specific value. Element.LocationCurve.Rotation = 5 degrees... not having to create rotation lines and compare with current rotation to get an offset rotation value that puts it in the correct rotation.

 

But I'll guess I must accept that there are no easy utility functions for setting rotation.

 

Thanks!

0 Likes
Message 7 of 8

TripleM-Dev.net
Advisor
Advisor

You can also set the Transform property directly.....but it requires a direction vector and not a Angle so also not what you're looking for?

0 Likes
Message 8 of 8

Anonymous
Not applicable

The best way to rotate the element to one position is probably setting the transform but for Revit API beginner it might be complicated. My suggested solution I think is more simple if you have to rotate object only in XY plane. 

If you have one orientation of object like this XYZ(1,0,0), you can use your elements "hand orientation".

It might look like this. 

double rotationAngle=elem.HandOrientation.AngleTo(your XYZ) 

and then just simply use rotation function as I posted before. Dont forget, angle in Revit is in radians

0 Likes