Delete Imported DWGs and Other CAD files

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

3 thoughts on “Delete Imported DWGs and Other CAD files

  1. Hi. This won’t work in REVIT 2014. Can you possibly update the code. My skills aren’s sufficient I’m afraid.
    Thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s