Question:
Why does nothing happen when setting the cropbox of view?
What he did is, first create a view and then set its CropBox property.
ViewFamilyType vTypeElev = Class1.getviewfamilytypes(
ViewFamily.FloorPlan, RevitDoc).First<ViewFamilyType>();
var view = ViewPlan.Create(RevitDoc, vTypeElev.Id,
RevitDoc.ActiveView.GenLevel.Id);
view.CropBoxActive = true;
BoundingBoxXYZ box = new BoundingBoxXYZ();
box.Min = new XYZ(100, 100, 0);
box.Max = new XYZ(200, 200, 100);
view.CropBox = box;
and he said it works (note: above code should be included in transaction).
However, when he change the CropBox seperately, there is nothing happen:
var view = RevitDoc.ActiveView;
BoundingBoxXYZ box = new BoundingBoxXYZ();
box.Min = new XYZ(0, 0, 0);
box.Max = new XYZ(100, 100, 100);
view.CropBox = box;
I tried his code, which works on my machine, I’m not sure why.
Even thouogh, I suggested him another way: using method SetCropRegionShape of class ViewCropRegionShapeManager:
double length = 100;
var view = RevitDoc.ActiveView;
List<Curve> nl = new List<Curve>();
XYZ p2 = new XYZ(0, 0, 0);
XYZ p3 = new XYZ(length, 0, 0);
XYZ p4 = new XYZ(length, length, 0);
XYZ p5 = new XYZ(0, length, 0);
nl.Add(Line.CreateBound(p2, p3));
nl.Add(Line.CreateBound(p3, p4));
nl.Add(Line.CreateBound(p4, p5));
nl.Add(Line.CreateBound(p5, p2));
CurveLoop cl = CurveLoop.Create(nl);
ViewCropRegionShapeManager vpcr = view.GetCropRegionShapeManager();
bool cropValid = vpcr.IsCropRegionShapeValid(cl);
if (cropValid)
{
vpcr.SetCropRegionShape(cl);
}
which is much powerful, because it not only support rectangle but other shapes.

Leave a Reply to Vlad PalyCancel reply