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:

6 Likes

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