Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Cropbox of Plan cannot be resized

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
laDev
1080 Views, 6 Replies

Cropbox of Plan cannot be resized

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;
        }
    }

 

6 REPLIES 6
Message 2 of 7
augusto.goncalves
in reply to: laDev

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
Message 3 of 7
laDev
in reply to: augusto.goncalves

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.

Message 4 of 7
laDev
in reply to: laDev

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;
        }

 

 

 

Message 5 of 7
Ning_Zhou
in reply to: laDev

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

Did you use a transaction:

 

 

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

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

	rvtTransaction.Commit();

}

 

 

Brett

 

 

 

Regards,
Brett
Message 7 of 7
Ning_Zhou
in reply to: bburling

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

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community