Element.rotate node rounds off degree values

Hi, so I’m using DynaMEP node “Element.Rotate” to rotate a few elements with it’s family origin, my issue is that it rounds off the degree values, is there any other solution?

@rajeshjamariya16

can you share a screenshot ? and the code also. maybe you can skip the rounding.

1 Like

I used ChatGPT code to get it working.

Hi @rajeshjamariya16 now we have a solution, could you please show it ?

1 Like
import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

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

import math

# Revit document
doc = DocumentManager.Instance.CurrentDBDocument

# Inputs
elements = UnwrapElement(IN[0])  # List of elements to rotate
angles = IN[1]  # List of angles in degrees for rotation

def degrees_to_radians(degrees):
    """Convert degrees to radians."""
    return degrees * (math.pi / 180.0)

def rotate_elements_in_plan(doc, elements, angles):
    """Rotate elements in plan view by specified angles around their location point."""
    TransactionManager.Instance.EnsureInTransaction(doc)
    
    # Ensure the lengths of elements and angles match
    num_elements = len(elements)
    num_angles = len(angles)
    
    # Apply a dummy rotation to the first element to avoid issues
    if num_elements > 0:
        first_element = elements[0]
        first_angle = angles[0] if num_angles > 0 else 0

        location = first_element.Location
        if hasattr(location, 'Point'):
            origin_point = location.Point
            rotation_axis = Line.CreateUnbound(origin_point, XYZ(0, 0, 1))
            angle_rad = degrees_to_radians(first_angle)
            # Apply a dummy rotation
            ElementTransformUtils.RotateElement(doc, first_element.Id, rotation_axis, angle_rad)
    
    # Rotate the elements
    for index in range(min(num_elements, num_angles)):
        element = elements[index]
        angle = angles[index]

        location = element.Location
        if not hasattr(location, 'Point'):
            continue
        
        origin_point = location.Point  
        
        # Debugging output: Print element information
        print(f"Rotating Element ID: {element.Id}, Origin: {origin_point}, Angle: {angle}")

        rotation_axis = Line.CreateUnbound(origin_point, XYZ(0, 0, 1))
        angle_rad = degrees_to_radians(angle)
        ElementTransformUtils.RotateElement(doc, element.Id, rotation_axis, angle_rad)

    TransactionManager.Instance.TransactionTaskDone()
    return "Elements rotated successfully."

# Execute rotation in plan view
OUT = rotate_elements_in_plan(doc, elements, angles)

2 Likes