Hello!
Ive been working on automizing creating elevations and CropBox from the model. I have a problem with BoundingBoxes and Transform Class.
Here is my Bounding Box getting method with the first problem: No matter which view I input, the BoundingBox is the same. Is it a bug that is common? I understood from RevitAPIdocs that it should give me the view`s own boundingbox of those elements.
def get_model_bounding_box(view):
doc = (I have my integrated method to do doc, which i skipped here, so dont mind this)
categories = [BuiltInCategory.OST_Columns, BuiltInCategory.OST_GenericModel,
BuiltInCategory.OST_StructuralFraming, BuiltInCategory.OST_Floors]
bounding_box = None
elements = []
for category in categories:
elements.extend(FilteredElementCollector(doc).OfCategory(category).WhereElementIsNotElementType().ToElements())
for element in elements:
bbox = element.get_BoundingBox(view)
if bbox is not None:
if bounding_box is None:
bounding_box = bbox
else:
bounding_box.Min = XYZ(
min(bounding_box.Min.X, bbox.Min.X),
min(bounding_box.Min.Y, bbox.Min.Y),
min(bounding_box.Min.Z, bbox.Min.Z)
)
bounding_box.Max = XYZ(
max(bounding_box.Max.X, bbox.Max.X),
max(bounding_box.Max.Y, bbox.Max.Y),
max(bounding_box.Max.Z, bbox.Max.Z)
)
return bounding_box
And here is the main code:
bounding_box = get_model_bounding_box(None)
print("Model:")
print(bounding_box.Min)
print(bounding_box.Max)
print(bounding_box.Max.X - bounding_box.Min.X)
print(bounding_box.Max.Y - bounding_box.Min.Y)
print(bounding_box.Max.Z - bounding_box.Min.Z)
transform = elevation_north.CropBox.Transform
transformed_bounding_box = BoundingBoxXYZ()
transformed_bounding_box.Transform = transform
min_point = transform.OfPoint(bounding_box.Min)
max_point = transform.OfPoint(bounding_box.Max)
transformed_bounding_box.Min = XYZ(min(min_point.X, max_point.X), min(min_point.Y, max_point.Y), min(min_point.Z, max_point.Z))
transformed_bounding_box.Max = XYZ(max(min_point.X, max_point.X), max(min_point.Y, max_point.Y), max(min_point.Z, max_point.Z))
print("After transformation North:")
print(transformed_bounding_box.Min)
print(transformed_bounding_box.Max)
print(transformed_bounding_box.Max.X - transformed_bounding_box.Min.X)
print(transformed_bounding_box.Max.Y - transformed_bounding_box.Min.Y)
print(transformed_bounding_box.Max.Z - transformed_bounding_box.Min.Z)
t = Transaction(doc, 'Set Crop Box')
t.Start()
elevation_north.CropBoxActive = True
elevation_north.CropBoxVisible = False
elevation_north.CropBox = transformed_bounding_box
t.Commit()
After I run this the newly created elevation has a Cropbox like so:
Applying the elevation Transform to the BoundingBox changes Z to Y (ca. +79), Y to Z (without change) and X to X (ca. +27). The CropBox in ElevationView appears around 79 units too high (as it was transformed). Why the addition?
Also here is how i create elevations, maybe its relevant:
def create_elevation(view_name, view_direction):
doc =
view_types = DB.FilteredElementCollector(doc).OfClass(ViewFamilyType).ToElements()
view_types_elevations = [vt for vt in view_types if vt.ViewFamily == ViewFamily.Elevation]
elevation_type = view_types_elevations[0]
if view_direction.lower() == "north":
angle = 0.5 * math.pi
elif view_direction.lower() == "south":
angle = 1.5 * math.pi
elif view_direction.lower() == "west":
angle = math.pi
elif view_direction.lower() == "east":
angle = 0
floor_plan = create_floor_plan(view_name)
bounding_box = get_grid_lines_bounding_box(floor_plan)
min_point = bounding_box.Min
max_point = bounding_box.Max
corners = {
"north": [XYZ(min_point.X, max_point.Y, 0), XYZ(max_point.X, max_point.Y, 0)],
"south": [XYZ(min_point.X, min_point.Y, 0), XYZ(max_point.X, min_point.Y, 0)],
"west": [XYZ(min_point.X, min_point.Y, 0), XYZ(min_point.X, max_point.Y, 0)],
"east": [XYZ(max_point.X, min_point.Y, 0), XYZ(max_point.X, max_point.Y, 0)]}
midpoints = {
"north": XYZ((min_point.X + max_point.X) / 2, max_point.Y, 0),
"south": XYZ((min_point.X + max_point.X) / 2, min_point.Y, 0),
"west": XYZ(min_point.X, (min_point.Y + max_point.Y) / 2, 0),
"east": XYZ(max_point.X, (min_point.Y + max_point.Y) / 2, 0)}
depth = max(max_point.X - min_point.X, max_point.Y - min_point.Y)
marker_XYZ = midpoints[view_direction.lower()]
t = Transaction(doc, 'Create View')
t.Start()
marker = ElevationMarker.CreateElevationMarker(doc, elevation_type.Id, marker_XYZ, 50)
elevation_view = marker.CreateElevation(doc, floor_plan.Id, 0)
# Set the bound offset
p = elevation_view.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR)
p.Set(depth)
# Rotate the marker
rotation_axis = Line.CreateBound(marker_XYZ, marker_XYZ + XYZ.BasisZ)
ElementTransformUtils.RotateElement(doc, marker.Id, rotation_axis, angle)
elevation_view.Name = view_name
t.Commit()
return elevation_view, marker_XYZ, floor_plan
Any help is greatly appreciated!