Auto dimension with python
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
import clr
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
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
def get_lower_points(element):
bounding_box = element.get_BoundingBox(uidoc.ActiveView)
if bounding_box:
min_point = bounding_box.Min
max_point = bounding_box.Max
lower_left_point = XYZ(min_point.X, min_point.Y, min_point.Z)
lower_right_point = XYZ(max_point.X, min_point.Y, min_point.Z)
return lower_left_point, lower_right_point
# Get the selected elements in the active view
selected_element_ids = uidoc.Selection.GetElementIds()
for element in selected_element_ids:
# Get the elements using their ElementIds
element1 = doc.GetElement(element)
# Create a ReferenceArray to store the references
refArr = ReferenceArray()
refArr.Append(Reference.ParseFromStableRepresentation(doc, element1.UniqueId + ":0:INSTANCE:" + element1.Symbol.UniqueId + ":1:SURFACE"))
refArr.Append(Reference.ParseFromStableRepresentation(doc, element1.UniqueId + ":0:INSTANCE:" + element1.Symbol.UniqueId + ":1:SURFACE"))
# Retrieve the lower points of the bounding boxes
lower_left_point, lower_right_point = get_lower_points(element1)
# Use the converted value to set the point
startPoint = lower_left_point
endPoint = lower_right_point
startPoint, endPoint
# Start a transaction
TransactionManager.Instance.EnsureInTransaction(doc)
# Create the dimension
doc.Create.NewDimension(doc.ActiveView, Line.CreateBound(startPoint, endPoint), refArr)
# Commit the transaction
TransactionManager.Instance.TransactionTaskDone()
Hello everyone,
i'm trying to automate the creation of dimensions for every selected element i've in the view. The script should create width dimension based on the bounding box of the element but instead its creating a 0 dimension in the lower center of the family. I know it's a little messy as written, but what is wrong?