Rotate Elevation Marker

Hello all,

I am trying to rotate an elevation marker. I have looked up many forum post on here as well as the ever popular Module 2. Module 2 got me close but I was not able to achieve what I wanted to do with it. The Python script was doing to much at once. I then found Rotate Family in archi-lab but it is not working. See Image below. The Python Script below rotate family is the code from the node. The node only gives null and the Python exports the Elevation Marker but does not rotate it.

image

I then tried to right my own code but get this err

“Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 26, in < module>
TypeError: expected Line, got Line”

EleId = UnwrapElement(IN[0])
Axis = UnwrapElement(IN[1])
Angle = UnwrapElement(IN[2])

TransactionManager.Instance.EnsureInTransaction(doc)

for EleId, Axis, Angle in zip(EleId, Axis, Angle):

	ElementTransformUtils.RotateElement(doc, EleId.Id, Axis, Angle)
	
TransactionManager.Instance.TransactionTaskDone()

OUT = EleID

Any help would be great,
Steven

I wasn’t sure how you were constructing your lines, etc. so I made a new code that constructs them within the Python script. In either case, the warning you got means it wanted an Autodesk.Revit.DB.Line and you were giving it a Dynamo Line so if you modify your axis input line to be UnwrapElement(IN[1]).ToRevitType() your code should work.

Here is the code I created; I haven’t modified it to handle lists yet but thought I would share now anyhow

import clr
import math

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

elev = UnwrapElement(IN[0])
angle_ = math.radians(IN[1])
view = UnwrapElement(IN[2])


TransactionManager.Instance.EnsureInTransaction(doc)

bbox = elev.BoundingBox[view]
diag = Line.CreateBound(bbox.Min,bbox.Max)
p1 = diag.Evaluate(0.5, True)
p2 = XYZ(p1.X, p1.Y,p1.Z+1)
axis_ = Line.CreateBound(p1, p2)
Autodesk.Revit.DB.ElementTransformUtils.RotateElement(doc, elev.Id, axis_, angle_)
	
TransactionManager.Instance.TransactionTaskDone()

OUT = elev

3 Likes

awilliams,
Thank you for your reply. I am very new to python and gave it my best shot but cannot figure it out. I tried adding UnwrapElement(IN[1]).ToRevitType() to my code but I get the err
"Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 28, in
AttributeError: ‘List[object]’ object has no attribute ‘ToRevitType’"

From my research I get this err because I am trying to run .ToRevitType() on a list rather than the items in the list.

I liked your code better though and think I almost got it to work with a list but not quite there. I get this err when I run your code (with my changes) on a list of marks.

“Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 38, in
TypeError: expected Line, got list”

import clr
import math

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

EleId = UnwrapElement(IN[0])
Angle = UnwrapElement(IN[1])
view = UnwrapElement(IN[2])
axis = []


TransactionManager.Instance.EnsureInTransaction(doc)


	
for EleId, Angle in zip(EleId, Angle):

	bbox = (EleId.BoundingBox[view])
	diag = Line.CreateBound(bbox.Min,bbox.Max)
	p1 = diag.Evaluate(0.5, True)
	p2 = XYZ(p1.X, p1.Y,p1.Z+1)
	axis_ = Line.CreateBound(p1, p2)
	axis.append(axis_)


	Autodesk.Revit.DB.ElementTransformUtils.RotateElement(doc, EleId.Id, axis, Angle)
	
TransactionManager.Instance.TransactionTaskDone()

OUT = EleID

Thank you for all of your help,
Steven

After a lot more tinkering and looking at code examples. I got the script to export the elevations markers with no warnings. It does not however rotate them. I am at a loss.

import clr
import math

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

EleId = UnwrapElement(IN[0])
Angle = UnwrapElement(IN[1])
view = UnwrapElement(IN[2])
axis = []
	
for i in EleId:

	bbox = (i.BoundingBox[view])
	diag = Line.CreateBound(bbox.Min,bbox.Max)
	p1 = diag.Evaluate(0.5, True)
	p2 = XYZ(p1.X, p1.Y,p1.Z+1)
	axis_ = Line.CreateBound(p1, p2)
	axis.append(axis_)
	
TransactionManager.Instance.EnsureInTransaction(doc)
element = []	
for EleId, axis, Angle in zip(EleId, axis, Angle):
	Autodesk.Revit.DB.ElementTransformUtils.RotateElement(doc, EleId.Id, axis, Angle)
	element.append(EleId)
	
TransactionManager.Instance.TransactionTaskDone()

