Create Dimensions - Rooms
In this post, we discussed creating dimensions with the Revit API. But we only discussed dimensioning walls.
Sometimes, however, we want to dimensions to include other elements - balconies, for instance, which are not typically drawn with wall elements.
In this case, we can use our room separation lines.
def r2(num): return round(num, 2) doc = DocumentManager.Instance.CurrentDBDocument rooms = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements()
Once that's done, we can iterate through all these lines to find their maximum extents (for the purposes of this post, I'll assume we just want to dimension the rooms' x extents).
leftmost_x = float('inf') rightmost_x = 0 line_left = None line_right = None for line in roomlines: info = line.Location.Curve direction = info.Direction origin = info.Origin if r2(direction.X) == 0: #We only want vertical lines here if origin.X < leftmost_x: leftmost_x = origin.X line_left = line if origin.X > rightmost_x: rightmost_x = origin.X line_right = line
The rest of the process is identical to the one we used to dimension walls. We need to create a line and a reference array, then pass these items to Create.NewDimension()
#Create line for dimension top_point = 0 for line in roomlines: info = line.Location.Curve direction = info.Direction origin = info.Origin if r2(direction.Y) == 0: #We only want horizontal lines now if origin.Y > top_point: top_point = origin.Y dimension_y = top_point + 1 #Add a foot to ensure we're far enough away dimension_left_point = XYZ(leftmost_x, dimension_y, 0) dimension_right_point = XYZ(rightmost_x, dimension_y, 0) dimension_line = Line.CreateBound(dimension_left_point, dimension_right_point) #Create reference array reference_left = line_left.GeometryCurve.Reference reference_right = line_right.GeometryCurve.Reference refArray = ReferenceArray() refArray.Append(reference_left) #Note that "Append" is spelt with a capital A here! refArray.Append(reference_right) #Create dimension TransactionManager.Instance.EnsureInTransaction(doc) new_dim = doc.Create.NewDimension(doc.ActiveView, dimension_line, refArray) TransactionManager.Instance.TransactionTaskDone()
This code above can of course be combined with a wall-dimensioning script to allow for a mix of wall and room-separation-line dimensioning.
Comments
Post a Comment