hello, I would like to toggle the visibility of my crop regions in all my views to be on, but I cannot find any nodes for that. Also, I would like to reset the ones that are not rectangular if possible. But I cant find anything on the topic to do it in mass. Can anyone help? Thanks!
Hi @mix ,
it’s easily accessible as a parameter of the views. It can bet set with the setparameterbyname node :
you just need to translate the name of the parameter in your language.
There are also ways to get and set the shape of tha crop region through the visibilitycropregionshapemanager … but do you just want to reset it to a rectangle that includes all the project ?
Here’s an example of how to access the shape of the crop region and “reset” it :
This code get the number of perimeter curves of the crop region and resets it if it has more than 4 curves… It can be pushed farther but you get the general idea :
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import*
clr.AddReference('RevitServices')
from System.Collections.Generic import*
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
if isinstance(IN[0],list):
viewset = [UnwrapElement(i) for i in IN[0]]
else:
viewset = [UnwrapElement(IN[0])]
crsm = [v.GetCropRegionShapeManager() for v in viewset]
shapes = []
TransactionManager.Instance.EnsureInTransaction(doc)
for c in crsm :
shape = c.GetCropRegionShape()
a = List[Line](shape)
if len(a) != 4 :
c.RemoveCropRegionShape()
shapes.append(shape)
TransactionManager.Instance.TransactionTaskDone()
OUT = '%d crop regions altered' % (len(shapes))
Thats great! Is there anyway to reset the crop region if it still has four sides, just that they are modified or not rectangular? I got this error message:
Hello?
The following code will reset all non rectangular crop regions
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import*
clr.AddReference('RevitServices')
from System.Collections.Generic import*
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
if isinstance(IN[0],list):
viewset = [UnwrapElement(i) for i in IN[0]]
else:
viewset = [UnwrapElement(IN[0])]
crsm = [v.GetCropRegionShapeManager() for v in viewset]
shapes = []
vects = []
TransactionManager.Instance.EnsureInTransaction(doc)
for c in crsm :
shape = c.GetCropRegionShape()
a = List[Line](shape)
if len(a) != 4 :
shapes.append(shape)
c.RemoveCropRegionShape()
else :
vect = [l.ComputeDerivatives(0,True).BasisX for l in a]
if vect[0].DotProduct(vect[1]) == 0 and vect[1].DotProduct(vect[2]) == 0 and vect[2].DotProduct(vect[3]) == 0:
continue
else :
c.RemoveCropRegionShape()
shapes.append(a)
TransactionManager.Instance.TransactionTaskDone()
OUT = '%s crop regions altered' % (len(shapes))
Hey @Mostafa_El_Ayoubi good to see you here my friend! I’d just like to note, I think the method .GetCropRegionShape() has been depreciated or at least for more recent versions of the API it has worked as .GetCropShape() instead.
updated code to work in 2019, v2.03
two small changes
.getShapeCrop as above and [line] changed to [curveloop]
thanks guys for the hard work in the original code, im just a code tweaking amateur
import clr
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import*
clr.AddReference(‘RevitServices’)
from System.Collections.Generic import*
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
if isinstance(IN[0],list):
viewset = [UnwrapElement(i) for i in IN[0]]
else:
viewset = [UnwrapElement(IN[0])]
crsm = [v.GetCropRegionShapeManager() for v in viewset]
shapes =
vects =
TransactionManager.Instance.EnsureInTransaction(doc)
for c in crsm :
shape = c.GetCropShape()
a = ListCurveLoop
if len(a) != 4 :
shapes.append(shape)
c.RemoveCropRegionShape()
else :
vect = [l.ComputeDerivatives(0,True).BasisX for l in a]
if vect[0].DotProduct(vect[1]) == 0 and vect[1].DotProduct(vect[2]) == 0 and vect[2].DotProduct(vect[3]) == 0:
continue
else :
c.RemoveCropRegionShape()
shapes.append(a)
TransactionManager.Instance.TransactionTaskDone()
OUT = ‘%s crop regions altered’ % (len(shapes))