Пример #1
0
def GetCommandSettingsOption(aborted,
                             commandLineOptions,
                             commandSettingsOption,
                             output,
                             invalidValueErrorMessage=None,
                             missingValueErrorMessage=None):
    # NOTE: option==None doesn't necessarily mean aborted==True. Specifically, if an optional option is not specified, option==None but aborted==False.
    option = None
    if CommandLineUtil.HasCommandLineOption(commandSettingsOption):
        optionValue = commandLineOptions[commandSettingsOption]
        if optionValue is None:
            output()
            if invalidValueErrorMessage is not None:
                output(invalidValueErrorMessage)
            else:
                output("ERROR: Invalid " + CommandLineUtil.OptionSwitchPrefix +
                       commandSettingsOption + " option value!")
            aborted = True
        else:
            option = optionValue
    elif CommandLineUtil.HasCommandLineOption(commandSettingsOption, False):
        output()
        if missingValueErrorMessage is not None:
            output(missingValueErrorMessage)
        else:
            output("ERROR: Missing " + CommandLineUtil.OptionSwitchPrefix +
                   commandSettingsOption + " option value!")
        aborted = True
    return option, aborted
Пример #2
0
def ConfigureBatchRvt(commandSettingsData, output):
    aborted = False

    commandLineOptions = CommandSettings.GetCommandLineOptions()
    batchRvtConfig = InitializeBatchRvtConfig(commandSettingsData,
                                              commandLineOptions)

    global_test_mode.InitializeGlobalTestMode(
        batchRvtConfig.TestModeFolderPath)
    global_test_mode.ExportSessionId(batchRvtConfig.SessionId)

    output()
    output("Session ID: " + batchRvtConfig.SessionId)

    output()
    output("Log File:")
    output()
    output("\t" + batchRvtConfig.LogFilePath)

    haveHelpOption = commandLineOptions[CommandSettings.HELP_OPTION]
    if not CommandLineUtil.HaveArguments() or haveHelpOption:
        ShowCommandLineHelp(output)
        aborted = True

    if not aborted:
        invalidOptions = CommandSettings.GetInvalidOptions()
        if invalidOptions.Any():
            ShowInvalidOptionsError(invalidOptions, output)
            aborted = True

    revitVersionOption, aborted = GetCommandSettingsOption(
        aborted, commandLineOptions, CommandSettings.REVIT_VERSION_OPTION,
        output)
    if not aborted and revitVersionOption is not None:
        output()
        output("Using specific Revit version: " +
               RevitVersion.GetRevitVersionText(revitVersionOption))

    revitFileListOption, aborted = GetCommandSettingsOption(
        aborted,
        commandLineOptions,
        CommandSettings.REVIT_FILE_LIST_OPTION,
        output,
        invalidValueErrorMessage="ERROR: Revit file list not found.",
        missingValueErrorMessage="ERROR: Missing Revit file list option value!"
    )

    taskScriptFilePathOption, aborted = GetCommandSettingsOption(
        aborted,
        commandLineOptions,
        CommandSettings.TASK_SCRIPT_FILE_PATH_OPTION,
        output,
        invalidValueErrorMessage="ERROR: Task script file not found.",
        missingValueErrorMessage="ERROR: Missing Task script file option value!"
    )

    centralFileOpenOption = None
    if not aborted:
        haveDetachOption = CommandLineUtil.HasCommandLineOption(
            CommandSettings.DETACH_OPTION, False)
        haveCreateNewLocalOption = CommandLineUtil.HasCommandLineOption(
            CommandSettings.CREATE_NEW_LOCAL_OPTION, False)
        if haveDetachOption and haveCreateNewLocalOption:
            output()
            output("ERROR: You cannot specify both " +
                   CommandLineUtil.OptionSwitchPrefix +
                   CommandSettings.DETACH_OPTION + " and " +
                   CommandLineUtil.OptionSwitchPrefix +
                   CommandSettings.CREATE_NEW_LOCAL_OPTION +
                   " options simultaneously.")
            aborted = True
        elif haveDetachOption or haveCreateNewLocalOption:
            centralFileOpenOption = (
                BatchRvt.CentralFileOpenOption.CreateNewLocal
                if haveCreateNewLocalOption else
                BatchRvt.CentralFileOpenOption.Detach  # default
            )

    worksetsOption, aborted = GetCommandSettingsOption(
        aborted, commandLineOptions, CommandSettings.WORKSETS_OPTION, output)

    auditOnOpeningOption = None
    if not aborted:
        haveAuditOnOpeningOption = CommandLineUtil.HasCommandLineOption(
            CommandSettings.AUDIT_ON_OPENING_OPTION, False)
        if haveAuditOnOpeningOption:
            auditOnOpeningOption = haveAuditOnOpeningOption

    perFileTimeoutOption, aborted = GetCommandSettingsOption(
        aborted, commandLineOptions,
        CommandSettings.PER_FILE_PROCESSING_TIMEOUT_OPTION, output)

    if (not RevitVersion.GetInstalledRevitVersions().Any()):
        output()
        output(
            "ERROR: Could not detect the BatchRvt addin for any version of Revit installed on this machine!"
        )
        output()
        output(
            "You must first install the BatchRvt addin for at least one version of Revit."
        )
        aborted = True

    if not aborted:
        batchRvtSettings = InitializeBatchRvtSettings(
            commandSettingsData, batchRvtConfig, revitFileListOption,
            taskScriptFilePathOption, output)
        if batchRvtSettings is None:
            aborted = True

    if not aborted:
        # Handles command-line overrides
        if revitVersionOption is not None:
            batchRvtSettings.RevitFileProcessingOption.SetValue(
                BatchRvt.RevitFileProcessingOption.UseSpecificRevitVersion)
            batchRvtSettings.BatchRevitTaskRevitVersion.SetValue(
                revitVersionOption)
        if revitFileListOption is not None:
            batchRvtSettings.RevitFileListFilePath.SetValue(
                revitFileListOption)
        if taskScriptFilePathOption is not None:
            batchRvtSettings.TaskScriptFilePath.SetValue(
                taskScriptFilePathOption)
        if centralFileOpenOption is not None:
            batchRvtSettings.CentralFileOpenOption.SetValue(
                centralFileOpenOption)
        if worksetsOption is not None:
            batchRvtSettings.WorksetConfigurationOption.SetValue(
                worksetsOption)
        if auditOnOpeningOption is not None:
            batchRvtSettings.AuditOnOpening.SetValue(auditOnOpeningOption)
        if perFileTimeoutOption is not None:
            batchRvtSettings.ProcessingTimeOutInMinutes.SetValue(
                perFileTimeoutOption)
        aborted = ConfigureBatchRvtSettings(batchRvtConfig, batchRvtSettings,
                                            output)

    return batchRvtConfig if not aborted else None
