Hi All,
I’ve used chatgpt to write a python script that creates a new elevation for every vertical surface of a room. I get various error messages when I try to run it. Does anybody have any idea why this might happen?
The script is below
import clr
clr.AddReference(‘RevitAPI’)
clr.AddReference(‘RevitAPIUI’)
import Autodesk
from Autodesk.Revit.UI import *
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Architecture import *
Get the current Revit document
doc = DocumentManager.Instance.CurrentDBDocument
Get all walls in the document
walls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements()
Get all rooms in the document
rooms = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements()
Loop through each room
for room in rooms:
# Get the closed shell of the room
shell = SpatialElementGeometryCalculator(doc).CalculateSpatialElementGeometry(room).GetGeometry()
# Loop through each face of the closed shell
for face in shell.Faces:
normal = face.ComputeNormal(UV.Zero)
if normal.Z == 0:
# This face is not vertical, skip it
continue
# Get the location point of the face
point = face.Origin
# Get the name of the wall that corresponds to this face
wall = None
for w in walls:
if w.Location.PointOnFace().IsAlmostEqualTo(point):
wall = w
break
if not wall:
# This face is not a wall, skip it
continue
# Get the mark parameter value of the wall
mark = wall.get_Parameter(BuiltInParameter.ALL_MODEL_MARK).AsString()
# Create a new elevation view
view = ViewSection.CreateElevation(doc, wall.GetTypeId(), wall.Id, point)
# Set the view's orientation to face the wall
view.SetOrientation(new XYZ(-normal.Y, normal.X, 0), new XYZ(normal.X, normal.Y, normal.Z))
# Set the view's name to the wall's mark value
view.Name = mark