Set Elevation View extents

Hi,

I’ve put together a Python routine which generates elevations for rooms - and it all works quite well apart from the elevation view extents:

As you can see, I need to reset the elevation view extents as the don’t match the wall its facing.

I originally assumed this is a parameter, but I can’t find any parameter which governs this and so am now thinking its to do with the views cropbox.

Looking at the ViewSection class, I can see there is a property called BoundingBox, but I can’t see a method to set the BoundingBox.

Or maybe I’m going down the wrong route?

Am I correct in thinging its the BoundingBox which sets the extents?

Thanks.

Could you consider generating the views in Dynamo?

Well I’m trying to write the whole thing in Python.

All of the code so far is in Python and I’m keen to getting he rest of it that way too, partly to learn Python and also partly to learn the API.

OK, this is what I’ve tried:

The elevation is called ‘TEST’, I’ve selected it using an FilteredElementCollector to ensure that I’m actually selecting it (didn’t want that bit of code letting me down).

This code fails with IronPython.Runtime.Types.ReflectedIndexer

But if I look for, say Category instead of BoundingBox it will work and return a category.

I’m unsure why BoundingBox fails and other properties such as Category work…

1 Like

Well I’ve managed to obtain the Cropbox values from the view (was confused with BoundingBox) - but I can’t seem to set the CropBox to a new value…

The code below looks for a view called ‘TEST’, it then uses .CropBox to get the Cropbox of the view, this returns the BoundingBoxXYZ class, which has two Properties Min and Max that define the left and right hand extends of the view (i.e. the line which the user can drag about).

This all works, but I cannot seem to set the minimum and max values, only obtain them.

The code below attempts to set the Min value to 10,10,10 - it executes with no error, but nothing happens and Revit does not show that anything has changed.

Maybe there is something wrong with my transaction?

Indeed, there is. Have a look here: https://github.com/DynamoDS/Dynamo/wiki/Python-0.6.3-to-0.7.x-Migration#transactions

mmm - No joy!

I changed the code to:

Same thing happens, the code executes with no error, but Revit does show that anything has happened / changed.

Even the Undo button does not show any changes listed to undo…

Have a look at Clockwork’s View.ResizeCropbox node. I used a slightly different approach (i.e. create a new cropbox and then assign that to the view) which should work.

2 Likes

Excellent - that works. I wonder why my original code didn’t work!

Thanks for your help.

@Kevin_Bell - Glad it helped. It would be great if you could share your code with the community and mark this thread as solved.

OK, to work this out I opened Clockwork’s View.ResizeCropBox node and took a look at how they set up the CropBox.

Rather than adjusting the existing Cropbox, I simply created a new one and applied it to the view:

#Get all views and find the one called 'TEST'
allViews = FilteredElementCollector(doc).OfClass(View).ToElements()

viewtopick = "TEST"

for f in allViews:
  if f.Name == "TEST":
    viewtouse = f

#Change the Min value of the crop box of view 'TEST'
t = Transaction(doc, "Update cropbox")
t.Start()

#Get View cropbox
viewcropbox = viewtouse.CropBox

#Create a new Bounding Box
newbox = BoundingBoxXYZ()

wallstartx = IN[1]
wallstarty = IN[2]
wallstartz = IN[3]

wallendx = IN[4]
wallendy = IN[5]
wallendz = IN[6]

#Set the min and Max values of the new BoundingBox
newbox.Min = XYZ(wallstartx, wallstarty, wallstartz)
newbox.Max = XYZ(wallendx, wallendy, wallendz)

#Apply the new BoundingBox as the Cropbox for the view
viewtouse.CropBox = newbox


t.Commit()

Note what the wallstartx - y and z and wallendx - y and z variables calculated from dynamo notes and are essentially numbers.

2 Likes