Andreas,
I have used the following approach. I think it does what you are trying to do. It first gets the ImportInstances, then the type from that. Let me know if it is helpful.
dwgs = DB.FilteredElementCollector(revit.doc).OfClass(DB.ImportInstance).WhereElementIsNotElementType().ToElements()
if len(dwgs) > 0: # Collector not empty
for ii, dwg in enumerate(dwgs):
dwg_id = dwg.Id
dwg_name = dwg.Parameter[DB.BuiltInParameter.IMPORT_SYMBOL_NAME].AsString()
dwg_type = doc.GetElement(dwg.GetTypeId()) # Get link type from instance
if dwg_type.IsExternalFileReference():
ext_ref = dwg_type.GetExternalFileReference()
dwg_link_path = DB.ModelPathUtils.ConvertModelPathToUserVisiblePath(ext_ref.GetAbsolutePath())
i am intrested in the imported ones , i am aware its wrong, but it happend. so the project is 2 years old. i hoped, that there is anywhere stored the origin of the .dwg
because you are not getting passed this “if” statement. put a simple command after that like print(“Yes”) and you will see it won’t print
Just do a quick compare on import and linked dwgs and you will see for the imported dwgs all the external file refrences are not available