예제 #1
0
def execute_script(script_path,
                   arguments=None,
                   sys_paths=None,
                   clean_engine=True,
                   fullframe_engine=True):
    """Executes a script using pyRevit script executor.

    Args:
        script_path (str): Address of the script file

    Returns:
        results dictionary from the executed script
    """

    from pyrevit import MAIN_LIB_DIR, MISC_LIB_DIR
    from pyrevit.coreutils import DEFAULT_SEPARATOR
    from pyrevit.framework import clr

    executor = loadertypes.ScriptExecutor()
    script_name = op.basename(script_path)
    core_syspaths = [MAIN_LIB_DIR, MISC_LIB_DIR]
    if sys_paths:
        sys_paths.extend(core_syspaths)
    else:
        sys_paths = core_syspaths

    cmd_runtime = \
        loadertypes.PyRevitCommandRuntime(
            cmdData=create_tmp_commanddata(),
            elements=None,
            scriptSource=script_path,
            alternateScriptSource=None,
            syspaths=DEFAULT_SEPARATOR.join(sys_paths),
            arguments=arguments,
            helpSource=None,
            cmdName=script_name,
            cmdBundle=None,
            cmdExtension=None,
            cmdUniqueName=None,
            needsCleanEngine=clean_engine,
            needsFullFrameEngine=fullframe_engine,
            refreshEngine=False,
            forcedDebugMode=False,
            altScriptMode=False,
            executedFromUI=False
            )

    executor.ExecuteScript(
        clr.Reference[loadertypes.PyRevitCommandRuntime](cmd_runtime))

    return cmd_runtime.GetResultsDictionary()
예제 #2
0
def execute_script(script_path):
    """Executes a script using pyRevit script executor.

    Args:
        script_path (str): Address of the script file

    Returns:
        results dictionary from the executed script
    """

    import os.path as op
    from pyrevit import HOST_APP
    from pyrevit import MAIN_LIB_DIR, MISC_LIB_DIR
    from pyrevit import PYTHON_LIB_DIR, PYTHON_LIB_SITEPKGS_DIR
    from pyrevit.coreutils import DEFAULT_SEPARATOR
    from pyrevit.coreutils.loadertypes import ScriptExecutor

    # noinspection PyUnresolvedReferences
    from System.Collections.Generic import Dictionary

    executor = ScriptExecutor(HOST_APP.uiapp)
    script_name = op.basename(script_path)
    results_dict = Dictionary[str, str]()
    sys_paths = DEFAULT_SEPARATOR.join([MAIN_LIB_DIR,
                                        PYTHON_LIB_DIR,
                                        PYTHON_LIB_SITEPKGS_DIR,
                                        MISC_LIB_DIR])

    executor.ExecuteScript(script_path,
                           sys_paths,
                           script_name,
                           script_name,
                           False, False,
                           results_dict)

    return results_dict
예제 #3
0
def set_loaded_pyrevit_assemblies(loaded_assm_name_list):
    envvars.set_pyrevit_env_var(PYREVIT_LOADEDASSMS_ENVVAR,
                                DEFAULT_SEPARATOR.join(loaded_assm_name_list))

    set_total_loaded_assm_count(get_total_loaded_assm_count() +
                                len(loaded_assm_name_list))
예제 #4
0
def set_loaded_pyrevit_assemblies(loaded_assm_name_list):
    set_pyrevit_env_var(LOADEDASSM_ISC_KEYNAME,
                        DEFAULT_SEPARATOR.join(loaded_assm_name_list))

    set_total_loaded_assm_count(get_total_loaded_assm_count() +
                                len(loaded_assm_name_list))