OUT = element

Thanks for any help you can provide,
Steven

After hours and hours of trying to figure this out I finally got it to work. The code I provided above and the archi-lab Rotate Family nodes both work. The problem was not with the code but that you cannot rotate an elevation marker without a view on it. Yep thats it just make sure you have at least one view active on the marker and it will rotate just fine.

4 Likes

Hi Steven.

I’m trying to do exactly the same, and got the same problem. Always null even with an active view.

Please may you share your graph?

@franciscusm
Would you be able to post a screen shot of what your graph looks like and the problem that you are having. My graph has a bunch of other stuff in it and this could be a great learning opportunity for you and others looking at this post.

The Python script and the archi-lab node work differently so please also specify what one you are using.

Sure, the graph is a bit messy because it’s WiP, but the idea is select a section marker and select a wall to look at.

It’s currently using the Archi-Lab node, but tried also the Python code in this post and another node I don’t remember with no joy, always null.

Tried both radians and grads and several different axis: perpendicular to plan view plane, contained in plan view plane…

I’ve tried to rotate other elements and was able to rotate a furniture family with the FamilyInstance.SetRotation node but not the Elevation mark or a section. And not with the Rotate Family node.

PS I’m using Revit 2018.2 in case something changes in the API

Capture

I think you just need to turn you Elevation marker into a list. Orange group in my picture.

This worked for me. Similar work flow to what you have. I used the Python I posted above.

1 Like

Steven,

Thanks man. Your python code works, just needed to put Elevation Marker and Angle in lists.

BTW have you noticed that the View’s ID is always the Marker’s ID +1 ? It’s very helpful.

1 Like

It works, however the rotated angle makes no sense at all. Even if I try to rotate it only 1 degree it rotates circa 90 :hushed:

You are right mine does not work. I am not sure why though.

Try this out. Arch-lab node does not work when bundled (not sure what thats about). The last Python is the code provided in Rotate Family.

The first Python is pulled from my code above. You can not place a BBox around a marker so I used the code to find the center point. (Note: its not the exact center point if the marker is at an angle)

Let me know if this helps,


Home.dyn (16.2 KB)

It seems to work right when rotating 90 degrees but not when rotating a random angle. The same happened with the previous graph.

I can’t find a pattern or a reason. It’s really strange. The axis seems to be just a perpendicular line to the floor plane in all cases so that shouldn’t be the issue, it may just affect the location of the marker but not the angle.

The last code you provided moves the marker far away from the original point (maybe the line-axis coordinates need to be converted from Dynamo format to API format?).

I’VE THINK I’VE FOUND SOMETHING: for whatever reason the angle needs to be angle/2, sometimes…

Getting there:

Well, It seems that dynamo needs to calculate the angle first and then connect the node to rotate the marker. Also we need to be careful with the direction of the rotation, not only the angle when using the output from Vector.AngleWithVector node.

Also it seems we need to close and open dynamo to work (may keep wrong values in memory from previous runs) and rotate in the right direction, not just the angle from the Vector.AngleWithVector node.

+angle will rotate anti clockwise
-angle will do clockwise

The angle will depend on the wall’s external face side as well, which is not very intuitive.

Did you download the last graph I posed and try that? It seams to be working fine for me.

Сan anybody explain me what is mean “Evaluate” ? (p1 = diag.Evaluate(0.5, True) )

This method is basically the equivalent of the Dynamo node Curve.PointAtParameter, here is the API doc info: Evaluate Method I interpret the use of the word “evaluate” here as meaning determine (the point) which is at the normalized (True) parameter (0.5)

1 Like

Oh…ok … thank you!

and i want to ask aslo about:
Autodesk.Revit.DB.ElementTransformUtils.RotateElement(
this method is can rotate any revit elements ?

I’d think it can rotate anything that is an Autodesk.Revit.DB Element that contains geometry. If it can be rotated in Revit then that method can be used

1 Like

Yes, I tried that graph and happens what I commented. Same seems to happen with the graph I posted before except the marker remains in almost the same position when rotated.

If it makes a difference that marker I’m rotating is off axis from vert / horiz and the true north.

Anyway it seems that the trick is finding out the direction of rotation before rotating (which varies depending on which wall is selected, probably depending on the wall’s relative position from the marker).

Thanks for your help.

By the way, to get an Autodesk.Revit.DB element from a Dynamo one we use UnwrapElement.
However, how can be converted an Autodesk.Revit.DB to a Dynamo element?

Great , I got new knowledge
d

1 Like