def cleanup_assembly_files(): if coreutils.get_revit_instance_count() == 1: for asm_file_path in appdata.list_data_files(file_ext='dll'): if not assmutils.find_loaded_asm(asm_file_path, by_location=True): appdata.garbage_data_file(asm_file_path) asm_log_file = asm_file_path.replace('.dll', '.log') if op.exists(asm_log_file): appdata.garbage_data_file(asm_log_file)
def _produce_ui_linkbutton(ui_maker_params): """ Args: ui_maker_params (UIMakerParams): Standard parameters for making ui item """ parent_ui_item = ui_maker_params.parent_ui parent = ui_maker_params.parent_cmp linkbutton = ui_maker_params.component ext_asm_info = ui_maker_params.asm_info if not linkbutton.is_supported: return None if linkbutton.is_beta and not ui_maker_params.create_beta_cmds: return None mlogger.debug('Producing button: %s', linkbutton) try: linked_asm = None # attemp to find the assembly file linked_asm_file = linkbutton.get_target_assembly() # if not found, search the loaded assemblies # this is usually a slower process if linked_asm_file: linked_asm = assmutils.load_asm_file(linked_asm_file) else: linked_asm_list = assmutils.find_loaded_asm(linkbutton.assembly) # cancel button creation if not found if not linked_asm_list: mlogger.error("Can not find target assembly for %s", linkbutton) return None linked_asm = linked_asm_list[0] parent_ui_item.create_push_button( button_name=linkbutton.name, asm_location=linked_asm.Location, class_name=_make_full_class_name( linked_asm.GetName().Name, linkbutton.command_class ), icon_path=linkbutton.icon_file or parent.icon_file, tooltip=_make_button_tooltip(linkbutton), tooltip_ext=_make_button_tooltip_ext(linkbutton, ext_asm_info.name), tooltip_media=linkbutton.media_file, ctxhelpurl=linkbutton.help_url, avail_class_name=linkbutton.avail_class_name, update_if_exists=True, ui_title=_make_ui_title(linkbutton)) linkbutton_ui = parent_ui_item.button(linkbutton.name) _set_highlights(linkbutton, linkbutton_ui) return linkbutton_ui except PyRevitException as err: mlogger.error('UI error: %s', err.msg) return None
def find_all_commands(category_set=None, cache=True): global pyrevit_extcmdtype_cache #pylint: disable=W0603 if cache and pyrevit_extcmdtype_cache: #pylint: disable=E0601 pyrevit_extcmds = pyrevit_extcmdtype_cache else: pyrevit_extcmds = [] for loaded_assm_name in sessioninfo.get_loaded_pyrevit_assemblies(): loaded_assm = assmutils.find_loaded_asm(loaded_assm_name) if loaded_assm: all_exported_types = loaded_assm[0].GetTypes() for pyrvt_type in all_exported_types: tname = pyrvt_type.FullName availtname = pyrvt_type.Name \ + runtime.CMD_AVAIL_NAME_POSTFIX pyrvt_availtype = None if not tname.endswith(runtime.CMD_AVAIL_NAME_POSTFIX)\ and runtime.RUNTIME_NAMESPACE not in tname: for exported_type in all_exported_types: if exported_type.Name == availtname: pyrvt_availtype = exported_type pyrevit_extcmds.append( PyRevitExternalCommandType(pyrvt_type, pyrvt_availtype)) if cache: pyrevit_extcmdtype_cache = pyrevit_extcmds # now check commands in current context if requested if category_set: return [ x for x in pyrevit_extcmds if x.is_available(category_set=category_set, zerodoc=HOST_APP.uidoc is None) ] else: return pyrevit_extcmds
def find_pyrevitcmd(pyrevitcmd_unique_id): """Searches the pyRevit-generated assemblies under current session for the command with the matching unique name (class name) and returns the command type. Notice that this returned value is a 'type' and should be instantiated before use. Example: >>> cmd = find_pyrevitcmd('pyRevitCorepyRevitpyRevittoolsReload') >>> command_instance = cmd() >>> command_instance.Execute() # Provide commandData, message, elements Args: pyrevitcmd_unique_id (str): Unique name for the command Returns: Type for the command with matching unique name """ # go through assmebles loaded under current pyRevit session # and try to find the command mlogger.debug('Searching for pyrevit command: %s', pyrevitcmd_unique_id) for loaded_assm_name in sessioninfo.get_loaded_pyrevit_assemblies(): mlogger.debug('Expecting assm: %s', loaded_assm_name) loaded_assm = assmutils.find_loaded_asm(loaded_assm_name) if loaded_assm: mlogger.debug('Found assm: %s', loaded_assm_name) for pyrvt_type in loaded_assm[0].GetTypes(): mlogger.debug('Found Type: %s', pyrvt_type) if pyrvt_type.FullName == pyrevitcmd_unique_id: mlogger.debug('Found pyRevit command in %s', loaded_assm_name) return pyrvt_type mlogger.debug('Could not find pyRevit command.') else: mlogger.debug('Can not find assm: %s', loaded_assm_name) return None
def _get_reference_file(ref_name): mlogger.debug('Searching for dependency: %s', ref_name) # First try to find the dll in the project folder addin_file = framework.get_dll_file(ref_name) if addin_file: assmutils.load_asm_file(addin_file) return addin_file mlogger.debug('Dependency is not shipped: %s', ref_name) mlogger.debug('Searching for dependency in loaded assemblies: %s', ref_name) # Lastly try to find location of assembly if already loaded loaded_asm = assmutils.find_loaded_asm(ref_name) if loaded_asm: return loaded_asm[0].Location mlogger.debug('Dependency is not loaded: %s', ref_name) mlogger.debug('Searching for dependency in installed frameworks: %s', ref_name) # Then try to find the dll in windows installed framework files if DOTNET_DIR: fw_module_file = _get_framework_module(ref_name) if fw_module_file: return fw_module_file mlogger.debug('Dependency is not installed: %s', ref_name) mlogger.debug('Searching for dependency in installed frameworks sdks: %s', ref_name) # Then try to find the dll in windows SDK if DOTNET_TARGETPACK_DIRS: fw_sdk_module_file = _get_framework_sdk_module(ref_name) if fw_sdk_module_file: return fw_sdk_module_file # if not worked raise critical error mlogger.critical('Can not find required reference assembly: %s', ref_name)
def _is_pyrevit_ext_already_loaded(ext_asm_name): mlogger.debug('Asking Revit for previously loaded package assemblies: %s', ext_asm_name) return len(assmutils.find_loaded_asm(ext_asm_name))
# call base constructor (consumes "this" and the created stack) gen.Emit(framework.OpCodes.Call, constructor) # Fill some space - this is how it is generated for equivalent C# code gen.Emit(framework.OpCodes.Nop) gen.Emit(framework.OpCodes.Nop) gen.Emit(framework.OpCodes.Nop) gen.Emit(framework.OpCodes.Ret) return type_builder.CreateType() if not EXEC_PARAMS.doc_mode: # compile or load the base types assembly # see it the assembly is already loaded RUNTIME_ASSM = None assm_list = assmutils.find_loaded_asm(RUNTIME_ASSM_NAME) if assm_list: RUNTIME_ASSM = assm_list[0] else: # else, let's generate the assembly and load it RUNTIME_ASSM = _get_runtime_asm() CMD_EXECUTOR_TYPE = \ assmutils.find_type_by_name(RUNTIME_ASSM, CMD_EXECUTOR_TYPE_NAME) CMD_AVAIL_TYPE_EXTENDED = \ assmutils.find_type_by_name(RUNTIME_ASSM, CMD_AVAIL_TYPE_NAME_EXTENDED) CMD_AVAIL_TYPE_SELECTION = \ assmutils.find_type_by_name(RUNTIME_ASSM, CMD_AVAIL_TYPE_NAME_SELECTION)
logger = script.get_logger() output = script.get_output() ASSMS = [ 'RevitAPI', 'RevitAPIUI', # 'UIFramework', # 'Adwindows', 'pyRevitLabs.Common', 'pyRevitLabs.TargetApps.Revit', 'pyRevitLabs.PyRevit', ] dest_path = forms.pick_folder() if dest_path: for assm_name in ASSMS: assm = assmutils.find_loaded_asm(assm_name) if assm: try: stubs_path = labs.PythonStubsBuilder.BuildAssemblyStubs( assm[0].Location, destPath=dest_path ) print('Generated stubs for %s -> %s' % (assm_name, stubs_path)) except Exception as sgEx: logger.error('Failed generating stubs for %s', assm_name)