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

Hi All,

Apologies for reviving this old thread but this seemed a bit better than starting a new one.
I am also trying to rotate crop frames in views using Dynamo to deal with orientation of several views on sheets.

I simplified the routine I was working on to only include the most problematic part. I am working in Revit 2024, so please let me know if this is not achievable in this version any more.

I followed the findings of @Konrad_K_Sobon , JeremyTammik, @Mark.Ackerley and others.
I can see that the code is able to retrieve the cropframe from the view (also tried this with the “GetCropRegionElement” node from Rythm package) but for some reason the rotation does not happen.

I am using a version of the code posted on the forum by @Mark.Ackerley:

#all thanks to Konrad @ Archi-lab, Jeremy Tammik and pretty much everyone else on the forum! No credit goes to me for this.

import clr

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

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

rot = IN[0]
viewport = UnwrapElement(IN[1])

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
	
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)
    TransactionManager.Instance.TransactionTaskDone()
    
   return view

crpbx = GetViewCropBoxElement(viewport)
crpbxRt = RotateCropBox(viewport, crpbx, rot)

OUT = crpbx, crpbxRt

here is the error/warning message I am receiving:

*apologies if the code above is formatted weirdly - I am not sure how to correctly include it in my post

to add to the above - I also tried formatting the inputs as lists using “listcreate” nodes.

I am not an expert in python and am using Copilot/ Claude AI as a crutch where I can and these have been very helpful with all the other dynamo tasks I did apart from this one - I tested many AI permutations of this code - all of them not working.

the posts by @Konrad_K_Sobon introducing the initial methodology were from 2016, so would be great if anyone could let me know if this is achievable at all with the current 2024 ver of Revit/Dynamo.

image

From Orchid (GitHub).

Hi @bvs1982, thank you for this, I wasn’t aware that such a package existed, could you, or anyone really let me know if you spot anything wrong with the below set up?:

I still cannot get this to work.
The routine runs, does not return any errors, but the crop region does not budge by even a single degree. On the view above - the point int he middle of the frame is the selected rotation point.

Just to be sure. There is no Scope Box active?

I understand that I both have a cropbox visible and active:
image

I meant

But after some digging it looks like it only works if your rotate it around x and y are 0

I just noticed that when the value typed in is low enough I can see a small skew in the crop box.
I’m not sure why this might be but I get no results for angular values from 20deg and up.
Another thing is I was aiming to change the rotation of the contents of my view by rotating the crop frame, as I would manually:
so, from this state:


to this:

ah, no scope box is off in this view. it was the crop frame/region/box of the view that I intended to rotate (I am confused when it comes to the correct naming at this point hah)

Hi @Mateusz.Madej could something here work…if i understand right :wink:

Revit_5I322soDQj

Yer. Forgot that also works.

AND for the Python (i used that one in the past too) i forgot it wants Lists

@sovitek YES! this is it! thank you, this works perfectly.
@bvs1982 Thank you for the help as well, will make sure to try out both the methods.

1 Like

if will reset your rotation you could try this one here