Example #1
0
 def __init__(self, revitFilePath):
     self.cloudModelInfo = RevitCloudModelInfo(revitFilePath)
     pathException = None
     try:
         revitFilePath = path_util.GetFullPath(revitFilePath)
     except ArgumentException, e:  # Catch exceptions such as 'Illegal characters in path.'
         pathException = e
Example #2
0
def InitializeBatchRvtConfig(commandSettingsData, commandLineOptions):
    batchRvtConfig = BatchRvtConfig()

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

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

    batchRvtConfig.SessionId = commandLineOptions[
        CommandSettings.SESSION_ID_OPTION]

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

    if commandSettingsData is not None:
        batchRvtConfig.TaskData = commandSettingsData.TaskData
    else:
        batchRvtConfig.TaskData = commandLineOptions[
            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 = commandLineOptions[
            CommandSettings.TEST_MODE_FOLDER_PATH_OPTION]

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

    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)

    return batchRvtConfig
Example #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