Delete elements from a list of IDs

Hi all,

I´m new in the forum so I’ll quickly introduce myself: my name is Francisco, I’m a spanish architect living in UK, currently working with Revit 2014 in a very big project with lots of tedious tasks, that’s why I’m interested in Dynamo and Python (I’m slowly learning, but the lack of time doesn’t help!).
For now I’m afraid that I’ll ask more than I’ll help others, but hopefully that will change soon.

I’ve just made my first Dynamo Workflow so far: just export a list of filters in the project to an Excel file, where the first column is the name of the filter and the second the ID of the filter.

The idea is to create a file with list of IDs (only the filters I want to delete in this case) and make Dynamo read that file and delete those elements. But I only managed to delete all the filters, not the ones I want, and just by selecting all elements, not by reading a list from an external file.

Any ideas on this?


There are also a lot of posts on here regarding grabbing data from excel.

Compare the 2 lists (list contains), and use filterbyboolmask (it will give the filters that don’t match you excel list.).
Maybe post what you have so far.

Thanks for the answers.

John, I’ve replicated your idea but does nothing. I’ve tried inside the Code Block “11408”; 11408; 11408…all the combinations, but didn’t delete the filter.

That’s a great idea salvatore, although I still have to reach that point. This is what I have now, just export to excel. Deleting a list of IDs from a file / copy&paste may be a different node.

@franciscusm I don’t think you need to export the element IDs, just the names would be enough.

Use your script to updated your list of filters.

Create another script and try follow my previous suggestions
1- Compare the names (strings)
2- Fitlerbyboolmask

Then what I would need is delete the elements from a list of names (or IDs would work for me also).

I managed to delete the elements from an IDs list.

What I need now is to find out how to import from file a custom list (text to list or something like that).

There are like 500 filters but I only need to keep around 10 of them, that is why I want to export and check the list in excel and then import back a modified list.

Hi again,

I managed to import the modified list from excel and to delete a list of elements by an IDs list.

But the list I managed to import seems not to be in the right format. Deleting the ‘green’ list works while the ‘red’ one doesn’t delete anything.

I think what I marked up in both lists is the clue. Now what I need is to convert the red list to the format of the green one, or even better, import directly like the green one.

@salvatoredragotta when I get it working I’d can go one step further and try your suggestion, but I think I need to this first for it to work.


Have a look below and see if it helps.

1 Like

I’ve tried what you said, and while it’s a good tip to compare lists, it didn´t delete anything, at least in this case.

In the other hand, with FLATTEN, I could make the ‘Red’ list like the ‘Green’ one, but still doesn’t delete the elements, while the ‘Green’ one does…maybe the IDs need to be a string, integer or anything…

See if some of these nodes helps:


Thanks very much, finally worked with your method! :slight_smile:

The problem was that the imported Excel list wasn’t considered as IDs by the node Element.ByID while the list generated by the node Element.ID was.

Thanks everybody for the help!

I want to share my first workflow it with you in case anybody finds it useful.
Thanks for the help (specially to @salvatoredragotta !

It allows to export the whole list of filters to excel, then you save another excel file with the filters you want to keep (or delete) and import the file to batch delete the desired filters.

I guess it should work with other categories like view templates, materials or line styles but haven’t tried yet!


Hi Francis,

Thanks for sharing your workflow. I noticed that there is null value from Read Excel node. Can you modify and drop the screenshot again. Thanks :slight_smile:

Hi @Kulkul the workflow works as it is, just needs to be run once for that null to disappear.
Anyway here’s a new pic without that null.


-Needs to be run twice. First time will generate the full list excel from the lower right FilePath node. Then we need to edit that list and save a different file with the information only in one column, and load that new file in the FilePath node un the upper left corner.
-Then the second run will delete the elements (set the boolean to true before DeleteElements node).

-The excel sheet name in the STRING node is “Filtros” by default. Ideally it would automatically pick the name from Element Types node in the lower left corner, removing the prefix Autodesk.Revit.DB., convert to string, etc. But I don’t know how to do that.


Thanks for the explanation :wink:

You’re welcome.

An update, I’ve found in the forum a way to directly import IDs to elements from Excel. It was not working before because the format must be System.Int32. Changing to string and back to number seems to do the trick.

I remember getting this script working in Dynamo 0.9.1 (and it still does), but how come it does not work in versione 1.2?

Oh, that’s annoyingly common when updating Dynamo…

try python code:

import clr
from Autodesk.DesignScript.Geometry import *

import Revit

import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

from System.Collections.Generic import *

import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument

ids = IN[0]
elements = []

for i in ids:
	temp = int(i)	
	elemID = Autodesk.Revit.DB.ElementId(temp)

OUT = elements