コード例 #1
0
def LogOutputErrorDetails(exception, output_, verbose=True):
    output = global_test_mode.PrefixedOutputForGlobalTestMode(
        output_, EXCEPTION_MESSAGE_HANDLER_PREFIX)
    exceptionMessage = (str(exception.message) if isinstance(
        exception, exceptions.Exception) else str(exception.Message) if
                        isinstance(exception, System.Exception) else str.Empty)
    output()
    output("Exception: [" + type(exception).__name__ + "] " + exceptionMessage)
    try:
        clsException = GetClrException(exception)
        if clsException is not None:
            clsExceptionType = clr.GetClrType(type(clsException))
            output(".NET exception: [" + str(clsExceptionType.Name) + "] " +
                   str(clsException.Message))
            if verbose:
                interpretedFrameInfo = GetInterpretedFrameInfo(
                    clsException.Data)
                if interpretedFrameInfo is not None:
                    output()
                    output("Further exception information:")
                    output()
                    for i in interpretedFrameInfo:
                        if str(i) != "CallSite.Target":
                            output("\t" + str(i))
    except:
        output("Could not obtain further exception information.")
    return
コード例 #2
0
def WithFailuresProcessingHandler(app, action, output_):
    output = global_test_mode.PrefixedOutputForGlobalTestMode(
        output_, REVIT_WARNINGS_MESSAGE_HANDLER_PREFIX)
    result = None
    failuresProcessingEventHandler = (
        EventHandler[FailuresProcessingEventArgs](
            lambda sender, args: FailuresProcessingEventHandler(
                sender, args, output)))
    app.FailuresProcessing += failuresProcessingEventHandler
    try:
        result = action()
    finally:
        app.FailuresProcessing -= failuresProcessingEventHandler
    return result
コード例 #3
0
def MonitorHostRevitProcess(hostRevitProcess, monitoringAction, output):
    output()
    output("Monitoring host Revit process (PID: " + str(hostRevitProcess.Id) +
           ")")
    output()

    busyOutput = global_test_mode.PrefixedOutputForGlobalTestMode(
        output, REVIT_BUSY_HANDLER_PREFIX)

    monitor_process.MonitorProcess(
        hostRevitProcess, monitoringAction, MONITOR_INTERVAL_IN_SECONDS,
        UNRESPONSIVE_THRESHHOLD_IN_SECONDS,
        lambda: OnBeginUnresponsive(busyOutput),
        lambda unresponsiveTimeInSeconds: OnEndUnresponsive(
            unresponsiveTimeInSeconds, busyOutput))

    output()
    output("Revit process (PID: " + str(hostRevitProcess.Id) + ") has exited!")

    # TODO: do something with last pending read line task if it exists?

    return
