View CropBox Resizing After Creation

View CropBox Resizing After Creation

Anonymous
Not applicable
1,829 Views
3 Replies
Message 1 of 4

View CropBox Resizing After Creation

Anonymous
Not applicable

Let's say I create a ViewPlan with a CropBox specified by the return value of a function "bounds(elements)".

 

t = Transaction(doc, "Create plan view."); t.Start()

view = ViewPlan.Create(doc, template.Id, level.Id)
view.CropBoxActive = True
view.CropBox = bounds(elements)

t.Commit()

 

This works well -- I get back a ViewPlan perfectly fitted around the elements I'm interested in.

 

Now let's say I want to change the aspect ratio of the ViewPlan after the initial commit (say, doubling the height of the CropBox). I can write a function "resize(current_cropbox, ratio)" that takes an existing ViewPlan's CropBox and desired aspect ratio and calculates a new CropBox meeting my aspect criteria. I then start a Transaction to update the CropBox:

 

t = Transaction(doc, "Attempt view resize"); t.Start()                                                                               view.CropBox = resize(view.CropBox, 2.0)
t.Commit()

 

This doesn't do anything. After the Commit(), the CropBox values remain unchanged, despite the fact that aspect() is calculating a new BoundingBoxXYZ object.

 

Why does this happen? Is it possible to modify a View's CropBox after creation? 

 

I see this has been asked before:

http://forums.autodesk.com/t5/revit-api/update-view-cropbox-extents/m-p/2442052/highlight/true#M1182

...but I haven't found a clear conclusion to the problem. Any pointers are appreciated.

 

Thanks in advance!

 

NB. Tested on Revit 2014 using IronPython.

0 Likes
Accepted solutions (1)
1,830 Views
3 Replies
Replies (3)
Message 2 of 4

Aaron.Lu
Autodesk
Autodesk

What about this:

List<Curve> nl = new List<Curve>();
XYZ p2 = new XYZ(-10.0, 0.0, 0.0);
XYZ p3 = new XYZ(10.0, 0.0, 0.0);
XYZ p4 = new XYZ(10.0, 0.0, 10.0);
XYZ p5 = new XYZ(-10.0, 0.0, 10.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);
}
else
{
    TaskDialog.Show("ERROR", "Failed");
}

doc.Regenerate();

 



Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 3 of 4

Aaron.Lu
Autodesk
Autodesk
Accepted solution

Furthermore, I created a new project, and haven't found any problem as yours.

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;
transaction.Commit();

 



Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 4 of 4

Anonymous
Not applicable

Thanks Aaron. Yes, I get the same result you do when I test on a simple sample model. I'll need to investigate the project model and code sections that caused the original problem, and see if I can recreate the result in isolation. Thanks again.

0 Likes