Delete all Fill Pattern Elements

Hi!

I am having trouble deleting all Fill Pattern Elements from a family document. I am creating scripts to remove elements from our office family templates, and have an issue when it comes to deleting all fill patterns.

I am fairly new to python and I might have made a mistake in the code or it might be trying to delete the internal solid fill pattern? In RevitPythonShell its saying that ElementId cannot be deleted so maybe I need to filter the Solid Fill pattern out?

If someone could point me in the right direction it would be much appreciated :slight_smile:

# Delete all fill patterns
fill_pats = FilteredElementCollector(doc).OfClass(FillPatternElement).WhereElementIsNotElementType().ToElements()

t = Transaction(doc)
t.Start("Delete Fill Patterns")

for fill in fill_pats:
        doc.Delete(fill.Id)

t.Commit()

Hi @AltControlIT
You are right, you cannot delete all of them, Revit needs a few of these to be functional.
a Try Except will probably do the trick:

# Delete all fill patterns
fill_pats = FilteredElementCollector(doc).OfClass(FillPatternElement).WhereElementIsNotElementType().ToElements()

t = Transaction(doc)
t.Start("Delete Fill Patterns")

for fill in fill_pats:
    try:
        doc.Delete(fill.Id)
    except Exception as e:
        print('Cannot delete {}: {}'.format(fill.Name, e)
t.Commit()

Thanks Jean-Marc that worked perfectly! :raised_hands:

1 Like