Exemple #1
0
def RunBatchRevitTasks(batchRvtConfig):
    aborted = False

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

    if not aborted:
        supportedRevitFileList = GetSupportedRevitFiles(batchRvtConfig)
        if supportedRevitFileList is None:
            aborted = True

    if not aborted:
        supportedCount = len(supportedRevitFileList)
        if supportedCount == 0:
            Output()
            Output(
                "ERROR: All specified Revit Files are of an unsupported version or have an unsupported file path."
            )
            aborted = True

    if not aborted:
        Output()
        Output("Revit Files for processing (" + str(supportedCount) + "):")
        for supportedRevitFileInfo in supportedRevitFileList:
            batch_rvt_monitor_util.ShowSupportedRevitFileInfo(
                supportedRevitFileInfo, Output)

        if batchRvtConfig.EnableDataExport:
            session_data_exporter.ExportSessionFilesData(
                batchRvtConfig.SessionDataFolderPath, batchRvtConfig.SessionId,
                [
                    supportedRevitFileInfo.GetRevitFileInfo().GetFullPath()
                    for supportedRevitFileInfo in supportedRevitFileList
                ])

    if not aborted:
        Output()
        Output("Starting batch operation...")
        aborted = ProcessRevitFiles(batchRvtConfig, supportedRevitFileList)

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

    return aborted
Exemple #2
0
def GetSupportedRevitFiles(batchRvtConfig):
    supportedRevitFileList = None

    revitFileList = batchRvtConfig.ReadRevitFileList(Output)

    if revitFileList is not None:
        supportedRevitFileList = list(
            revit_file_list.SupportedRevitFileInfo(revitFilePath.Trim('"'))
            for revitFilePath in revitFileList)

        nonExistentRevitFileList = list(
            supportedRevitFileInfo
            for supportedRevitFileInfo in supportedRevitFileList
            if not RevitFileExists(supportedRevitFileInfo))

        supportedRevitFileList = list(
            supportedRevitFileInfo
            for supportedRevitFileInfo in supportedRevitFileList
            if RevitFileExists(supportedRevitFileInfo))

        unsupportedRevitFileList = list(
            supportedRevitFileInfo
            for supportedRevitFileInfo in supportedRevitFileList if
            not HasAllowedRevitVersion(batchRvtConfig, supportedRevitFileInfo))

        unsupportedRevitFilePathRevitFileList = list(
            supportedRevitFileInfo
            for supportedRevitFileInfo in supportedRevitFileList
            if (not HasSupportedRevitFilePath(supportedRevitFileInfo)))

        supportedRevitFileList = list(
            supportedRevitFileInfo
            for supportedRevitFileInfo in supportedRevitFileList
            if (RevitFileExists(supportedRevitFileInfo) and
                HasAllowedRevitVersion(batchRvtConfig, supportedRevitFileInfo)
                and HasSupportedRevitFilePath(supportedRevitFileInfo)
                )).OrderBy(lambda supportedRevitFileInfo: GetRevitFileSize(
                    supportedRevitFileInfo)).ToList()

        nonExistentCount = len(nonExistentRevitFileList)
        unsupportedCount = len(unsupportedRevitFileList)
        unsupportedRevitFilePathCount = len(
            unsupportedRevitFilePathRevitFileList)

        if nonExistentCount > 0:
            Output()
            Output("WARNING: The following Revit Files do not exist (" +
                   str(nonExistentCount) + "):")
            for supportedRevitFileInfo in nonExistentRevitFileList:
                batch_rvt_monitor_util.ShowSupportedRevitFileInfo(
                    supportedRevitFileInfo, Output)

        if unsupportedCount > 0:
            Output()
            Output(
                "WARNING: The following Revit Files are of an unsupported version ("
                + str(unsupportedCount) + "):")
            for supportedRevitFileInfo in unsupportedRevitFileList:
                batch_rvt_monitor_util.ShowSupportedRevitFileInfo(
                    supportedRevitFileInfo, Output)

        if unsupportedRevitFilePathCount > 0:
            Output()
            Output(
                "WARNING: The following Revit Files have an unsupported file path ("
                + str(unsupportedRevitFilePathCount) + "):")
            for supportedRevitFileInfo in unsupportedRevitFilePathRevitFileList:
                batch_rvt_monitor_util.ShowSupportedRevitFileInfo(
                    supportedRevitFileInfo, Output)

    return supportedRevitFileList
