Switch from pyRevit Script Window to Dialog Box

Hi, all.

The code at the bottom of the post rotates all selected objects by each of their center/axis points. Currently, that code will open the pyRevit stack/script window (the one that opens at the right side, specially if there are errors) to interact with the user, such as to ask what angle to rotate the objects.

Would anyone know how to change the code so that it uses the pyRevit form or Revit’s dialog box? I’d like to have the user interact with the tool in the most common way possible :slightly_smiling_face:

Thanks in advance,


from pyrevit import revit, DB
from pyrevit import script
import math

def rotate_elements(selection, angle):
    with revit.Transaction("Rotate Multiple Elements"):
        for element in selection:
            # Get the element's location and rotation axis
            location = element.Location
            if isinstance(location, DB.LocationPoint):
                axis = DB.Line.CreateBound(location.Point, location.Point.Add(DB.XYZ.BasisZ))
            elif isinstance(location, DB.LocationCurve):
                axis = location.Curve
                print("Cannot rotate element {}. Skipping...".format(element.Id))
            # Rotate the element about its center point or axis
            rotation = DB.ElementTransformUtils.RotateElement(revit.doc, element.Id, axis, angle)
            if rotation != DB.SetComparisonResult.Disjoint:
                print("Element {} rotated by {} degrees.".format(element.Id, math.degrees(angle)))

# Get user selection
selection = revit.get_selection()

# Get rotation angle from user input (in radians)
angle_degrees = float(input("Enter rotation angle in degrees: "))
angle_radians = math.radians(angle_degrees)

# Rotate selected elements
rotate_elements(selection, angle_radians)

Effective Input

1 Like

Great source page, @sanzoghenzo - I’m bound to find exactly what I need there.

Thank you very much!

1 Like