Revit API

Reply
Valued Contributor
grahamcook
Posts: 52
Registered: ‎06-18-2012
Message 1 of 10 (941 Views)

Modify CropBox of Elevation View

941 Views, 9 Replies
09-03-2012 04:39 AM

I am having difficulty in modifying the cropbox of an elevation view.  The extract code below will place an elevation marker in a room and then create an elevation off index 0 of the marker.  I then get the existing cropbox and attempt to reduce the height by 3 feet (just as an example).  The code runs successfully (within a transaction) but the result is as per the original cropbox, ie, no change.  When an elevation marker is placed in a room using the User Interface Revit will automatically find the extents of the room and set the crop box accordingly.  I'm wondering if this behavior is overwriting the changes I make via the API?

 

ElevationMarker elevMarker = 
ElevationMarker.CreateElevationMarker(doc, vft.Id, roomCenter, scale);

ViewSection sv = elevMarker.CreateElevation(doc, viewPlan.Id, 0);
doc.Regenerate();

// get the bounding box of the section
BoundingBoxXYZ bb = sv.CropBox;

// by way of example reduce the section height by 3 foot
XYZ max = bb.Max;
max = new XYZ(max.X, max.Y - 3, max.Z);
bb.Max = max;

// set the new bounding box
sv.CropBox = bb;

 

ADN Support Specialist
Joe.Ye
Posts: 334
Registered: ‎03-05-2010
Message 2 of 10 (930 Views)

Re: Modify CropBox of Elevation View

09-05-2012 12:24 AM in reply to: grahamcook

 

It is likely that Revit overwrite the cropbox when the transaction is submitted. However not sure, as I didn't test this.

 

This idea just came to my mind. 

Can you use two transactions to do this?

Start the first transaction to create the section marker and the section view, then commit the transaction.

Start the second transaction to change the crop box.

 

 



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Valued Contributor
grahamcook
Posts: 52
Registered: ‎06-18-2012
Message 3 of 10 (926 Views)

Re: Modify CropBox of Elevation View

09-05-2012 04:28 AM in reply to: grahamcook

Joe, thanks for your suggestion.

 

I tried the idea of creating a second transaction to carry out the cropbox resize but unfortunately didn’t make any difference.  I must clarify though that this issue relates to elevations created using the new 2013 class.  I have created the attached graphic to illustrate some weird behaviour though:

 

As we go through the code in the graphic you will see that I set BoundingBoxXYZ bb to equal the cropbox of my testView. (1)

I then modify bb by reducing the height by 3 feet.

I then set the cropBox to equal bb, see 2 and 3 in the image.  At this point an unexpected change in the boundingBox values takes place.  You will see that even though we set the cropBox to equal bb both of the Z values seem to have reversed in the new cropBox (3).

After regenerating I checked the cropBox value again and you will see that the Y value we reduced by 3 feet has reverted to the original value but the incorrect Z values have remained.  This has the effect of the elevation looking back on itself.

 

ADN Support Specialist
Joe.Ye
Posts: 334
Registered: ‎03-05-2010
Message 4 of 10 (898 Views)

Re: Modify CropBox of Elevation View

09-12-2012 01:48 AM in reply to: grahamcook

 

The Z value of the CropBox Max and Min is not so important. In the elevation view, the Z coordinate is vertical to the elevation view. The X is horizontal to  the right, and Y is vertical up. Probably Revit change the CropBox max and min Z value automatically. This doesn't affect the appearance of the elevation view.

 

After assign the bb back to the elevation view, I cannot reproduce the issue you reported. "Y value we reduced by 3 feet has reverted to the original value "

 

I also wrote a command like yours. I cannot reproduce the Y value reduced back to the original value issue.

 

here is the code I used.

 

<code>


[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class RevitCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{

UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
Transaction trans = new Transaction(doc, "ExComm");
trans.Start();

FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfClass(typeof(ViewFamilyType));


var viewFamilyTypes = from elem in collector
let type = elem as ViewFamilyType
where type.ViewFamily == ViewFamily.Elevation
select type;

ElementId viewtypeId;
if (viewFamilyTypes.Count() > 0)
viewtypeId = viewFamilyTypes.First().Id;
else
return Result.Cancelled;

ElevationMarker marker = ElevationMarker.CreateElevationMarker(doc, viewtypeId, new XYZ(0, 10, 0), 100);

ViewSection sv = marker.CreateElevation(doc,doc.ActiveView.Id, 1);

trans.Commit();

//chang the cropbox.
Transaction trans2 = new Transaction(doc,"test2");
trans2.Start();

doc.Regenerate();

// get the bounding box of the section
BoundingBoxXYZ bb = sv.CropBox;

// by way of example reduce the section height by 3 foot
XYZ max = bb.Max;
max = new XYZ(max.X+ 3, max.Y - 3, max.Z);
bb.Max = max;

// set the new bounding box
sv.CropBox = bb;

trans2.Commit();

return Result.Succeeded ;
}
}

 

 