Пример #3
0
def ConfigureBatchRvt(commandSettingsData, output):
    aborted = False

    batchRvtConfig = BatchRvtConfig()

    options = CommandSettings.GetCommandLineOptions()

    if commandSettingsData is not None:
        batchRvtConfig.SettingsFilePath = commandSettingsData.SettingsFilePath
    else:
        batchRvtConfig.SettingsFilePath = options[
            CommandSettings.SETTINGS_FILE_PATH_OPTION]

    if commandSettingsData is not None:
        batchRvtConfig.LogFolderPath = commandSettingsData.LogFolderPath
    else:
        batchRvtConfig.LogFolderPath = options[
            CommandSettings.LOG_FOLDER_PATH_OPTION]

    batchRvtConfig.SessionId = options[CommandSettings.SESSION_ID_OPTION]

    batchRvtConfig.SessionId, batchRvtConfig.SessionStartTime = ParseSessionIdAndStartTime(
        batchRvtConfig.SessionId)

    if commandSettingsData is not None:
        batchRvtConfig.TaskData = commandSettingsData.TaskData
    else:
        batchRvtConfig.TaskData = options[CommandSettings.TASK_DATA_OPTION]

    # NOTE: use of output function must occur after the log file initialization
    batchRvtConfig.LogFilePath = InitializeLogging(
        batchRvtConfig.LogFolderPath, batchRvtConfig.SessionStartTime)

    if commandSettingsData is not None:
        commandSettingsData.GeneratedLogFilePath = batchRvtConfig.LogFilePath

    testModeFolderPath = None
    if commandSettingsData is not None:
        testModeFolderPath = commandSettingsData.TestModeFolderPath
    else:
        testModeFolderPath = options[
            CommandSettings.TEST_MODE_FOLDER_PATH_OPTION]

    batchRvtConfig.TestModeFolderPath = (
        path_util.GetFullPath(testModeFolderPath)
        if not str.IsNullOrWhiteSpace(testModeFolderPath) else None)
    global_test_mode.InitializeGlobalTestMode(
        batchRvtConfig.TestModeFolderPath)

    if commandSettingsData is not None:
        if commandSettingsData.RevitFileList is not None:
            # NOTE: list is constructed here because although the source object is an IEnumerable<string> it may not be a list.
            batchRvtConfig.RevitFileList = list(
                revitFilePath
                for revitFilePath in commandSettingsData.RevitFileList)

    global_test_mode.ExportSessionId(batchRvtConfig.SessionId)

    output()
    output("Session ID: " + batchRvtConfig.SessionId)

    output()
    output("Log File:")
    output()
    output("\t" + batchRvtConfig.LogFilePath)

    haveHelpOption = options[CommandSettings.HELP_OPTION]
    if not CommandLineUtil.HaveArguments() or haveHelpOption:
        output()
        output("Help:")
        output()
        output("\t" + "Usage (using a settings file):")
        output()
        output(
            "\t\t" +
            "BatchRvt.exe --settings_file <SETTINGS FILE PATH> [--log_folder <LOG FOLDER PATH>]"
        )
        output()
        output("\t" + "Example:")
        output()
        output(
            "\t\t" +
            "BatchRvt.exe --settings_file BatchRvt.Settings.json --log_folder ."
        )
        output()
        output()
        output("\t" + "Usage (without a settings file):")
        output()
        output(
            "\t\t" +
            "BatchRvt.exe --file_list <REVIT FILE LIST PATH> --task_script <TASK SCRIPT FILE PATH> [--revit_version <REVIT VERSION>] [--log_folder <LOG FOLDER PATH>]"
        )
        output()
        output(
            "\t" +
            "(NOTE: this mode operates in batch mode only; operates in detach mode for central files.)"
        )
        output()
        output("\t" + "Example:")
        output()
        output(
            "\t\t" +
            "BatchRvt.exe --task_script MyDynamoWorkspace.dyn --file_list RevitFileList.xlsx"
        )

        aborted = True

    revitVersionOption = None
    if not aborted:
        if CommandLineUtil.HasCommandLineOption(
                CommandSettings.REVIT_VERSION_OPTION, False):
            revitVersionOption = options[CommandSettings.REVIT_VERSION_OPTION]
            if revitVersionOption is not None:
                output()
                output("Using specific Revit version: " + revitVersionOption)
            else:
                output()
                output("Invalid value for " +
                       CommandLineUtil.OptionSwitchPrefix +
                       CommandSettings.REVIT_VERSION_OPTION + " option!")
                aborted = True

    revitFileListOption = None
    if not aborted:
        if CommandLineUtil.HasCommandLineOption(
                CommandSettings.REVIT_FILE_LIST_OPTION):
            revitFileListOption = options[
                CommandSettings.REVIT_FILE_LIST_OPTION]
            if revitFileListOption is None:
                output()
                output("ERROR: Revit file list not found.")
                aborted = True
        elif CommandLineUtil.HasCommandLineOption(
                CommandSettings.REVIT_FILE_LIST_OPTION, False):
            output()
            output("ERROR: Missing Revit file list option value!")
            aborted = True

    taskScriptFilePathOption = None
    if not aborted:
        if CommandLineUtil.HasCommandLineOption(
                CommandSettings.TASK_SCRIPT_FILE_PATH_OPTION):
            taskScriptFilePathOption = options[
                CommandSettings.TASK_SCRIPT_FILE_PATH_OPTION]
            if taskScriptFilePathOption is None:
                output()
                output("ERROR: Task script file not found.")
                aborted = True
        elif CommandLineUtil.HasCommandLineOption(
                CommandSettings.TASK_SCRIPT_FILE_PATH_OPTION, False):
            output()
            output("ERROR: Missing Task script file option value!")
            aborted = True

    if (not RevitVersion.GetInstalledRevitVersions().Any()):
        output()
        output(
            "ERROR: Could not detect the BatchRvt addin for any version of Revit installed on this machine!"
        )
        output()
        output(
            "You must first install the BatchRvt addin for at least one version of Revit."
        )
        aborted = True

    if not aborted:
        if commandSettingsData is not None and commandSettingsData.Settings is not None:
            batchRvtSettings = commandSettingsData.Settings
        elif batchRvtConfig.SettingsFilePath is not None:
            batchRvtSettings = GetBatchRvtSettings(
                batchRvtConfig.SettingsFilePath, output)
            if batchRvtSettings is None:
                aborted = True
        elif revitFileListOption is not None and taskScriptFilePathOption is not None:
            # Initialize appropriate defaults for non-settings-file mode.
            batchRvtSettings = BatchRvtSettings()
            batchRvtSettings.CentralFileOpenOption.SetValue(
                BatchRvt.CentralFileOpenOption.Detach
            )  # TODO: make this a command line option too?
            batchRvtSettings.RevitProcessingOption.SetValue(
                BatchRvt.RevitProcessingOption.BatchRevitFileProcessing)
            batchRvtSettings.RevitSessionOption.SetValue(
                BatchRvt.RevitSessionOption.UseSameSessionForFilesOfSameVersion
            )  # TODO: reconsider default?
            batchRvtSettings.RevitFileProcessingOption.SetValue(
                BatchRvt.RevitFileProcessingOption.
                UseFileRevitVersionIfAvailable)
            batchRvtSettings.IfNotAvailableUseMinimumAvailableRevitVersion.SetValue(
                False)  # TODO: reconsider default?
        else:
            output()
            output(
                "ERROR: No settings file specified or settings file not found."
            )
            aborted = True

    if not aborted:
        if revitVersionOption is not None:
            batchRvtSettings.RevitFileProcessingOption.SetValue(
                BatchRvt.RevitFileProcessingOption.UseSpecificRevitVersion)
            batchRvtSettings.BatchRevitTaskRevitVersion.SetValue(
                RevitVersion.GetSupportedRevitVersion(revitVersionOption))
        if revitFileListOption is not None:
            batchRvtSettings.RevitFileListFilePath.SetValue(
                revitFileListOption)
        if taskScriptFilePathOption is not None:
            batchRvtSettings.TaskScriptFilePath.SetValue(
                taskScriptFilePathOption)
        aborted = ConfigureBatchRvtSettings(batchRvtConfig, batchRvtSettings,
                                            output)

    return batchRvtConfig if not aborted else None