Hi,
I’m hoping someone can give me some advice on manipulating the Cropbox of a view.
In essence from the View Class the CropBox can be obtained, and then from that the BoundingBoxXYZ class can be obtained which has Min and Max properties which define the extents of the views Crop.
Min is the Upper left corner in plan (lower level)
Max is the Lower right corner in plan (Upper level).
This screen grab shows two red lines which are what I want to set the Crop to, along with the Min and Max point coordinates:
My Python code which runs in Dynamo inputs the Crop coordinates as number nodes and runs a Python script:
Note that for the code to work the Elevation View created has to be called ‘TEST’.
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from math import atan2, radians, cos, sin, degrees
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
adoc = doc.ActiveView
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
##For this routine to work you need to create 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()
wallstartx = IN[1]
wallstarty = IN[2]
wallstartz = IN[3]
wallendx = IN[4]
wallendy = IN[5]
wallendz = IN[6]
#Get the min and max values of existing view's Cropbox
exmincb = viewcropbox.Min
exmaxcb = viewcropbox.Max
newmincp = XYZ(wallstartx, wallstarty, wallstartz)
newmaxcp = XYZ(wallendx, wallendy, wallendz)
#Set the min and Max values of BoundingBox
newbox.Min = viewcropbox.Transform.Inverse.OfPoint(newmincp)
newbox.Max = viewcropbox.Transform.Inverse.OfPoint(newmaxcp)
viewtouse.CropBox = newbox
t.Commit()
#Assign your output to the OUT variable.
OUT = ["Cropbox existing:",exmincb, exmaxcb, "New Cropbox pre trans:", newmincp, newmaxcp, "New Cropbox post trans:", newbox.Min, newbox.Max]
The problem is that it doesn’t set the CropBox as expected, it reverses it flipping it the other way:
I can’t see whats going wrong, the coordinates I’m using are exactly the same when I manually move the CropBox to the position I want and report them.
Any help would be appreciated.