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