"A managed exception was thrown by Revit or by one of its external applications." message when editing family parameters via Python

So my goal is to uncheck the “Show pre-cut family in plan views” box in Family Parameters for all Structural Columns automatically.

So far, I could not do it with Dynamo since it is kind an unusual parameter. Here is what I managed to get with Python

And here is the message I see every time running the script. It seems like it works with few columns and then stops at that exception
“Exception : Autodesk.Revit.Exceptions.InternalException: A managed exception was thrown by Revit or by one of its external applications.
в Autodesk.Revit.DB.FilteredElementIterator.MoveNext()”
What might be the problem?

You’re iterating through the families in the project and at the same time making changes to those families. That invalidates the information in the iterator and breaks things down…

Thank you for clarification! I solved the problem by adding fec=list(fec)

Denis,

could you please post the final solution. I am currently trying to do the same thing. I am not sure where it goes in the script.

I was trying to solve this solution via Dynamo nodes without python but am getting errors with the Orchid Package @erfajo

thanks.

Hi!

Below is the full code. I run it in Python Shell ( https://github.com/architecture-building-systems/revitpythonshell](https://protect-eu.mimecast.com/s/F2hYCwpE8UR3gqIqPTYV?domain=github.com ), because Dynamo was not able to change Revit Families

import clr

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

clr.AddReference(‘RevitAPIUI’)
from Autodesk.Revit.UI import *

app = revit.Application
uidoc = revit.ActiveUIDocument
doc = revit.ActiveUIDocument.Document

class FamilyOption(IFamilyLoadOptions):
def OnFamilyFound(self,familyInUse,overwriteParameterValues):
return True

def OnSharedFamilyFound(self, sharedFamily, familyInUse, FamilySource, overwriteParameterValues):
return True

#Preparing input from dynamo to revit
fec = FilteredElementCollector(doc).OfClass(Family)
fec = list(fec)
for f1 in fec:
if f1.FamilyCategory.Name == ‘Structural Columns’:
print f1.Name
f = f1
o = 0

famdoc = doc.EditFamily(f)

thisFamily = famdoc.OwnerFamily
parPrecut = thisFamily.get_Parameter(BuiltInParameter.FAMILY_USE_PRECUT_SHAPE)

t = Transaction(famdoc)
t.Start(“Edit o”)
parPrecut.Set(o)
t.Commit()

print famdoc.LoadFamily(doc, FamilyOption())

print famdoc.Close(False)

1 Like