Skip to content

Commit

Permalink
fixed issue #992 [tool]
Browse files Browse the repository at this point in the history
  • Loading branch information
eirannejad committed Sep 27, 2020
1 parent 1545fa8 commit b1a2a3c
Showing 1 changed file with 34 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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'\
Expand All @@ -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 = \
Expand Down

0 comments on commit b1a2a3c

Please sign in to comment.