def Main(): aborted = False commandSettingsData = TryGetCommandSettingsData() batchRvtConfig = batch_rvt_config.ConfigureBatchRvt( commandSettingsData, Output) if batchRvtConfig is None: aborted = True else: if batchRvtConfig.EnableDataExport: path_util.CreateDirectory(batchRvtConfig.SessionDataFolderPath) session_data_exporter.ExportSessionData( batchRvtConfig.SessionId, batchRvtConfig.SessionStartTime, None, batchRvtConfig.SessionDataFolderPath, None) sessionError = None try: if batchRvtConfig.RevitProcessingOption == BatchRvt.RevitProcessingOption.BatchRevitFileProcessing: aborted = RunBatchRevitTasks(batchRvtConfig) else: aborted = RunSingleRevitTask(batchRvtConfig) except Exception, e: sessionError = exception_util.GetExceptionDetails(e) raise finally:
def InitializeLogging(logFolderPath, sessionStartTime): logFolderPath = logFolderPath if not str.IsNullOrWhiteSpace(logFolderPath) else BatchRvt.GetDataFolderPath() path_util.CreateDirectory(logFolderPath) logName = LOG_NAME + "_" + snapshot_data_util.GetSnapshotFolderName(sessionStartTime.ToLocalTime()) logging_util.InitializeLogging(logName, logFolderPath) logFilePath = logging_util.GetLogFilePath() return logFilePath
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)