output() output("Deleting local file...") File.Delete(localFilePath) output() output("Local file deleted.") except Exception, e: output() output("WARNING: failed to delete the local file!") if enableDataExport: snapshotEndTime = time_util.GetDateTimeNow() snapshotData = snapshot_data_exporter.ExportSnapshotData( sessionId, centralFilePath, snapshotStartTime, snapshotEndTime, dataExportFolderPath, revitJournalFilePath, snapshotError) snapshot_data_util.ConsolidateSnapshotData( dataExportFolderPath, output) # Ensure aborted message is shown in the event of an exception. if aborted: output() output("Operation aborted.") if aborted: output() output("Operation aborted.") else: output() output("Operation completed.") return aborted
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)