diff --git a/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/ptools.stack/Links.pulldown/Reload Links.pushbutton/script.py b/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/ptools.stack/Links.pulldown/Reload Links.pushbutton/script.py index 7dc6da685..1da6250ea 100644 --- a/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/ptools.stack/Links.pulldown/Reload Links.pushbutton/script.py +++ b/extensions/pyRevitTools.extension/pyRevit.tab/Project.panel/ptools.stack/Links.pulldown/Reload Links.pushbutton/script.py @@ -4,7 +4,6 @@ from pyrevit import HOST_APP from pyrevit import revit, DB -from pyrevit.revit import query from pyrevit import forms from pyrevit import script @@ -15,31 +14,39 @@ need_tsaxn_dict = [DB.ExternalFileReferenceType.CADLink] -def reload_links(linktype=DB.ExternalFileReferenceType.RevitLink): +def reload_links(ref_type=DB.ExternalFileReferenceType.RevitLink): """Reload links of selected type""" try: - extrefs = query.get_links(linktype) - for ref in extrefs: - logger.debug(ref) - - if extrefs: - refcount = len(extrefs) - if refcount > 1: - selected_extrefs = \ + link_type = DB.RevitLinkType + if ref_type == DB.ExternalFileReferenceType.CADLink: + link_type = DB.CADLinkType + + links = DB.FilteredElementCollector(revit.doc) \ + .OfClass(link_type)\ + .ToElements() + + for link in links: + logger.debug(link) + + if links: + xrefs = [revit.db.ExternalRef(x, None) for x in links] + linkcount = len(xrefs) + if linkcount > 1: + selected_xrefs = \ forms.SelectFromList.show( - extrefs, + xrefs, title='Select Links to Reload', width=500, button_name='Reload', multiselect=True ) - if not selected_extrefs: + if not selected_xrefs: script.exit() - elif refcount == 1: - selected_extrefs = extrefs + elif linkcount == 1: + selected_xrefs = xrefs if revit.doc.IsWorkshared\ - and linktype == DB.ExternalFileReferenceType.RevitLink: + and ref_type == DB.ExternalFileReferenceType.RevitLink: reload_locally = forms.alert( 'Do you want to reload links locally, without taking '\ 'ownership and without affecting other users?\n'\ @@ -49,37 +56,32 @@ def reload_links(linktype=DB.ExternalFileReferenceType.RevitLink): else: reload_locally = False - for extref in selected_extrefs: - print("Reloading...\n\t{0}{1}" - .format(str(extref.linktype) + ':', extref.path)) - if linktype in need_tsaxn_dict: - with revit.Transaction('Reload Links'): - extref.reload() - elif linktype \ - and linktype == DB.ExternalFileReferenceType.RevitLink: + for xref in selected_xrefs: + print("Reloading \"{}\"".format(xref.name)) + if ref_type == DB.ExternalFileReferenceType.RevitLink: if reload_locally: try: - if not extref.link.LocallyUnloaded: - extref.link.UnloadLocally(None) - extref.link.RevertLocalUnloadStatus() + if not xref.link.LocallyUnloaded: + xref.link.UnloadLocally(None) + xref.link.RevertLocalUnloadStatus() except Exception as local_reload_err: logger.debug( 'Error while locally reloading ' 'linked model: %s' % local_reload_err) else: - extref.reload() - else: - extref.reload() + xref.reload() + elif ref_type == DB.ExternalFileReferenceType.CADLink: + with revit.Transaction('Reload CAD Links'): + xref.reload() + print("Reload Completed...") except Exception as reload_err: - logger.debug('Load error: %s' % reload_err) - forms.alert('Model is not saved yet. Can not acquire location.') + logger.error('Load error: %s' % reload_err) linktypes = {'Revit Links': DB.ExternalFileReferenceType.RevitLink} if HOST_APP.is_newer_than(2017): linktypes['CAD Links'] = DB.ExternalFileReferenceType.CADLink - linktypes['DWF Markup'] = DB.ExternalFileReferenceType.DWFMarkup if len(linktypes) > 1: selected_option = \