View Cropping

View Cropping

The crop region for some views may be modified using the Revit API. The ViewCropRegionShapeManager.Valid property indicates whether the view is allowed to manage the crop region shape while the ShapeSet property indicates whether a shape has been set. The following example crops a view around the boundary of a room.

Code Region: Cropping a view

public void CropAroundRoom(Room room, View view)
{
    if (view != null)
    {
        IList<IList<Autodesk.Revit.DB.BoundarySegment>>  segments = room.GetBoundarySegments(new SpatialElementBoundaryOptions());

        if (null != segments)  //the room may not be bound
        {
            foreach (IList<Autodesk.Revit.DB.BoundarySegment> segmentList in segments)
            {
                CurveLoop loop = new CurveLoop();
                foreach (Autodesk.Revit.DB.BoundarySegment boundarySegment in segmentList)
                {
                    loop.Append(boundarySegment.Curve);
                }

                ViewCropRegionShapeManager vcrShapeMgr = view.GetCropRegionShapeManager();
                vcrShapeMgr.SetCropRegionShape(loop);
                break;  // if more than one set of boundary segments for room, crop around the first one
            }
        }
    }
}