<code>

 


When debuging, I kept watching  the CropBox value, and the bb value. The result is attached.

Not sure what's the problem in your side.

 



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Valued Contributor
grahamcook
Posts: 52
Registered: ‎06-18-2012
Message 5 of 10 (884 Views)

Re: Modify CropBox of Elevation View

09-13-2012 02:27 AM in reply to: grahamcook

Joe

Thanks for trying to reproduce the problem.  If you add a doc.regenerate() between sv.CropBox = bb and trans2.Commit() you should see the modified X and Y values revert back.  I tested your code on the rac_basic_sample_project.rvt model and was able to reproduce the behaviour (see cropboxProblem_debug.jpg image attched).  I also attach an image cropboxProblem2.jpg that shows the effect of the max and min Z values being reversed and you will see it does infact make a significant difference to the resulting view.

I hope you are able to now reproduce the issue as i know this is fundamental in getting these things fixed.

 

Graham Cook

ADN Support Specialist
Joe.Ye
Posts: 334
Registered: ‎03-05-2010
Message 6 of 10 (864 Views)

Re: Modify CropBox of Elevation View

09-20-2012 03:21 AM in reply to: grahamcook

 

HI Graham,

 

Yes, i also reproduce the issue. If calling the regenerate() method, the cropbox value is reversed. 

This looks wield.

Then how about not calling the Regenerate() method. 

Since the transaction commit can automatically regenerate the model. 

 

 



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Valued Contributor
grahamcook
Posts: 52
Registered: ‎06-18-2012
Message 7 of 10 (861 Views)

Re: Modify CropBox of Elevation View

09-20-2012 04:29 AM in reply to: grahamcook

Hi Joe

Glad you are now able to see the same issue!

Unfortunately, as you say the commit also performs a regenerate behind the scenes and it is at this point that Revit resets any changes to the cropbox back to the original values (and reverses min and max Z).  The cropbox can be modified no problem through the user interface so it looks to be a bug with the API.

 

I have also just tested the same code you provided but changed the XYZ location of the elevation marker to 0,0,0.  This puts the marker on the outside of the building (if run on the rac_basic_sample_project file).  When the elevation is outside and not within a room then the specified X and Y changes work OK.  But the Z still gets reversed.

 

Could this be logged as a bug with the development team?

 

Regards

 

Graham

ADN Support Specialist
Joe.Ye
Posts: 334
Registered: ‎03-05-2010
Message 8 of 10 (841 Views)

Re: Modify CropBox of Elevation View

09-25-2012 09:00 AM in reply to: grahamcook

 

I See, will let the engineering team know this issue soon.



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Member
rodh257
Posts: 3
Registered: ‎11-30-2013
Message 9 of 10 (471 Views)

Re: Modify CropBox of Elevation View

12-01-2013 12:54 AM in reply to: Joe.Ye

has there been any update on this issue? 

 

The reason I ask is in a command I do this on a Section:

 

					var section = (from v in new FilteredElementCollector(uiDoc.Document).OfClass(typeof(ViewSection)).Cast<ViewSection>()
								   where v.Name == viewName
								   select v).First();

					if (section != null)
					{
						var cropbox = section.CropBox;
						section.CropBox = cropbox;
					}

 

If I run it once and set a breadkpoint on the section I get:


+ Max {(39.920867142, 6.000000000, 0.000000000)} Autodesk.Revit.DB.XYZ
+ Min {(-36.346794904, -6.000000000, -10.000000000)} Autodesk.Revit.DB.XYZ

 

If I run it again I get:

 

+ Max {(39.920867142, 6.000000000, 10.000000000)} Autodesk.Revit.DB.XYZ
+ Min {(-36.346794904, -6.000000000, 0.000000000)} Autodesk.Revit.DB.XYZ

 

If I run it a third time, it goes back to what I got the first time, and so forth. It's very puzzling, I was trying to work out how to set the depth of a section, I'm guessing this means I won't be able to do that? 

 

 

Contributor
ari.monteiro
Posts: 18
Registered: ‎03-11-2005
Message 10 of 10 (382 Views)

Re: Modify CropBox of Elevation View

02-21-2014 09:44 AM in reply to: grahamcook
Dear Joe, Recently I'm figure out the same problem when I found this post. I post my problem here and your colleague, Jeremy Tammik, tried to help me. I used the idea of one transaction for adjust the crop box, but not success. I saw in your last reply on this post that you sent the issue to analysis by engineering team. This issue persists in Revit 2014 API. Any suggestions to solve this issue? Regards, Ari Monteiro
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.