Try not to break loop

Hi, i’m trying to modify a python loop for it to be redundant in case any of it steps fail. Here below is SetCropboxCurve from MEPover package. I’m working on a fairly messy model, where these cropbox curves aren’t pretty and they tend to produce some results, up to a first instance of messy or not closed curve causing it to stop working.

I am looking for advice on how to add a try/except/else in this bit of code to make it work even if there are loops that return errors. Thanks!

listout = []
for view,curve in zip(views,curves):
	regionMan = view.GetCropRegionShapeManager()
	revit_curve = [c.ToRevitType() for c in curve]
	curveloop = Autodesk.Revit.DB.CurveLoop()
	for c in revit_curve:
		curveloop.Append(c)
	TransactionManager.Instance.EnsureInTransaction(doc)
	if view.CropBoxActive == False:
		view.CropBoxActive = True
		view.CropBoxVisible = True
	regionMan.SetCropShape(curveloop)
	TransactionManager.Instance.TransactionTaskDone()
	listout.append(view)


#Assign your output to the OUT variable.
OUT = listout
for item in list:
    try:
        regionMan = view.GetCropRegionShapeManager()
	revit_curve = [c.ToRevitType() for c in curve]
	curveloop = Autodesk.Revit.DB.CurveLoop()
	for c in revit_curve:
		curveloop.Append(c)
	TransactionManager.Instance.EnsureInTransaction(doc)
	if view.CropBoxActive == False:
		view.CropBoxActive = True
		view.CropBoxVisible = True
	regionMan.SetCropShape(curveloop)
	TransactionManager.Instance.TransactionTaskDone()
	listout.append(view)
    except:
        listout.append(None)
        continue
1 Like

thanks!

I was trying similar way to what you’ve shown, but I was missing ‘continue’ command - did not find it in python website I was learning from. I was just using ‘pass’

1 Like