Python | TypeError: iteration over non-sequence of type ViewSection

Hello,

I got the code below from the following link:
https://www.linkedin.com/pulse/methods-fitting-crop-region-elements-revit-using-dynamo-ashwin-kumar-

# Load the Python Standard and DesignScript Libraries
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

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

and its producing the following error:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 19, in
TypeError: iteration over non-sequence of type ViewSection

I’m using Revit 2020

I’d be most appreciative if you could assist as to why it is producing an error.

hi,
this may happend because you have instance view not a list of view, make this instance as a list
try to use List.Create then Flatten before you input the result to Python node

I actually saw that solution when Googling my error but didn’t think it applied to my solution. Gave it a shot and it seems to have worked!

Thanks a lot @khuzaimah.ElecEng!