Message 1 of 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm using a room to create elevations, then crop them to the extents of the room. For some of the models the approach is not working and I cannot figure out why. these are my steps:
- place the sections along each boundary
- get the BBox of the room in each of the created sections
- deduct the outline of the view from the bbox
In some of the models this method returns a BBox that seams to be equal to a 3D Bbox of the room (instead of the desired BBox in view).
here's my code:
def set_crop_to_bb(element, view, crop_offset, doc=revit.doc):
# set the crop box of the view to elements's bounding box in that view
# draw 2 sets of outlines for each orientation (front/back, left/right)
# # deactivate crop first, just to make sure the element appears in view
view.CropBoxActive = False
doc.Regenerate()
bb = element.get_BoundingBox(view)
active_view = revit.active_view
#debug
footprint = get_bb_outline(bb)
for curve in footprint:
l = doc.Create.NewDetailCurve(active_view, curve)
pt1 = DB.XYZ(bb.Max.X, bb.Max.Y, bb.Min.Z)
pt2 = DB.XYZ(bb.Max.X, bb.Max.Y, bb.Max.Z)
pt3 = DB.XYZ(bb.Min.X, bb.Min.Y, bb.Max.Z)
pt4 = DB.XYZ(bb.Min.X, bb.Min.Y, bb.Min.Z)
pt7 = DB.XYZ(bb.Min.X, bb.Max.Y, bb.Min.Z)
pt8 = DB.XYZ(bb.Min.X, bb.Max.Y, bb.Max.Z)
pt5 = DB.XYZ(bb.Max.X, bb.Min.Y, bb.Max.Z)
pt6 = DB.XYZ(bb.Max.X, bb.Min.Y, bb.Min.Z)
l1 = DB.Line.CreateBound(pt1, pt2)
l2 = DB.Line.CreateBound(pt2, pt3)
l3 = DB.Line.CreateBound(pt3, pt4)
l4 = DB.Line.CreateBound(pt4, pt1)
l5 = DB.Line.CreateBound(pt6, pt5)
l6 = DB.Line.CreateBound(pt5, pt8)
l7 = DB.Line.CreateBound(pt8, pt7)
l8 = DB.Line.CreateBound(pt7, pt6)
curves_set1 = [l1, l2, l3, l4]
curves_set2 = [l5, l6, l7, l8]
crsm = view.GetCropRegionShapeManager()
view_direction = view.ViewDirection
view.CropBoxActive = True
try:
# try with set 1, if doesn't work try with set 2
crop_loop = DB.CurveLoop.Create(List[DB.Curve](curves_set1))
# offset the crop with the specified offset
curve_loop_offset = DB.CurveLoop.CreateViaOffset(crop_loop, crop_offset, view_direction)
# in case the offset works inwards, correct it to offset outwards
if curve_loop_offset.GetExactLength() < crop_loop.GetExactLength():
curve_loop_offset = DB.CurveLoop.CreateViaOffset(crop_loop, crop_offset, -view_direction)
crsm.SetCropShape(curve_loop_offset)
except:
crop_loop = DB.CurveLoop.Create(List[DB.Curve](curves_set2))
#
# curve_loop_offset = DB.CurveLoop.CreateViaOffset(crop_loop, crop_offset, view_direction) # fails here
# if curve_loop_offset.GetExactLength() < crop_loop.GetExactLength():
# curve_loop_offset = DB.CurveLoop.CreateViaOffset(crop_loop, crop_offset, -view_direction)
# crsm.SetCropShape(curve_loop_offset)
return
Thanks!
Daria
Solved! Go to Solution.