def get_links(linktype=None, doc=None): doc = doc or HOST_APP.doc location = doc.PathName if not location: raise PyRevitException('PathName is empty. Model is not saved.') links = [] model_path = \ DB.ModelPathUtils.ConvertUserVisiblePathToModelPath(location) if not model_path: raise PyRevitException('Model is not saved. Can not read links.') try: trans_data = DB.TransmissionData.ReadTransmissionData(model_path) external_refs = trans_data.GetAllExternalFileReferenceIds() for ref_id in external_refs: ext_ref = trans_data.GetLastSavedReferenceData(ref_id) link = doc.GetElement(ref_id) if linktype: if ext_ref.ExternalFileReferenceType == linktype: links.append(db.ExternalRef(link, ext_ref)) else: links.append(db.ExternalRef(link, ext_ref)) return links except Exception as data_err: raise PyRevitException( 'Error reading links from model path: {} | {}'.format( model_path, data_err))
def get_linked_model_doc(linked_model): lmodel = None if isinstance(linked_model, DB.RevitLinkType): lmodel = db.ExternalRef(linked_model) #pylint: disable=E1120 elif isinstance(linked_model, db.ExternalRef): lmodel = linked_model if lmodel: for open_doc in HOST_APP.docs: if open_doc.Title == lmodel.name: return open_doc
def get_links(linktype=None, doc=None): doc = doc or HOST_APP.doc location = doc.PathName if not location: raise PyRevitException('PathName is empty. Model is not saved.') links = [] modelPath = \ DB.ModelPathUtils.ConvertUserVisiblePathToModelPath(location) transData = DB.TransmissionData.ReadTransmissionData(modelPath) externalReferences = transData.GetAllExternalFileReferenceIds() for refId in externalReferences: extRef = transData.GetLastSavedReferenceData(refId) link = doc.GetElement(refId) if linktype: if extRef.ExternalFileReferenceType == linktype: links.append(db.ExternalRef(link, extRef)) else: links.append(db.ExternalRef(link, extRef)) return links