How to Rotate a column in Dynamo Python?

Hello,

I am wondering if someone can help me with an issue.
I am trying to rotate a structural column around its vertical axis:

image

This is the code I am using:

# load libraries
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI.Selection import *

from Autodesk.Revit.DB import Transaction

import System.Collections.Generic.List as List
import math
import sys

doc = DocumentManager.Instance.CurrentDBDocument




# el
el = UnwrapElement(IN[0])
el_id = el.Id

# rotation line
cenPt = el.Location.Point
vecUp = Autodesk.Revit.DB.XYZ(0,0,1)
rotAx = Autodesk.Revit.DB.Line.CreateBound( cenPt, cenPt + vecUp )

# rotation angle
rotAngle = math.radians(45)  # rotate input column by 45 degrees



TransactionManager.Instance.EnsureInTransaction( doc )
Autodesk.Revit.DB.ElementTransformUtils.RotateElement(doc, el_id, rotAx, rotAngle)
TransactionManager.Instance.TransactionTaskDone()

When I run the code first time, it works without issues:

However, if I apply ‘Undo’ in Revit, and run the Dynamo Python node again, the rotation is performed for 90 degrees (even though I still have 45 degrees defined in the code). Why is this happening?

I identified that this problem appears only when I am using Dynamo’s ‘RevitServices.Transactions.TransactionManager’. If I use Revit’s ‘Autodesk.Revit.DB.Transaction’, the column is correctly rotated by 45 degrees, each time I run the Dynamo Python node.

Does anyone have an explanation, why is ‘RevitServices.Transactions.TransactionManager’ buggy in this situation?
According to posts on this forum, there is no reason not to use Dynamo TransactionManager, it is actually advised to use it instead of Revit one.

Any help is appreciated. I am using Revit 2019.2 and Dynamo 2.0.2

Attached are files.
rotateColumn.rvt (3.0 MB)
rotateColumn.dyn (5.7 KB)

@george you can find more than one solution here:

1 Like

Thank you for the reply @Elie.Trad ,

I am trying to use Revit API to rotate the structural column. I see you used Revit Nodes.
As for @sovitek 's advice: I get False when checking the property of the structural column family instance:

# el
el = UnwrapElement(IN[0])
OUT = el.CanRotate  # returns 'False'

It guess it has to be a bug with the Dynamo ‘RevitServices.Transactions.TransactionManager’ namespace?

@george change the Column Style parameter to anything other than Vertical, then change the Cross-Section Rotation value to any angle value you want, I am sure these parameters are accessible through the API.

2 Likes

Thank you for the help once again @Elie.Trad ,

I tried changing the “Column Style” parameter to both Slanted - Angle Driven and Slanted - End Point Driven:

image

but in both cases I get “False” on the OUT = el.CanRotate.
Even if I got “True”, under the “FamilyInstance” class I see only one method “rotate”, and it only rotates by 180 degrees, it has no input for the rotation angle.
So the correct Revit API way to do it has to be through Autodesk.Revit.DB.ElementTransformUtils.RotateElement, I just don’t understand why Dynamo TransactionManager fails. And even so it makes uneasy if I should ever use the TransactionManager again for other transactions.

A few questions:

  1. If you move the Python into a custom node, does that resolve the undo issue?
  2. If you use the out of the box nodes instead of Python does that resolve the undo issue?
  3. If you use Python 3 (in Revit 2022) does that resolve the undo issue?
  4. If you set the parameter for cross section rotation instead of rotating the element, does that resolve the undo issue?
  5. If you update to the lastest version of Revit (2019.2.4) and Dynamo for Revit 2019 (2.0.4), does that resolve the undo issue? Note that Revit 2019 will no longer be supported in a few months, so it’s time to upgrade anyway.
  6. If you run via Dynamo Player, does that resolve the undo issue?
  7. If you undo twice instead of once, does that resolve the undo issue?

If all of those are false, submit a GitHub issue here and the Dev team will look into it. Issues ¡ DynamoDS/DynamoRevit ¡ GitHub

1 Like

Hi Jacob,

3 ) I have just tested the code on Revit 2022 and Dynamo 2.10.1 and IronPython2 (not CPython). There are no problems at all. So the bug must have been in Dynamo 2.0.2 for Revit 2019.
The reason why I still stick with 2019, is because our current project is using this version (the architect client sends the .rvt file in 2019 format), so I have everything setup (custom Dynamo node packages also) on Revit 2019. But I agree with your advice, I should start working in 2022.

1 ) I haven’t tried this.
2 ) It’s hard to compare. RevitNodes ‘FamilyInstance.SetRotation’ does not allow a “cumulative rotation”, which what I am after. By cumulative, I mean: it will not rotate the column by 45 degrees more, if rotation angle input remains 45. Literally it will not perfom rotation at all, it will stay the same.
But yes, there are no issues with Undo when it comes to ‘FamilyInstance.SetRotation’ node.
4 ) The structural column in question does not have the ‘Cross-Section Rotation’ parameter.
5 ) I didn’t try this.
6 ) Didn’t try it.
7 ) Didn’t try it.

Thank you for the help!

The screenshot above indicates that parameter exists as an instance parameter, so I made an assumption. It’s likely best to post a sample RVT and the full DYN, otherwise we’re stuck guessing.

If you’re using ‘additive’ 45, than this result would make sense as you’re creating the same instance a second time, so Dynamo’s seeing it as the same thing, the rotation would report as 45 as that was what it was before, and then it’ll add another 45 to that. If you use 10 degrees does the rotation wind up at 20 degrees?

Best to flag this as needing an upgrade now then - you’re clearly in the Design phase which means that there is ZERO chance of completing the project before the end of support.

1 Like

One can download the .rvt and .dyn files in the first reply of the topic.
And you are right, there’s ‘Cross-Section Rotation’ parameter. I just had to switch “Column Style” parameter to either Slanted - Angle Driven orSlanted - End Point Driven. When it’s at `Vertical’, only then the ‘Cross-Section Rotation’ parameter does not exist.
And you were right - I could also rotate the column by changing this ‘Cross-Section Rotation’ parameter, it’s just it does not support cumulative rotation.

It should work cumulative - this is what I need. If I use something less than 45 (like 20 or 22.5), then it also works cumulative. The bug was definitely with Dynamo 2.0.2.

I think the reason why the architect is still with Revit 2019 is because they have some plugin made for that version. An external CAD office made it for them, and they would have to pay again if they would like to use it on Revit 2022. At least that’s the information I got, don’t know if this is the reason.

Thank you for the help Jason!