Rotate existing wall

Does anyone know how to get dynamo to work rotating walls with doors in them? The doors seems to fly off. Or for curtain walls?


Perplexity AI, rotate the wall using element transform function. Also rotate walls to the shortest distance. Things attached to walls dont like being flipped around.

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

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

doc = DocumentManager.Instance.CurrentDBDocument

def rotate_wall(wall, angle_degrees):
    # Convert degrees to radians
    angle_radians = math.radians(abs(angle_degrees))
    
    curve = wall.Location.Curve
    start_point = curve.GetEndPoint(0)
    end_point = curve.GetEndPoint(1)
    mid_point = XYZ(
        (start_point.X + end_point.X) / 2,
        (start_point.Y + end_point.Y) / 2,
        (start_point.Z + end_point.Z) / 2
    )
    
    # Create rotation axis based on angle sign
    if angle_degrees >= 0:
        axis = Line.CreateBound(mid_point, XYZ(mid_point.X, mid_point.Y, mid_point.Z + 1))
    else:
        axis = Line.CreateBound(mid_point, XYZ(mid_point.X, mid_point.Y, mid_point.Z - 1))
    
    TransactionManager.Instance.EnsureInTransaction(doc)
    ElementTransformUtils.RotateElement(doc, wall.Id, axis, angle_radians)
    TransactionManager.Instance.TransactionTaskDone()
    
    return wall

# Unwrap input walls and angles
walls = UnwrapElement(IN[0])
angles_degrees = IN[1]

# Ensure walls is a list
if not isinstance(walls, list):
    walls = [walls]

# Ensure angles_degrees is a list
if not isinstance(angles_degrees, list):
    angles_degrees = [angles_degrees]

# Rotate each wall with the specified angle
rotated_walls = [rotate_wall(wall, angle) for wall, angle in zip(walls, angles_degrees)]

OUT = rotated_walls
1 Like