How to Reset Crop view using Dynamo

How do i “Reset Crop Region” using Dynamo?
Crop Resize.dyn (28.8 KB)

@ashwinash112

1 Like


i mean this option here,

What yo ushowed me turns crop view on/off which i also needed.

You need to get a hold of this method from the API:

http://www.revitapidocs.com/2018.1/23549769-0715-f39b-7083-86f1902bd8a8.htm

I don’t know if there’s any nodes currently that handles this, but you can use this code:

#Import the Revit API
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

#Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

#Reference the active Document and application
doc = DocumentManager.Instance.CurrentDBDocument

view = UnwrapElement(IN[0])

csm = view.GetCropRegionShapeManager()

#Transaction start:
TransactionManager.Instance.EnsureInTransaction(doc)

csm.RemoveCropRegionShape()

TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable.
OUT = 0

This will handle the active view. It needs to be set up in a loop if you have a list of views :slight_smile:

Hope it helps.

1 Like

Oh well, I was almost there:

For a list of views:

#Import the Revit API
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

#Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

#Reference the active Document and application
doc = DocumentManager.Instance.CurrentDBDocument

view = UnwrapElement(IN[0])
TransactionManager.Instance.EnsureInTransaction(doc)

for v in view:
	if v.CropBoxActive == True:
		csm = v.GetCropRegionShapeManager()
		csm.RemoveCropRegionShape()

TransactionManager.Instance.TransactionTaskDone()

OUT = 0
3 Likes

One tiny addition to help!

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

#Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

#Reference the active Document and application
doc = DocumentManager.Instance.CurrentDBDocument

view = UnwrapElement(IN[0])

# If the Input List doesn't have the attribute of '__iter__' (Which means iterable 
# - i.e it's an object that contains objects such as a 'List') then we want to 
# wrap that singular item (In our case a view) into a List of one thing. 
# This way our For Loop will never fail :) 

if not hasattr(view, '__iter__'):
    view = [view]

TransactionManager.Instance.EnsureInTransaction(doc)

for v in view:
    if v.CropBoxActive == True:
        csm = v.GetCropRegionShapeManager()
        csm.RemoveCropRegionShape()

TransactionManager.Instance.TransactionTaskDone()

OUT = 0
3 Likes

Yeah i should have included that check, Sol. Cheers :+1::grinning:

1 Like

I closed and opened Dynamo , Now it Works …THNX

The solution should actually be Sol’s post, since the part he added will ensure the script works with both lists and singletons :slight_smile:

I tried Both ,but it would only accept one…

Now i need to Expand my crop Box .on only one Side…Il Start a new Thread.

Something went wrong in @solamour’s formatting. There’s a flaw in the if-sentence indentation:

i corrected it here:

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

#Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

#Reference the active Document and application
doc = DocumentManager.Instance.CurrentDBDocument

view = UnwrapElement(IN[0])

# If the Input List doesn't have the attribute of '__iter__' (Which means iterable 
# - i.e it's an object that contains objects such as a 'List') then we want to 
# wrap that singular item (In our case a view) into a List of one thing. 
# This way our For Loop will never fail :)

if not hasattr(view, '__iter__'):
	view = [view]

TransactionManager.Instance.EnsureInTransaction(doc)

for v in view:
	if v.CropBoxActive == True:
		csm = v.GetCropRegionShapeManager()
		csm.RemoveCropRegionShape()

TransactionManager.Instance.TransactionTaskDone()

OUT = 0

This ran without errors with a list of views.

What a messy thread. Sorry :smiley:

7 Likes

Ah yeah I’m just a muppet… my bad for manually typing in the 4x spaces to ‘indent’ :frowning:

@MartinSpence @solamour

I have used this Python in the past, but it doesn’t work for Revit 2021.
I don’t know if i only ever used it in older Revit versions.
What do i have to do to make it work in Revit 2021?

I also tried the node from Genius.Loci @Alban_de_Chasteigner but that also
didn’t work. Only works if the Crop wasn’t rectangular in the first place and only for a single View.
I have 358 Views which need a Reset Crop.

image

Hi @bvs1982 - Looks like the hasattr (Has attribute) call is not implemented in CPython3, which I assume you are using :slight_smile: Simply change it to the following isinstance approach and it should work.

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

#Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

#Reference the active Document and application
doc = DocumentManager.Instance.CurrentDBDocument

view = UnwrapElement(IN[0])

# If the Input List doesn't have the attribute of '__iter__' (Which means iterable 
# - i.e it's an object that contains objects such as a 'List') then we want to 
# wrap that singular item (In our case a view) into a List of one thing. 
# This way our For Loop will never fail :)

if not isinstance(view, list):
	view = [view]

TransactionManager.Instance.EnsureInTransaction(doc)

for v in view:
	if v.CropBoxActive == True:
		csm = v.GetCropRegionShapeManager()
		csm.RemoveCropRegionShape()

TransactionManager.Instance.TransactionTaskDone()

OUT = view
1 Like

@solamour

Thanks for your reply. I have no need for this anymore as i worked around it.
I tested your solution though for people who might run into the same issue.
It didn’t work.

image

The error message you have is stating that you have an additional level depth in your inputs. In Python you have to stipulate how to deal with levels, while Dynamo automagically does that for you, or provides Lacing and List@Level to dictate it :blush:

I will look at (read; test) it again, but i am pretty sure i had NO level depths in my input.