コード例 #4
0
def DismissCheekyRevitDialogBoxes(revitProcessId, output_):
    output = global_test_mode.PrefixedOutputForGlobalTestMode(
        output_, REVIT_DIALOG_MESSAGE_HANDLER_PREFIX)
    enabledDialogs = ui_automation_util.GetEnabledDialogsInfo(revitProcessId)
    if len(enabledDialogs) > 0:
        for enabledDialog in enabledDialogs:
            revitDialog = RevitDialogInfo(enabledDialog.Hwnd)
            buttons = revitDialog.Buttons
            win32Buttons = revitDialog.Win32Buttons
            if enabledDialog.WindowText == MODEL_UPGRADE_WINDOW_TITLE and len(
                    buttons) == 0:
                pass  # Do nothing for model upgrade dialog box. It has no buttons and will go away on its own.
            elif (enabledDialog.WindowText == LOAD_LINK_WINDOW_TITLE
                  and len(win32Buttons) == 1
                  and ui_automation_util.GetButtonText(
                      win32Buttons[0]) == CANCEL_LINK_BUTTON_TEXT):
                pass  # Do nothing for this dialog box. It will go away on its own.
            elif enabledDialog.WindowText == script_host_error.BATCH_RVT_ERROR_WINDOW_TITLE:
                # Report dialog detection but do nothing for BatchRvt error message windows.
                if not HAVE_REPORTED_BATCH_RVT_ERROR_WINDOW_DETECTION[0]:
                    output()
                    output(
                        "WARNING: Revit Batch Processor error window detected! Processing has halted!"
                    )
                    HAVE_REPORTED_BATCH_RVT_ERROR_WINDOW_DETECTION[0] = True
                    staticControls = list(
                        ui_automation_util.WindowInfo(hwnd)
                        for hwnd in win32_user32.FindWindows(
                            enabledDialog.Hwnd, STATIC_CONTROL_CLASS_NAME,
                            None))
                    if len(staticControls) > 0:
                        output()
                        output("Dialog has the following static control text:")
                        for staticControl in staticControls:
                            staticControlText = staticControl.WindowText
                            if not str.IsNullOrWhiteSpace(staticControlText):
                                output()
                                output(staticControlText)
            elif enabledDialog.WindowText == CHANGES_NOT_SAVED_TITLE and len(
                    buttons) == 4:
                output()
                output("'" + enabledDialog.WindowText +
                       "' dialog box detected.")
                DismissRevitDialogBox(enabledDialog.WindowText, buttons,
                                      DO_NOT_SAVE_THE_PROJECT_TEXT, output)
            elif enabledDialog.WindowText == CLOSE_PROJECT_WITHOUT_SAVING_TITLE and len(
                    buttons) == 3:
                output()
                output("'" + enabledDialog.WindowText +
                       "' dialog box detected.")
                DismissRevitDialogBox(
                    enabledDialog.WindowText, buttons,
                    RELINQUISH_ALL_ELEMENTS_AND_WORKSETS_TEXT, output)
            elif enabledDialog.WindowText == SAVE_FILE_WINDOW_TITLE and len(
                    buttons) == 3:
                output()
                output("'" + enabledDialog.WindowText +
                       "' dialog box detected.")
                DismissRevitDialogBox(enabledDialog.WindowText, buttons,
                                      NO_BUTTON_TEXT, output)
            elif enabledDialog.WindowText == EDITABLE_ELEMENTS_TITLE and len(
                    buttons) == 3:
                output()
                output("'" + enabledDialog.WindowText +
                       "' dialog box detected.")
                DismissRevitDialogBox(enabledDialog.WindowText, buttons,
                                      RELINQUISH_ELEMENTS_AND_WORKSETS_TEXT,
                                      output)
            elif enabledDialog.WindowText in [
                    "Revit", str.Empty
            ] and len(buttons) == 0 and len(win32Buttons) > 0:
                output()
                output("'" + enabledDialog.WindowText +
                       "' dialog box detected.")
                staticControls = list(
                    ui_automation_util.WindowInfo(hwnd)
                    for hwnd in win32_user32.FindWindows(
                        enabledDialog.Hwnd, STATIC_CONTROL_CLASS_NAME, None))
                if len(staticControls) > 0:
                    output()
                    output("Dialog has the following static control text:")
                    for staticControl in staticControls:
                        staticControlText = staticControl.WindowText
                        if not str.IsNullOrWhiteSpace(staticControlText):
                            output()
                            output(staticControlText)
                SendButtonClick(win32Buttons, output)
            elif enabledDialog.WindowText == AUTODESK_CUSTOMER_INVOLVEMENT_PROGRAM_TITLE and len(
                    buttons) == 0 and len(win32Buttons) > 0:
                output()
                output("'" + enabledDialog.WindowText +
                       "' dialog box detected.")
                output()
                output("Sending close message...")
                win32_user32.SendCloseMessage(enabledDialog.Hwnd)
                output()
                output("...sent.")
            elif enabledDialog.WindowText in OPENING_WORKSETS_TITLES and len(
                    buttons) == 0 and len(win32Buttons) > 0:
                output()
                output("'" + enabledDialog.WindowText +
                       "' dialog box detected.")
                output()
                SendButtonClick(win32Buttons, output)
            else:
                output()
                output("Revit dialog box detected!")
                output()
                output("\tDialog box title: '" + enabledDialog.WindowText +
                       "'")

                buttons = buttons if len(buttons) > 0 else win32Buttons
                for button in buttons:
                    buttonText = ui_automation_util.GetButtonText(button)
                    output()
                    output("\tButton: '" + buttonText + "'")
                SendButtonClick(buttons, output)
    return