Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed. ImportError: No module named Autodesk.Revit.DB

hi, im trying to run a python code for moving all the doors in my model to be 18" away from the wall parallel to the door swing at 90 degrees. i havent found any topics on here that discuss the Autodesk. Revit. DB import to be causing issues so any help is greatly appreciated!

Below is my python script:

import clr
import math
clr.AddReference('RevitServices') 
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Input: List of door elements from Dynamo
doors = IN[0]

# Get the current document
doc = DocumentManager.Instance.CurrentDBDocument

def move_doors(doc, doors):
    TransactionManager.Instance.EnsureInTransaction(doc)

    for door in doors:
        location = door.Location
        
        if isinstance(location, LocationCurve):
            # For doors with a line location
            location_curve = location.Curve
            
            # Get swing angle
            swing_param = door.LookupParameter("Swing Angle")
            swing_angle = swing_param.AsDouble() if swing_param else 0
            
            # Calculate midpoint
            door_position = location_curve.Evaluate(0.5, True)  # Midpoint
            
            # Calculate offset direction based on swing angle
            rotation_vector = XYZ(math.cos(swing_angle), math.sin(swing_angle), 0)
        
        elif isinstance(location, LocationPoint):
            # For doors with a point location
            door_position = location.Point
            
            # Assuming swing angle is available for point doors as well
            swing_param = door.LookupParameter("Swing Angle")
            swing_angle = swing_param.AsDouble() if swing_param else 0
            
            # Calculate offset direction based on swing angle
            rotation_vector = XYZ(math.cos(swing_angle), math.sin(swing_angle), 0)

        else:
            # Skip if the location type is neither
            continue
        
        # Offset by 18 inches (converted to feet)
        offset = rotation_vector * (18 / 304.8)
        
        # New location
        new_location = door_position + offset
        
        # Move the door
        ElementTransformUtils.MoveElement(doc, door.Id, new_location - door_position)

    TransactionManager.Instance.TransactionTaskDone()

# Call the function
move_doors(doc, doors)

# Output: Indicate successful completion
OUT = "Doors moved successfully."

Admin Edit: formatted text

Please make sure you’re formatting your code so it comes across correctly.

You don’t have a reference to the API in your node and it may not be referenced anywhere else in your graph. What happens if you import the API first?
clr.AddReference('RevitAPI')

1 Like

worked thank you!