Get Crop views

Hi everyone,

I’m trying to get a crop box on a view, to select it in dynamo. I already try to use the code from Konrad K Sobon, but well… here is the message I had :
image

and here is the code :
import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

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

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

view = IN[0]

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()

#Affectez la sortie à la variable OUT.
OUT = 0

Do you have any ideas? what is wrong?

Hi @mickael.g,

Change “view = IN[0]” with view = UnwrapElement(IN[0])

#From Konrad Sobon
import clr
clr.AddReference("ProtoGeometry")
from Autodesk.DesignScript.Geometry import *

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

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

view = UnwrapElement(IN[0])

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()

#Affectez la sortie à la variable OUT.
OUT = cropBoxElement

Hi,

thanks for your answer… I found a way to do this with existing node ^^ but I might need you help on another subject