def _get_reference_file(ref_name): # First try to find the dll in the project folder addin_file = get_addin_dll_file(ref_name) if addin_file: return addin_file # Then try to find the dll in windows SDK if FRAMEWORK_DIRS: fw_module_file = _get_framework_module(ref_name) if fw_module_file: return fw_module_file # Lastly try to find location of assembly if already loaded loaded_asm = find_loaded_asm(ref_name) if loaded_asm: return loaded_asm[0].Location # if not worked raise critical error logger.critical( 'Can not find required reference assembly: {}'.format(ref_name))
import importlib import os.path as op from pyrevit import HOST_APP, PyRevitException, EXEC_PARAMS from pyrevit.compat import safe_strtype from pyrevit.framework import clr from pyrevit.framework import DateTime, DateTimeOffset from pyrevit.coreutils.logger import get_logger from pyrevit.loader.addin import get_addin_dll_file logger = get_logger(__name__) GIT_LIB = 'LibGit2Sharp' if not EXEC_PARAMS.doc_mode: libgit_dll = get_addin_dll_file(GIT_LIB) logger.debug('Loading dll: {}'.format(libgit_dll)) try: clr.AddReferenceToFileAndPath(libgit_dll) # public libgit module libgit = importlib.import_module(GIT_LIB) except Exception as load_err: logger.error('Can not load {} module. ' 'This module is necessary for getting pyRevit version ' 'and staying updated. | {}'.format(GIT_LIB, load_err)) class PyRevitGitAuthenticationError(PyRevitException): pass
# noinspection PyUnresolvedReferences from System import DateTime, DateTimeOffset logger = get_logger(__name__) GIT_LIB = 'LibGit2Sharp' if not EXEC_PARAMS.doc_mode: # todo: figure out how to import extensions on the caller's scope. clr.AddReference("System.Core") clr.ImportExtensions(System.Linq) # clr.AddReferenceByName(GIT_LIB) try: clr.AddReferenceToFileAndPath(get_addin_dll_file(GIT_LIB)) except: logger.error('Can not load %s module. ' 'This module is necessary for getting pyRevit version ' 'and staying updated.' % GIT_LIB) if not EXEC_PARAMS.doc_mode: # public libgit module libgit = importlib.import_module(GIT_LIB) class PyRevitGitAuthenticationError(PyRevitException): pass
from pyrevit import EXEC_PARAMS from pyrevit.framework import clr from pyrevit.coreutils.logger import get_logger from pyrevit.loader.addin import get_addin_dll_file logger = get_logger(__name__) MATHNET_LIB = 'MathNet.Numerics' mathnet_dll = get_addin_dll_file(MATHNET_LIB) logger.debug('Loading dll: {}'.format(mathnet_dll)) if not EXEC_PARAMS.doc_mode: try: clr.AddReferenceToFileAndPath(mathnet_dll) import MathNet except Exception as load_err: logger.error('Can not load {} module. | {}'.format(GIT_LIB, load_err))