Removing linked/imported CAD-Files

AngelM_
Explorer
Explorer

Removing linked/imported CAD-Files

AngelM_
Explorer
Explorer

Hello,

 

I have a problem with my code(python) that needs to filter and delete all linked or imported CAD-Files in my project.
This is how I started, the deletion of the linked Revit & IFC-files is working smoothly. Only the CAD are causing trouble and dont seem to work the same way.

This is how this part of my code looks like right now:

 

# Helper function to delete all linked file types (Revit, IFC, CAD)
def delete_all_linked_file_types(doc):
# Collect all link types first
revit_link_types = FilteredElementCollector(doc).OfClass(RevitLinkType).ToElements()
ifc_link_types = FilteredElementCollector(doc).OfClass(ImportInstance).ToElements()
cad_link_types = FilteredElementCollector(doc).OfClass(CADLinkType).WhereElementIsElementType().ToElements()
# Delete Revit link types
for link_type in revit_link_types:
doc.Delete(link_type.Id)

# Delete IFC link types
for link_type in ifc_link_types:
if link_type.Name and 'IFC' in link_type.Name:
doc.Delete(link_type.Id)

# Delete CAD link types
for cad_link_type in cad_link_types:
doc.Delete(cad_link_type.Id)

0 Likes
Reply
196 Views
1 Reply
Reply (1)

jeremy_tammik
Autodesk
Autodesk

Interesting to note that the CAD link types cause problems, and are also the only ones where you are adding the additional WhereElementIsElementType filter. Why are you adding that? Why are your filtered element collectors different for CAD types than for the other two? 

  

By the way, you can probably eliminate the calls to ToElements, because the filtered element collector itself is alreay iterable.

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes