In yesterday’s post we learned that imports belong to the ImportInstance Class and that the ImportInstance.IsLinked property is true if the element is linked and false if it is imported.
With this knowledge, we just need a FilteredElementCollector, a bit of LINQ, a transaction, and Document.Delete to get the imports (but not the links) out of the model.
public void deleteImportsNotLinks()
{
Document doc = this.ActiveUIDocument.Document;
using (Transaction t = new Transaction(doc,"Delete Imports"))
{
t.Start();
foreach (ImportInstance ii in new FilteredElementCollector(doc).OfClass(typeof(ImportInstance)).Cast<ImportInstance>().Where(i => i.IsLinked == false))
{
doc.Delete(ii);
}
t.Commit();
}
}
Hi. This won’t work in REVIT 2014. Can you possibly update the code. My skills aren’s sufficient I’m afraid.
Thank you!
Hi Kyrre,
I’ve updated the code in a new post at https://boostyourbim.wordpress.com/2013/09/11/looped-deletion-of-elements-in-2014/
Also, if you’d like to improve your API skills please check out my new course at https://www.udemy.com/revitapi/
Harry
Very nice of you, thank you!