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”
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
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.
@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
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)
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.
This method is basically the equivalent of the Dynamo node Curve.PointAtParameter, here is the API doc info: http://www.revitapidocs.com/2017/1145f18e-3e01-60df-e438-e176c38c3ce9.htm I interpret the use of the word “evaluate” here as meaning determine (the point) which is at the normalized (True) parameter (0.5)
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
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?
This is the final version of my graph based on @Steven and @awilliams code above (thanks both). I won’t try to figure out the direction of rotation so I added an option to select it ( usually the smaller rotation is the right direction).
Inputs are the Elevation Mark to rotate, the wall to look at and the elevation that will look at that wall (and the direction of rotation clockwise or not).
Just ended up using this for room elevations. Cant remember whos code it is but this line seems to be what susses it. Would be cool to get how it does. Probably adapt for anything and elevations