Set a view cropbox error

Set a view cropbox error

Anonymous
Not applicable
2,527 Views
5 Replies
Message 1 of 6

Set a view cropbox error

Anonymous
Not applicable

Hi,

 

I have been trying to set a cropbox in a view. Here is snippet code

using (var trans = new Transaction(doc))
            {
                trans.Start("Set CropBox");

                var boundingBoxElement = elem.get_BoundingBox(null);
                newView.CropBoxActive = true;
                newView.CropBox = boundingBoxElement;
           
                trans.Commit();
            }

 

In debug I can see how the cropBox changes but when transaction is committed the cropBox has suddenly changed.

 

Why is this happening? transaction is committed successfully 

0 Likes
Accepted solutions (1)
2,528 Views
5 Replies
Replies (5)
Message 2 of 6

bhprest
Advocate
Advocate

From the Revit API documentation:

 

Remarks
Note: the Transform of the input BoundingBoxXYZ is ignored. Only Max and Min members of the input BoundingBoxXYZ are used.

 

I'm going to guess that this is what you're seeing. The min/max members of the input are used, but the view maintains  its original transform, but changes its min/max members to match the input values.

 

Hard to say w/o being in an active debug environment.

0 Likes
Message 3 of 6

TripleM-Dev.net
Advisor
Advisor

Also @bhprest the defined values can differ per view type. see: CropBox Property 

 

So setting the CropBox for a floorplan would normally have the expected result.

But for elevation, sections etc. the result depends on it's orientation and might need some transfroms of the min/max to align/project to the correct plane of the view.

 

@Anonymous , What type of view are you using, and what means "cropBox has suddenly changed" into what?

Maybe post a image before/after?

 

- Michel

Message 4 of 6

Anonymous
Not applicable

@TripleM-Dev.net  @bhprest  thanks for your answers. But I can not do it well yet. 

First of all, my view is a ViewPlan.

I am trying to set a cropBox in the view to see just a element. That's why I get element.get_BoundingBox(null), then I set view.CropBox with element boundingBox value. As @bhprest said " min/max members of the input are used " I did the following

 

         newView.CropBox.Min = boundingBoxElement.Min;
         newView.CropBox.Max = boundingBoxElement.Max;

 

But when I see it in the debug, neither value has changed. However, if  I do 

 

      newView.CropBox = boundingBoxElement;

 

CropBox changes.

 

my code now is:

 

  using (var trans = new Transaction(doc))
            {
                trans.Start("Set cropview");
                newView.CropBoxActive = false;
                var boundingBoxElement = elem.get_BoundingBox(null);
                

                newView.CropBox = boundingBoxElement;#Part2
                newView.CropBoxActive = true;
                newView.CropBoxVisible = false;

               trans.Commit();
            }

 

Just before starting #Part2

 

Both BoundaringBoxXYZ are different.

Once they have been assigned with

 

        newView.CropBox = boundingBoxElement;

 

 Both boundaringBoxXYZ are equal, except ZPart2.PNG

But after committing the transaction the view.CropBox changes and has the previous value again

afterTrans.PNG

 

I have checked the transaction and it was committed successfully

 

Any clue?  

0 Likes
Message 5 of 6

RPTHOMAS108
Mentor
Mentor

Might be it rejects the bounding box taken from the Element because some other aspect such as transform/BoundsEnabled etc. is invalid for the bounding box required by the view.

 

For a ViewPlan try getting bounding box from view and assign to independent variable then set the max/min based on bounding box from Element and then pass entire updated bounding box from variable back to view (rather than just it's properties as was done in first attempt). You may be bypassing hidden setter logic of the View.CropBox property by changing the properties of the bounding box directly (I've never found that to work). 

 

Also set CropBox active before applying bounding box.

0 Likes
Message 6 of 6

Anonymous
Not applicable
Accepted solution

I've just found the error, 

 

when there is a previous non-rectangular cropBox in the view. First you should remove the shape 

                var shapeManager = newView.GetCropRegionShapeManager();
                shapeManager.RemoveCropRegionShape();

 And then you can set the boundingBox that by default is a rectangle. 

0 Likes