コード例 #1
0
            def processDocument(doc):
                revit_script_util.SetScriptDocument(doc)
                
                def executeTaskScript():
                    success = False
                    output()
                    output("Task script operation started.")
                    if path_util.HasFileExtension(scriptFilePath, script_util.DYNAMO_SCRIPT_FILE_EXTENSION):
                        if revit_dynamo.IsDynamoRevitModuleLoaded():
                            revit_dynamo.ExecuteDynamoScript(uiapp, scriptFilePath, showUI=False)
                            success = True
                        else:
                            success = False
                            output()
                            output(revit_dynamo_error.DYNAMO_REVIT_MODULE_NOT_FOUND_ERROR_MESSAGE)
                    else:
                        script_util.ExecuteScript(scriptFilePath)
                        success = True
                    if success:
                        output()
                        output("Task script operation completed.")
                    else:
                        output()
                        output("ERROR: An error occurred while executing the task script! Operation aborted.")
                    return

                result = script_host_error.WithErrorHandling(
                        executeTaskScript,
                        "ERROR: An error occurred while executing the task script! Operation aborted.",
                        output,
                        showMessageBoxOnTaskError
                    )
                return result
コード例 #2
0
 def outputStreamWriterAction():
     revit_script_util.SetOutputFunction(
         stream_io_util.GetSafeWriteLine(outputStreamWriter))
     result = script_host_error.WithErrorHandling(
         lambda: DoRevitSessionProcessing(
             scriptFilePath, scriptDataFilePath, progressNumber,
             batchRvtProcessUniqueId, revit_script_util.Output),
         "ERROR: An error occurred while executing the script host! Operation aborted.",
         output=revit_script_util.Output,
         showErrorMessageBox=False)
     return result
コード例 #3
0
def DoRevitSessionProcessing(
        scriptFilePath,
        scriptDataFilePath,
        progressNumber,
        batchRvtProcessUniqueId,
        output
    ):
    results = []
    revit_script_util.SetUIApplication(revit_session.GetSessionUIApplication())
    revit_script_util.SetScriptDataFilePath(scriptDataFilePath)
    scriptDatas = (
            revit_script_util.LoadScriptDatas()
            .Where(lambda scriptData: scriptData.ProgressNumber.GetValue() >= progressNumber)
            .OrderBy(lambda scriptData: scriptData.ProgressNumber.GetValue())
            .ToList()
        )
    if len(scriptDatas) > 0:
        revitProcessingOption = GetRevitProcessingOptionForSession(scriptDatas)
        if revitProcessingOption == BatchRvt.RevitProcessingOption.BatchRevitFileProcessing:
            for scriptData in scriptDatas:
                revit_script_util.SetCurrentScriptData(scriptData)
                if not revit_process_host.IsBatchRvtProcessRunning(batchRvtProcessUniqueId):
                    script_host_error.ShowScriptErrorMessageBox("ERROR: The BatchRvt process appears to have terminated! Operation aborted.")
                    break
                progressRecordFilePath = ScriptDataUtil.GetProgressRecordFilePath(scriptDataFilePath)
                progressRecorded = ScriptDataUtil.SetProgressNumber(progressRecordFilePath, scriptData.ProgressNumber.GetValue())
                if not progressRecorded:
                    output()
                    output("WARNING: Failed to update the session progress record file!")
                result = script_host_error.WithErrorHandling(
                        lambda: RunBatchTaskScript(scriptFilePath),
                        "ERROR: An error occurred while processing the file!",
                        output,
                        False
                    )
                results.append(result)
        else:
            scriptData = scriptDatas[0]
            revit_script_util.SetCurrentScriptData(scriptData)
            result = RunSingleTaskScript(scriptFilePath)
            results.append(result)
    else:
        raise Exception("ERROR: received no script data!")
    return results
コード例 #4
0
def RunSingleTaskScript(scriptFilePath):
    aborted = False

    showMessageBoxOnTaskError = revit_script_util.GetShowMessageBoxOnTaskError()
    output = revit_script_util.Output

    try:
        def executeTaskScript():
            output()
            output("Task script operation started.")
            script_util.ExecuteScript(scriptFilePath)
            output()
            output("Task script operation completed.")
            return
        result = script_host_error.WithErrorHandling(
                executeTaskScript,
                "ERROR: An error occurred while executing the task script! Operation aborted.",
                output,
                showMessageBoxOnTaskError
            )
    except Exception, e:
        aborted = True
        raise
コード例 #5
0
                        batchRvtProcessUniqueId, revit_script_util.Output),
                    "ERROR: An error occurred while executing the script host! Operation aborted.",
                    output=revit_script_util.Output,
                    showErrorMessageBox=False)
                return result

            stream_io_util.UsingStream(outputStreamWriter,
                                       outputStreamWriterAction)
            return

        stream_io_util.UsingStream(outputStream, outputStreamAction)

    return


def TerminateSession():
    currentProcess = GetCurrentProcess()
    DoEvents(END_SESSION_DELAY_IN_SECONDS)
    ShutdownSession(currentProcess)
    DoEvents(END_SESSION_DELAY_IN_SECONDS)
    currentProcess.Kill()
    return


script_host_error.WithErrorHandling(
    Main,
    "ERROR: An error occurred while executing the script host! Operation aborted.",
    showErrorMessageBox=False)

TerminateSession()