Rotate View cropbox

Hi all

Can anyone help me here please.

trying to rotate cropbox in plan view got python together but looks like cant rotate to given angle can any one look at it please???

All i want is to rotate 90deg but when i do that it rotates to strange angle.

Regards

ROTATED CROP.dyn (5.6 KB)

@dkeinys Try converting degrees to radians

image

2 Likes

Thanks you saved my day

regards

1 Like

Hello,
On a single view it’s working great.
When I try to apply this script on multiple views I get this error:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 74, in
File “”, line 51, in GetViewCropBoxElement
AttributeError: ‘List[object]’ object has no attribute ‘CropBoxVisible’

While the crop regions are visible in all views.
Any idea ?

Best regards, Fred

import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

Import DocumentManager and TransactionManager

clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

Import RevitAPI

clr.AddReference(“RevitAPI”)
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

from System.Collections.Generic import *

Import ToDSType(bool) extension method

clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)

################### Definitions ###################
def RotateCropBox(view, cropBox, angle):
doc = DocumentManager.Instance.CurrentDBDocument
bbox = view.CropBox
center = 0.5 * (bbox.Max + bbox.Min)
axis = Line.CreateBound(center, center + XYZ.BasisZ)
TransactionManager.Instance.EnsureInTransaction(doc)
ElementTransformUtils.RotateElement(doc, cropBox.Id, axis, angle*0.0174533)
TransactionManager.Instance.TransactionTaskDone()
return view

def GetViewCropBoxElement(view):
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.ForceCloseTransaction()
tGroup = TransactionGroup(doc, “Temp to find crop box element”)
tGroup.Start()
trans1 = Transaction(doc, “Temp to find crop box element”)
trans1.Start()
view.CropBoxVisible = False
trans1.Commit()

shownElems = FilteredElementCollector(doc, view.Id).ToElementIds()

trans1.Start()
view.CropBoxVisible = True
trans1.Commit()

cropBoxElement = FilteredElementCollector(doc, view.Id).Excluding(shownElems).FirstElement()
tGroup.RollBack()
return cropBoxElement

doc = DocumentManager.Instance.CurrentDBDocument
################### Inputs ###################
#get the bool in port IN[0]…
views = (UnwrapElement(IN[0]))
angle = (UnwrapElement(IN[1]))

center =

RotateCropBox(views, GetViewCropBoxElement(views), angle)

OUT = RotateCropBox

This error means that the function expects an instance of something, while a list was fed instead. This means that the python script is made for single instance not a list. So you can put the python script in a custom node and make it work on list of items that way or you can rewrite the script so that the script works directly from the graph with multiple items.

Thanks Alexander, I will see if I can make it work.

Any succes yet? I also want to rotate my Crop Box using Dynamo.

Note; i have no experience with Python.

EDIT
The Python in this post worked for me. I think it is also what you are looking for.
https://forum.dynamobim.com/t/rotate-crop-box-of-multiple-views/38815/5

EDIT2
Only the rotation is ‘wrong’… If i say ‘30’ it does not rotate 30 degrees.

EDIT3
Solved! I totally missed