def RunSingleRevitTask(batchRvtConfig):
    aborted = False

    revitVersion = batchRvtConfig.SingleRevitTaskRevitVersion
    Output()
    Output("Revit Version:")
    Output()
    Output("\t" + RevitVersion.GetRevitVersionText(revitVersion))

    if revitVersion not in RevitVersion.GetInstalledRevitVersions():
        Output()
        Output(
            "ERROR: The specified Revit version is not installed or the addin is not installed for it."
        )
        aborted = True

    if not aborted:
        if batchRvtConfig.ExecutePreProcessingScript:
            aborted = ExecutePreProcessingScript(batchRvtConfig, Output)

    if not aborted:
        Output()
        Output("Starting single task operation...")

        Output()
        Output("Starting Revit " +
               RevitVersion.GetRevitVersionText(revitVersion) + " session...")

        scriptData = ScriptDataUtil.ScriptData()
        scriptData.SessionId.SetValue(batchRvtConfig.SessionId)
        scriptData.TaskScriptFilePath.SetValue(batchRvtConfig.ScriptFilePath)
        scriptData.TaskData.SetValue(batchRvtConfig.TaskData)
        scriptData.EnableDataExport.SetValue(batchRvtConfig.EnableDataExport)
        scriptData.SessionDataFolderPath.SetValue(
            batchRvtConfig.SessionDataFolderPath)
        scriptData.ShowMessageBoxOnTaskScriptError.SetValue(
            batchRvtConfig.ShowMessageBoxOnTaskError)
        scriptData.RevitProcessingOption.SetValue(
            batchRvtConfig.RevitProcessingOption)
        scriptData.ProgressNumber.SetValue(1)
        scriptData.ProgressMax.SetValue(1)

        batchRvtScriptsFolderPath = BatchRvt.GetBatchRvtScriptsFolderPath()

        batch_rvt_monitor_util.RunScriptedRevitSession(
            revitVersion, batchRvtScriptsFolderPath,
            batchRvtConfig.ScriptFilePath, [scriptData], 1,
            batchRvtConfig.ProcessingTimeOutInMinutes,
            batchRvtConfig.ShowRevitProcessErrorMessages,
            batchRvtConfig.TestModeFolderPath, Output)

    if not aborted:
        if batchRvtConfig.ExecutePostProcessingScript:
            aborted = ExecutePostProcessingScript(batchRvtConfig, Output)

    return aborted
Example #2
0
def StartRevitProcess(revitVersion, initEnvironmentVariables):
    revitExecutableFilePath = RevitVersion.GetRevitExecutableFilePath(revitVersion)
    psi = ProcessStartInfo(revitExecutableFilePath)
    psi.UseShellExecute = False
    psi.RedirectStandardError = True
    psi.RedirectStandardOutput = True
    psi.WorkingDirectory = RevitVersion.GetRevitExecutableFolderPath(revitVersion)
    initEnvironmentVariables(psi.EnvironmentVariables)
    revitProcess = Process.Start(psi)
    return revitProcess
Example #3
0
 def __init__(self, revitFilePathData):
     self.revitFileInfo = RevitFileInfo(revitFilePathData.RevitFilePath)
     self.revitFilePathData = revitFilePathData
     revitVersionText = None
     revitVersionNumber = None
     if self.revitFileInfo.IsCloudModel():
         revitVersionText = self.revitFileInfo.GetRevitCloudModelInfo(
         ).GetRevitVersionText()
         if not str.IsNullOrWhiteSpace(revitVersionText):
             if RevitVersion.IsSupportedRevitVersionNumber(
                     revitVersionText):
                 revitVersionNumber = RevitVersion.GetSupportedRevitVersion(
                     revitVersionText)
     else:
         revitVersionText = self.revitFileInfo.TryGetRevitVersionText()
         if not str.IsNullOrWhiteSpace(revitVersionText):
             if any(
                     revitVersionText.StartsWith(prefix) for prefix in
                     revit_file_version.REVIT_VERSION_TEXT_PREFIXES_2015):
                 revitVersionNumber = RevitVersion.SupportedRevitVersion.Revit2015
             elif any(
                     revitVersionText.StartsWith(prefix) for prefix in
                     revit_file_version.REVIT_VERSION_TEXT_PREFIXES_2016):
                 revitVersionNumber = RevitVersion.SupportedRevitVersion.Revit2016
             elif any(
                     revitVersionText.StartsWith(prefix) for prefix in
                     revit_file_version.REVIT_VERSION_TEXT_PREFIXES_2017):
                 revitVersionNumber = RevitVersion.SupportedRevitVersion.Revit2017
             elif any(
                     revitVersionText.StartsWith(prefix) for prefix in
                     revit_file_version.REVIT_VERSION_TEXT_PREFIXES_2018):
                 revitVersionNumber = RevitVersion.SupportedRevitVersion.Revit2018
             elif any(
                     revitVersionText.StartsWith(prefix) for prefix in
                     revit_file_version.REVIT_VERSION_TEXT_PREFIXES_2019):
                 revitVersionNumber = RevitVersion.SupportedRevitVersion.Revit2019
             elif any(
                     revitVersionText.StartsWith(prefix) for prefix in
                     revit_file_version.REVIT_VERSION_TEXT_PREFIXES_2020):
                 revitVersionNumber = RevitVersion.SupportedRevitVersion.Revit2020
             elif any(
                     revitVersionText.StartsWith(prefix) for prefix in
                     revit_file_version.REVIT_VERSION_TEXT_PREFIXES_2021):
                 revitVersionNumber = RevitVersion.SupportedRevitVersion.Revit2021
             elif any(
                     revitVersionText.StartsWith(prefix) for prefix in
                     revit_file_version.REVIT_VERSION_TEXT_PREFIXES_2022):
                 revitVersionNumber = RevitVersion.SupportedRevitVersion.Revit2022
     self.revitVersionText = revitVersionText
     self.revitVersionNumber = revitVersionNumber
     return
