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.
I then tried to right my own code but get this err
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
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: 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)
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?