OK, something is definitely going wrong here.
I modified to code to simply obtain the Cropbox Min and Max values of the existing view, and then create a new Cropbox with the existing Min and Max values and assign it back to the same view.
In other words - I'm setting the view with the same settings and so nothing should change.
#For this to work you need an Elevation View called 'TEST; #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() #Get the min and max values of existing view's Cropbox exmincb = viewcropbox.Min exmaxcb = viewcropbox.Max #Set the min and Max values of BoundingBox to the same as the old values newbox.Min = exmincb newbox.Max = exmaxcb viewtouse.CropBox = newbox t.Commit() #Assign your output to the OUT variable. OUT = ["Cropbox existing:",exmincb, exmaxcb, newbox]
But it does!
If I run the code, the view box flips, when I run it again it flips back again:
Original:
Run once:
Run again:
I don't understand why this is happening, Perhaps its a bug? I don't see why setting the View crop with the same settings as its currently using is changing anything??