Cropbox of Plan cannot be resized

Cropbox of Plan cannot be resized

Anonymous
Not applicable
1,412 Views
6 Replies
Message 1 of 7

Cropbox of Plan cannot be resized

Anonymous
Not applicable

I am trying to resize the Cropbox of the active view using the API for plans and sections using Revit 2013 . (This code was tested on Plan views).

 

The code below asks the user for a PickBox which is then applied as the Min and Max values of the Cropbox.

 

The cropbox appears to be created, but doesn't match the dimensions given (it just crops to the Revit default extents).

 

Does anyone have any suggestions for how to programmatically change the size of a 2D view cropbox? (I've seen the 3D tutorial here: http://thebuildingcoder.typepad.com/blog/2009/12/crop-3d-view-to-room.html, but I'm looking for how to crop 2D views)

 

   [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Automatic)]
    public class TestButton2 : IExternalCommand
    {
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
                                                        ref string message, ElementSet elements)
        {
            Autodesk.Revit.DB.View myNewCroppedView = commandData.Application.ActiveUIDocument.ActiveView;


            Autodesk.Revit.DB.ViewPlan myPlanView = myNewCroppedView as ViewPlan;

            Autodesk.Revit.UI.Selection.PickedBox myBox = commandData.Application.ActiveUIDocument.Selection.PickBox(Autodesk.Revit.UI.Selection.PickBoxStyle.Crossing);

         XYZ pt1 = myBox.Max;
            XYZ pt2 = myBox.Min;

            XYZ pt2WithNewZ = new XYZ(pt2.X, pt2.Y, -100);

            myNewCroppedView.CropBox.Max = pt1;
            myNewCroppedView.CropBox.Min = pt2WithNewZ;

            myNewCroppedView.CropBox.Enabled = true;
            myNewCroppedView.CropBoxActive = true;

            return Result.Succeeded;
        }
    }

 

0 Likes
Accepted solutions (1)
1,413 Views
6 Replies
Replies (6)
Message 2 of 7

augusto.goncalves
Alumni
Alumni

Not sure if I'm following you idea/goal...can you create it with Revit UI and provide us a image/printscreen?

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes
Message 3 of 7

Anonymous
Not applicable

Please see the attached expected behavior.

 

Also, please note that I don't expect PickBox (which returns a "PickedBox" object) to directly work as input to CropBox (which expects a BoundingBoxXYZ object). Instead, I manually pull out the MAX and MIN points and work directly with those.

 

Basically, I'm having trouble setting the View.CropBox Property as described in the View.CropBox Property documentation in the RevitApi.chm file that comes with the 2013 SDK. According to the docs, I should be able to set the CropBox extents, but I don't seem able to do so.

 

Any help would be much appreciated.

0 Likes
Message 4 of 7

Anonymous
Not applicable
Accepted solution

Finally figured it out.

 

Basically, Cropbox requires that CropBox.Max has the highest X, Y, and Z values. It does not accept arbitrary points (this seems obvious to me now, but I thought that just giving it two corners would solve the problem).

 

If you run into the same issue, I recommend sanitizing your X,Y,and Zs for Max and Min values prior to sending them to CropBox.Min or CropBox.Max.

 

Here's the function that I used:

        public BoundingBoxXYZ createBoundingBox(XYZ point1, XYZ point2)
        {
            double[] listX = { point1.X, point2.X };
            double[] listY = { point1.Y, point2.Y };
            double[] listZ = { point1.Z, point2.Z };

            XYZ ptMax = new XYZ(listX.Max(), listY.Max(), listZ.Max());
            XYZ ptMin = new XYZ(listX.Min(), listY.Min(), listZ.Min());


            BoundingBoxXYZ myBox = new BoundingBoxXYZ();
            myBox.Max = ptMax;
            myBox.Min = ptMin;

            return myBox;
        }

 

 

 

0 Likes
Message 5 of 7

Ning_Zhou
Advocate
Advocate
i used laDev code to update cropbox but nothing happens, i even added refreshview, regenerate, etc.
perhaps i missed something simple?!
0 Likes
Message 6 of 7

Anonymous
Not applicable

Did you use a transaction:

 

 

using (Transaction rvtTransaction = new Transaction(document)) {
	rvtTransaction.Start("Crop View");

       //code to crop view here.....

	rvtTransaction.Commit();

}

 

 

Brett

 

 

 

0 Likes
Message 7 of 7

Ning_Zhou
Advocate
Advocate

thanks bburling.

regenerate requires transaction so it's already there.

i'm using active view, is it the reason?

 

edit: never mind, i used cropbox.max / min instead of using cropbox directlySmiley Embarassed

 

0 Likes