Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Removing linked/imported CAD-Files

1 REPLY 1
Reply
Message 1 of 2
AngelM_
147 Views, 1 Reply

Removing linked/imported CAD-Files

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)

1 REPLY 1
Message 2 of 2
jeremy_tammik
in reply to: AngelM_

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community