# How to Reset Crop view using Dynamo

**URL:** <https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140>\
**Category:** Revit\
**Created:** [August 23, 2018, 9:25am UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140 "2018-08-23T09:25:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashwinash112](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@ashwinash112](https://forum.dynamobim.com/u/ashwinash112)\
**Post date:** [August 23, 2018, 9:25am UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140/1 "2018-08-23T09:25:34Z")

</div>

How do i “Reset Crop Region” using Dynamo?  
[Crop Resize.dyn](https://forum.dynamobim.com/uploads/short-url/xqzapc9xjLK5VImeB5BBnaHC8V0.dyn) (28.8 KB)

---

<div class="post-metadata">

**Author:** ![m.rijsmus](https://avatars.discourse-cdn.com/v4/letter/m/6f9a4e/32.png) [@m.rijsmus](https://forum.dynamobim.com/u/m.rijsmus)\
**Post date:** [August 23, 2018, 9:28am UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140/2 "2018-08-23T09:28:28Z")

</div>

@ashwinash112

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/8/c8ec6306a716e03cae0256adc764e25d668f27e3.png)

---

<div class="post-metadata">

**Author:** ![ashwinash112](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@ashwinash112](https://forum.dynamobim.com/u/ashwinash112)\
**Post date:** [August 24, 2018, 7:26am UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140/3 "2018-08-24T07:26:55Z")

</div>

![Crop](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/1/612023049e2826181f1036491bdb03ed3d7b7161.png)  
i mean this option here,

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

---

<div class="post-metadata">

**Author:** ![MartinSpence](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/martinspence/32/25208_2.png) [@MartinSpence](https://forum.dynamobim.com/u/MartinSpence)\
**Post date:** [August 24, 2018, 11:00am UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140/4 "2018-08-24T11:00:10Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/a/4ab41f8670025593ea749f3cb4fd6d95caa5e8a6.png)

[http://www.revitapidocs.com/2018.1/23549769-0715-f39b-7083-86f1902bd8a8.htm](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

```

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/8/48a3dfea58c484e21ef36acf81cd98d4fdb31642.png)

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

Hope it helps.

---

<div class="post-metadata">

**Author:** ![MartinSpence](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/martinspence/32/25208_2.png) [@MartinSpence](https://forum.dynamobim.com/u/MartinSpence)\
**Post date:** [August 24, 2018, 11:09am UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140/5 "2018-08-24T11:09:30Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![solamour](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/solamour/32/153516_2.png) [@solamour](https://forum.dynamobim.com/u/solamour)\
**Post date:** [August 24, 2018, 11:23am UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140/6 "2018-08-24T11:23:26Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![MartinSpence](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/martinspence/32/25208_2.png) [@MartinSpence](https://forum.dynamobim.com/u/MartinSpence)\
**Post date:** [August 24, 2018, 11:26am UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140/7 "2018-08-24T11:26:54Z")

</div>

Yeah i should have included that check, Sol. Cheers 👍😀

---

<div class="post-metadata">

**Author:** ![ashwinash112](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@ashwinash112](https://forum.dynamobim.com/u/ashwinash112)\
**Post date:** [August 24, 2018, 11:34am UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140/8 "2018-08-24T11:34:05Z")

</div>

> [@MartinSpence](#):
>
> #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

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/5/f50dcaec6a21a7677b22254eb6c535afa8fdbd14.png)

---

<div class="post-metadata">

**Author:** ![ashwinash112](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@ashwinash112](https://forum.dynamobim.com/u/ashwinash112)\
**Post date:** [August 24, 2018, 11:39am UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140/9 "2018-08-24T11:39:08Z")

</div>

> [@MartinSpence](#):
>
> #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

I closed and opened Dynamo , Now it Works …THNX

---

<div class="post-metadata">

**Author:** ![MartinSpence](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/martinspence/32/25208_2.png) [@MartinSpence](https://forum.dynamobim.com/u/MartinSpence)\
**Post date:** [August 24, 2018, 11:41am UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140/10 "2018-08-24T11:41:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ashwinash112](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@ashwinash112](https://forum.dynamobim.com/u/ashwinash112)\
**Post date:** [August 24, 2018, 11:43am UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140/11 "2018-08-24T11:43:07Z")

</div>

I tried Both ,but it would only accept one…

---

<div class="post-metadata">

**Author:** ![ashwinash112](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@ashwinash112](https://forum.dynamobim.com/u/ashwinash112)\
**Post date:** [August 24, 2018, 11:49am UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140/12 "2018-08-24T11:49:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ashwinash112](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@ashwinash112](https://forum.dynamobim.com/u/ashwinash112)\
**Post date:** [August 24, 2018, 11:52am UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140/13 "2018-08-24T11:52:24Z")

</div>

> [@How do i Resize a Crop Box](https://forum.dynamobim.com/t/how-do-i-resize-a-crop-box/25177):
>
> [3] Im using This curenlty,But its not reliable,sometimes it works,sometimes it doesnt.

---

<div class="post-metadata">

**Author:** ![MartinSpence](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/martinspence/32/25208_2.png) [@MartinSpence](https://forum.dynamobim.com/u/MartinSpence)\
**Post date:** [August 24, 2018, 11:52am UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140/14 "2018-08-24T11:52:51Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/f/af28099598ed77c6cc3ffad8d4a8fa2659796ab5.png)

What a messy thread. Sorry 😃

---

<div class="post-metadata">

**Author:** ![solamour](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/solamour/32/153516_2.png) [@solamour](https://forum.dynamobim.com/u/solamour)\
**Post date:** [August 24, 2018, 12:49pm UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140/15 "2018-08-24T12:49:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bvs1982](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bvs1982](https://forum.dynamobim.com/u/bvs1982)\
**Post date:** [March 27, 2023, 2:11pm UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140/16 "2023-03-27T14:11:49Z")

</div>

@MartinSpence @solamour

I have used this Python in the past, but it doesn’t work for Revit 20 **21**.  
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 20 **21**?

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/3/f38656933acb8f19cd08a92ffde5d5b589ab4581.png)

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](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/9/894e6b80eee3fcdeba1d90367e736cf63ce47668.png)

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/d/fd5eeea9cebb5eff041e9da5cbe3d58f235cb456.png)

---

<div class="post-metadata">

**Author:** ![solamour](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/solamour/32/153516_2.png) [@solamour](https://forum.dynamobim.com/u/solamour)\
**Post date:** [March 27, 2023, 3:49pm UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140/17 "2023-03-27T15:49:39Z")

</div>

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

```auto
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
```

---

<div class="post-metadata">

**Author:** ![bvs1982](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bvs1982](https://forum.dynamobim.com/u/bvs1982)\
**Post date:** [March 28, 2023, 12:50pm UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140/18 "2023-03-28T12:50:53Z")

</div>

@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](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/0/40cc6ccce9fe6066a577c1fa0716604ed136c8a2.png)

---

<div class="post-metadata">

**Author:** ![solamour](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/solamour/32/153516_2.png) [@solamour](https://forum.dynamobim.com/u/solamour)\
**Post date:** [March 28, 2023, 1:29pm UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140/19 "2023-03-28T13:29:32Z")

</div>

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 😊

---

<div class="post-metadata">

**Author:** ![bvs1982](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bvs1982](https://forum.dynamobim.com/u/bvs1982)\
**Post date:** [March 28, 2023, 1:31pm UTC](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140/20 "2023-03-28T13:31:20Z")

</div>

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

[Next page](https://forum.dynamobim.com/t/how-to-reset-crop-view-using-dynamo/25140.md?page=2)