Exemple #3
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)
def GetSupportedRevitFiles(batchRvtConfig):
    supportedRevitFileList = None

    revitFileListData = batchRvtConfig.ReadRevitFileListData(Output)

    if revitFileListData is not None:
        supportedRevitFileList = list(
            revit_file_list.SupportedRevitFileInfo(revitFilePathData)
            for revitFilePathData in revitFileListData)

        nonExistentRevitFileList = list(
            supportedRevitFileInfo
            for supportedRevitFileInfo in supportedRevitFileList
            if (not supportedRevitFileInfo.IsCloudModel()
                and not RevitFileExists(supportedRevitFileInfo)))

        supportedRevitFileList = list(
            supportedRevitFileInfo
            for supportedRevitFileInfo in supportedRevitFileList
            if (supportedRevitFileInfo.IsCloudModel()
                or RevitFileExists(supportedRevitFileInfo)))

        unsupportedRevitFileList = list(
            supportedRevitFileInfo
            for supportedRevitFileInfo in supportedRevitFileList if
            not HasAllowedRevitVersion(batchRvtConfig, supportedRevitFileInfo))

        unsupportedRevitFilePathRevitFileList = list(
            supportedRevitFileInfo
            for supportedRevitFileInfo in supportedRevitFileList
            if (not supportedRevitFileInfo.IsCloudModel()
                and not HasSupportedRevitFilePath(supportedRevitFileInfo)))

        supportedRevitFileList = list(
            supportedRevitFileInfo
            for supportedRevitFileInfo in supportedRevitFileList
            if ((supportedRevitFileInfo.IsCloudModel()
                 or RevitFileExists(supportedRevitFileInfo)) and
                (HasAllowedRevitVersion(batchRvtConfig, supportedRevitFileInfo)
                 ) and (supportedRevitFileInfo.IsCloudModel()
                        or HasSupportedRevitFilePath(supportedRevitFileInfo)))
        ).OrderBy(lambda supportedRevitFileInfo: GetRevitFileSize(
            supportedRevitFileInfo) if not supportedRevitFileInfo.IsCloudModel(
            ) else System.Int64(0)  # dummy file size value for Cloud models
                  ).ToList()

        nonExistentCount = len(nonExistentRevitFileList)
        unsupportedCount = len(unsupportedRevitFileList)
        unsupportedRevitFilePathCount = len(
            unsupportedRevitFilePathRevitFileList)

        if nonExistentCount > 0:
            Output()
            Output("WARNING: The following Revit Files do not exist (" +
                   str(nonExistentCount) + "):")
            for supportedRevitFileInfo in nonExistentRevitFileList:
                batch_rvt_monitor_util.ShowSupportedRevitFileInfo(
                    supportedRevitFileInfo, Output)

        if unsupportedCount > 0:
            Output()
            Output(
                "WARNING: The following Revit Files are of an unsupported version ("
                + str(unsupportedCount) + "):")
            for supportedRevitFileInfo in unsupportedRevitFileList:
                batch_rvt_monitor_util.ShowSupportedRevitFileInfo(
                    supportedRevitFileInfo, Output)

        if unsupportedRevitFilePathCount > 0:
            Output()
            Output(
                "WARNING: The following Revit Files have an unsupported file path ("
                + str(unsupportedRevitFilePathCount) + "):")
            for supportedRevitFileInfo in unsupportedRevitFilePathRevitFileList:
                batch_rvt_monitor_util.ShowSupportedRevitFileInfo(
                    supportedRevitFileInfo, Output)

    return supportedRevitFileList