Example #4
0
def GetRevitVersionForRevitFileSession(batchRvtConfig, supportedRevitFileInfo):
    revitVersion = RevitVersion.GetMinimumInstalledRevitVersion()
    if (batchRvtConfig.RevitFileProcessingOption ==
            BatchRvt.RevitFileProcessingOption.UseSpecificRevitVersion):
        revitVersion = batchRvtConfig.BatchRevitTaskRevitVersion
    elif HasSupportedRevitVersion(supportedRevitFileInfo):
        revitVersion = supportedRevitFileInfo.TryGetRevitVersionNumber()
    return revitVersion
Example #5
0
 def __init__(self, cloudModelDescriptor):
     self.cloudModelDescriptor = cloudModelDescriptor
     self.projectGuid = None
     self.modelGuid = None
     self.revitVersionText = None
     self.isValid = False
     parts = self.GetCloudModelDescriptorParts(cloudModelDescriptor)
     numberOfParts = len(parts)
     if numberOfParts == 2 or numberOfParts == 3:
         revitVersionPart = str.Empty
         otherParts = parts
         if numberOfParts == 3:
             revitVersionPart = parts[0]
             otherParts = parts[1:]
         self.projectGuid = self.SafeParseGuidText(otherParts[0])
         self.modelGuid = self.SafeParseGuidText(otherParts[1])
         if RevitVersion.IsSupportedRevitVersionNumber(revitVersionPart):
             self.revitVersionText = revitVersionPart
         self.isValid = (self.projectGuid is not None
                         and self.modelGuid is not None)
     return
