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();
}
}


