# Rotate existing wall

**URL:** <https://forum.dynamobim.com/t/rotate-existing-wall/106653>\
**Category:** Uncategorized\
**Created:** [December 17, 2024, 9:56pm UTC](https://forum.dynamobim.com/t/rotate-existing-wall/106653 "2024-12-17T21:56:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanman](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vanman/32/20881_2.png) [@vanman](https://forum.dynamobim.com/u/vanman)\
**Post date:** [December 17, 2024, 9:56pm UTC](https://forum.dynamobim.com/t/rotate-existing-wall/106653/1 "2024-12-17T21:56:34Z")

</div>

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?

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/1/215a8118e9b8f08843f1faa9e88a74418639f83d.png)  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/3/6386debf744afa62662877a10fe2ca13f0ae4ed0.png)

---

<div class="post-metadata">

**Author:** ![vanman](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vanman/32/20881_2.png) [@vanman](https://forum.dynamobim.com/u/vanman)\
**Post date:** [December 18, 2024, 2:35am UTC](https://forum.dynamobim.com/t/rotate-existing-wall/106653/2 "2024-12-18T02:35:08Z")

</div>

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.

```auto
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

```