Example #6
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
def RunBatchTaskScript(scriptFilePath):
    aborted = False

    uiapp = revit_session.GetSessionUIApplication()
    sessionId = revit_script_util.GetSessionId()
    centralFilePath = revit_script_util.GetRevitFilePath()
    openInUI = revit_script_util.GetOpenInUI()
    enableDataExport = revit_script_util.GetEnableDataExport()
    dataExportFolderPath = revit_script_util.GetDataExportFolderPath()
    showMessageBoxOnTaskError = revit_script_util.GetShowMessageBoxOnTaskError(
    )
    centralFileOpenOption = revit_script_util.GetCentralFileOpenOption()
    deleteLocalAfter = revit_script_util.GetDeleteLocalAfter()
    discardWorksetsOnDetach = revit_script_util.GetDiscardWorksetsOnDetach()
    progressNumber = revit_script_util.GetProgressNumber()
    progressMax = revit_script_util.GetProgressMax()
    output = revit_script_util.Output

    if enableDataExport and not path_util.DirectoryExists(
            dataExportFolderPath):
        output()
        output("ERROR: data export folder does not exist!")
        if not str.IsNullOrWhiteSpace(dataExportFolderPath):
            output()
            output("\t" + dataExportFolderPath)
        aborted = True
    elif not path_util.FileExists(centralFilePath):
        output()
        output("ERROR: Revit project file does not exist!")
        if not str.IsNullOrWhiteSpace(centralFilePath):
            output()
            output("\t" + centralFilePath)
        aborted = True
    else:
        if enableDataExport:
            snapshotStartTime = time_util.GetDateTimeNow()
            snapshotError = None
            snapshotEndTime = None
            revitJournalFilePath = uiapp.Application.RecordingJournalFilename
            snapshotData = snapshot_data_exporter.ExportTemporarySnapshotData(
                sessionId, centralFilePath, snapshotStartTime, snapshotEndTime,
                dataExportFolderPath, revitJournalFilePath, snapshotError)

        localFilePath = None
        openCreateNewLocal = False  # default is False because the file may not be a workshared Central file.
        isCentralModel = False
        isLocalModel = False
        try:
            output()
            output("Processing file (" + str(progressNumber) + " of " +
                   str(progressMax) + "): " + centralFilePath)

            if revit_file_util.IsWorkshared(centralFilePath):
                if revit_file_util.IsLocalModel(centralFilePath):
                    output()
                    output(
                        "WARNING: the file being processed appears to be a Workshared Local file!"
                    )
                    isLocalModel = True
                if revit_file_util.IsCentralModel(centralFilePath):
                    output()
                    output("The file is a Central Model file.")
                    isCentralModel = True
                if centralFileOpenOption == BatchRvt.CentralFileOpenOption.CreateNewLocal:
                    openCreateNewLocal = True
            elif path_util.HasFileExtension(centralFilePath, ".rfa"):
                output()
                output("The file is a Family file.")
            else:
                output()
                output("The file is a Non-workshared file.")

            if enableDataExport:
                output()
                output("Export folder is: " + dataExportFolderPath)

            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

            result = None
            activeDoc = None  #revit_script_util.GetActiveDocument(uiapp)
            if activeDoc is not None:
                result = processDocument(activeDoc)
            else:
                if openCreateNewLocal:
                    revitVersion = RevitVersion.GetSupportedRevitVersion(
                        revit_session.GetSessionRevitVersionNumber())
                    localFilePath = RevitVersion.GetRevitLocalFilePath(
                        revitVersion, centralFilePath)
                    try:
                        if File.Exists(localFilePath):
                            output()
                            output("Deleting existing local file...")
                            File.Delete(localFilePath)
                            output()
                            output("Local file deleted.")
                    except Exception, e:
                        output()
                        output("WARNING: failed to delete the local file!")
                    path_util.CreateDirectoryForFilePath(localFilePath)
                    result = revit_script_util.RunNewLocalDocumentAction(
                        uiapp, openInUI, centralFilePath, localFilePath,
                        processDocument, output)
                elif isCentralModel or isLocalModel:
                    result = revit_script_util.RunDetachedDocumentAction(
                        uiapp, openInUI, centralFilePath,
                        discardWorksetsOnDetach, processDocument, output)
                else:
Example #8
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
Example #9
0
def HasSupportedRevitVersion(supportedRevitFileInfo):
    return (supportedRevitFileInfo.TryGetRevitVersionNumber()
            in RevitVersion.GetInstalledRevitVersions())
Example #10
0
def ProcessRevitFiles(batchRvtConfig, supportedRevitFileList):
    aborted = False

    totalFilesCount = len(supportedRevitFileList)
    progressNumber = 1

    for revitVersion, supportedRevitFiles in GroupByRevitVersion(
            batchRvtConfig, supportedRevitFileList):

        sessionRevitFiles = []
        queuedRevitFiles = list(supportedRevitFiles)

        while queuedRevitFiles.Any():
            scriptDatas = []
            snapshotDataExportFolderPaths = []

            if batchRvtConfig.RevitSessionOption == BatchRvt.RevitSessionOption.UseSameSessionForFilesOfSameVersion:
                sessionRevitFiles = queuedRevitFiles
                queuedRevitFiles = []
            else:
                sessionRevitFiles = [queuedRevitFiles[0]]
                queuedRevitFiles = queuedRevitFiles[1:]

            sessionFilesCount = len(sessionRevitFiles)
            if len(sessionRevitFiles) == 1:
                Output()
                Output("Processing Revit file (" + str(progressNumber) +
                       " of " + str(totalFilesCount) + ")" + " in Revit " +
                       RevitVersion.GetRevitVersionText(revitVersion) +
                       " session.")
            else:
                Output()
                Output("Processing Revit files (" + str(progressNumber) +
                       " to " + str(progressNumber + sessionFilesCount - 1) +
                       " of " + str(totalFilesCount) + ")" + " in Revit " +
                       RevitVersion.GetRevitVersionText(revitVersion) +
                       " session.")

            for supportedRevitFileInfo in sessionRevitFiles:
                batch_rvt_monitor_util.ShowSupportedRevitFileInfo(
                    supportedRevitFileInfo, Output)

            Output()
            Output("Starting Revit " +
                   RevitVersion.GetRevitVersionText(revitVersion) +
                   " session...")

            for index, supportedRevitFileInfo in enumerate(sessionRevitFiles):
                snapshotDataExportFolderPath = str.Empty
                revitFilePath = supportedRevitFileInfo.GetRevitFileInfo(
                ).GetFullPath()

                if batchRvtConfig.EnableDataExport:
                    snapshotDataExportFolderPath = snapshot_data_util.GetSnapshotFolderPath(
                        batchRvtConfig.DataExportFolderPath, revitFilePath,
                        batchRvtConfig.SessionStartTime)
                    path_util.CreateDirectory(snapshotDataExportFolderPath)
                    snapshotDataExportFolderPaths.append(
                        snapshotDataExportFolderPath)

                revitFilePath = supportedRevitFileInfo.GetRevitFileInfo(
                ).GetFullPath()
                scriptData = ScriptDataUtil.ScriptData()
                scriptData.SessionId.SetValue(batchRvtConfig.SessionId)
                scriptData.TaskScriptFilePath.SetValue(
                    batchRvtConfig.ScriptFilePath)
                scriptData.RevitFilePath.SetValue(revitFilePath)
                scriptData.TaskData.SetValue(batchRvtConfig.TaskData)
                scriptData.OpenInUI.SetValue(batchRvtConfig.OpenInUI)
                scriptData.EnableDataExport.SetValue(
                    batchRvtConfig.EnableDataExport)
                scriptData.SessionDataFolderPath.SetValue(
                    batchRvtConfig.SessionDataFolderPath)
                scriptData.DataExportFolderPath.SetValue(
                    snapshotDataExportFolderPath)
                scriptData.ShowMessageBoxOnTaskScriptError.SetValue(
                    batchRvtConfig.ShowMessageBoxOnTaskError)
                scriptData.RevitProcessingOption.SetValue(
                    batchRvtConfig.RevitProcessingOption)
                scriptData.CentralFileOpenOption.SetValue(
                    batchRvtConfig.CentralFileOpenOption)
                scriptData.DeleteLocalAfter.SetValue(
                    batchRvtConfig.DeleteLocalAfter)
                scriptData.DiscardWorksetsOnDetach.SetValue(
                    batchRvtConfig.DiscardWorksetsOnDetach)
                scriptData.ProgressNumber.SetValue(progressNumber + index)
                scriptData.ProgressMax.SetValue(totalFilesCount)
                scriptDatas.append(scriptData)

            batchRvtScriptsFolderPath = BatchRvt.GetBatchRvtScriptsFolderPath()

            while scriptDatas.Any():
                nextProgressNumber = batch_rvt_monitor_util.RunScriptedRevitSession(
                    revitVersion, batchRvtScriptsFolderPath,
                    batchRvtConfig.ScriptFilePath, scriptDatas, progressNumber,
                    batchRvtConfig.ProcessingTimeOutInMinutes,
                    batchRvtConfig.TestModeFolderPath, Output)

                if nextProgressNumber is None:
                    Output()
                    Output(
                        "WARNING: The Revit session failed to initialize properly! No Revit files were processed in this session!"
                    )
                    progressNumber += len(scriptDatas)
                    break
                else:
                    progressNumber = nextProgressNumber

                scriptDatas = (scriptDatas.Where(
                    lambda scriptData: scriptData.ProgressNumber.GetValue(
                    ) >= progressNumber).ToList())

                if batchRvtConfig.EnableDataExport:
                    Output()
                    Output("Consolidating snapshots data.")
                    for snapshotDataExportFolderPath in snapshotDataExportFolderPaths:
                        snapshot_data_util.ConsolidateSnapshotData(
                            snapshotDataExportFolderPath, Output)
                        # NOTE: Have disabled copying of journal files for now because if many files were processed
                        #       in the same Revit session, too many copies of a potentially large journal file
                        #       will be made. Consider modifying the logic so that the journal file is copied only
                        #       once per Revit seesion. Perhaps copy it to the BatchRvt session folder.
                        if False:
                            try:
                                snapshot_data_util.CopySnapshotRevitJournalFile(
                                    snapshotDataExportFolderPath, Output)
                            except Exception, e:
                                Output()
                                Output(
                                    "WARNING: failed to copy the Revit session's journal file to snapshot data folder:"
                                )
                                Output()
                                Output("\t" + snapshotDataExportFolderPath)
                                exception_util.LogOutputErrorDetails(e, Output)