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
def HasCSVFileExtension(filePath): return path_util.HasFileExtension(filePath, CSV_FILE_EXTENSION)
def HasExcelFileExtension(filePath): return any( path_util.HasFileExtension(filePath, extension) for extension in [".xlsx", ".xls"])
def HasTextFileExtension(filePath): return path_util.HasFileExtension(filePath, TXT_FILE_EXTENSION)
def ConfigureBatchRvtSettings(batchRvtConfig, batchRvtSettings, output): aborted = False # General Task Script settings batchRvtConfig.ScriptFilePath = batchRvtSettings.TaskScriptFilePath.GetValue( ) batchRvtConfig.ShowMessageBoxOnTaskError = batchRvtSettings.ShowMessageBoxOnTaskScriptError.GetValue( ) batchRvtConfig.ProcessingTimeOutInMinutes = batchRvtSettings.ProcessingTimeOutInMinutes.GetValue( ) batchRvtConfig.ShowRevitProcessErrorMessages = batchRvtSettings.ShowRevitProcessErrorMessages.GetValue( ) # Revit File List settings batchRvtConfig.RevitFileListFilePath = batchRvtSettings.RevitFileListFilePath.GetValue( ) # Data Export settings batchRvtConfig.EnableDataExport = batchRvtSettings.EnableDataExport.GetValue( ) batchRvtConfig.DataExportFolderPath = batchRvtSettings.DataExportFolderPath.GetValue( ) # Pre-processing Script settings batchRvtConfig.ExecutePreProcessingScript = batchRvtSettings.ExecutePreProcessingScript.GetValue( ) batchRvtConfig.PreProcessingScriptFilePath = batchRvtSettings.PreProcessingScriptFilePath.GetValue( ) # Post-processing Script settings batchRvtConfig.ExecutePostProcessingScript = batchRvtSettings.ExecutePostProcessingScript.GetValue( ) batchRvtConfig.PostProcessingScriptFilePath = batchRvtSettings.PostProcessingScriptFilePath.GetValue( ) # Central File Processing settings batchRvtConfig.CentralFileOpenOption = batchRvtSettings.CentralFileOpenOption.GetValue( ) batchRvtConfig.DeleteLocalAfter = batchRvtSettings.DeleteLocalAfter.GetValue( ) batchRvtConfig.DiscardWorksetsOnDetach = batchRvtSettings.DiscardWorksetsOnDetach.GetValue( ) batchRvtConfig.WorksetConfigurationOption = batchRvtSettings.WorksetConfigurationOption.GetValue( ) # Revit Session settings batchRvtConfig.RevitSessionOption = batchRvtSettings.RevitSessionOption.GetValue( ) # Revit Processing settings batchRvtConfig.RevitProcessingOption = batchRvtSettings.RevitProcessingOption.GetValue( ) # Single Revit Task Processing settings batchRvtConfig.SingleRevitTaskRevitVersion = batchRvtSettings.SingleRevitTaskRevitVersion.GetValue( ) # Batch Revit File Processing settings batchRvtConfig.RevitFileProcessingOption = batchRvtSettings.RevitFileProcessingOption.GetValue( ) batchRvtConfig.IfNotAvailableUseMinimumAvailableRevitVersion = batchRvtSettings.IfNotAvailableUseMinimumAvailableRevitVersion.GetValue( ) batchRvtConfig.BatchRevitTaskRevitVersion = batchRvtSettings.BatchRevitTaskRevitVersion.GetValue( ) batchRvtConfig.AuditOnOpening = batchRvtSettings.AuditOnOpening.GetValue() batchRvtConfig.OpenInUI = batchRvtSettings.OpenInUI.GetValue() if not File.Exists(batchRvtConfig.ScriptFilePath): output() output("ERROR: No script file specified or script file not found.") aborted = True else: output() output("Task Script:") output() output("\t" + batchRvtConfig.ScriptFilePath) isDynamoTaskScript = path_util.HasFileExtension( batchRvtConfig.ScriptFilePath, script_util.DYNAMO_SCRIPT_FILE_EXTENSION) if isDynamoTaskScript: batchRvtConfig.OpenInUI = True # Always open and activate documents in the UI when executing a Dynamo task script. if isDynamoTaskScript: # Always use a separate Revit session for each Revit file when executing a Dynamo task script. # This restriction is due a limitation on closing documents that are active in the UI (which Dynamo requires). batchRvtConfig.RevitSessionOption = BatchRvt.RevitSessionOption.UseSeparateSessionPerFile if batchRvtConfig.ShowMessageBoxOnTaskError: output() output("Show Message Box on Task Script Error is enabled.") if batchRvtConfig.ProcessingTimeOutInMinutes > 0: output() output("Revit Task / File processing time-out setting:") output() output("\t" + str(batchRvtConfig.ProcessingTimeOutInMinutes) + " " + ("minute" if batchRvtConfig.ProcessingTimeOutInMinutes == 1 else "minutes")) revitProcessingModeDescription = ( "Batch Revit File processing" if batchRvtConfig.RevitProcessingOption == BatchRvt.RevitProcessingOption.BatchRevitFileProcessing else "Single Revit Task processing") output() output("Revit Processing mode:") output() output("\t" + revitProcessingModeDescription) if batchRvtConfig.EnableDataExport: if str.IsNullOrWhiteSpace(batchRvtConfig.DataExportFolderPath): output() output("ERROR: No data export folder specified.") aborted = True else: output() output("Data Export is enabled.") output() output("Data Export Folder:") output() output("\t" + batchRvtConfig.DataExportFolderPath) batchRvtConfig.SessionDataFolderPath = ( session_data_util.GetSessionFolderPath( batchRvtConfig.DataExportFolderPath, batchRvtConfig.SessionStartTime)) output() output("Session Folder:") output() output("\t" + batchRvtConfig.SessionDataFolderPath) if batchRvtConfig.ExecutePreProcessingScript: if not File.Exists(batchRvtConfig.PreProcessingScriptFilePath): output() output("ERROR: Pre-processing script file does not exist.") aborted = True else: output() output("Pre-Processing Script:") output() output("\t" + batchRvtConfig.PreProcessingScriptFilePath) if batchRvtConfig.ExecutePostProcessingScript: if not File.Exists(batchRvtConfig.PostProcessingScriptFilePath): output() output("ERROR: Post-processing script file does not exist.") aborted = True else: output() output("Post-Processing Script:") output() output("\t" + batchRvtConfig.PostProcessingScriptFilePath) if batchRvtConfig.RevitProcessingOption == BatchRvt.RevitProcessingOption.BatchRevitFileProcessing: centralFileProcessingDescription = ("Create New Local" if ( batchRvtConfig.CentralFileOpenOption == BatchRvt.CentralFileOpenOption.CreateNewLocal) else "Detach from Central") output() output("Central File Processing mode:") output() output("\t" + centralFileProcessingDescription) usingWorksetConfigurationOption = False if (batchRvtConfig.CentralFileOpenOption == BatchRvt.CentralFileOpenOption.CreateNewLocal): usingWorksetConfigurationOption = True if (batchRvtConfig.DeleteLocalAfter): output() output("\t" + "Local File will be deleted after processing.") elif (batchRvtConfig.CentralFileOpenOption == BatchRvt.CentralFileOpenOption.Detach): if (batchRvtConfig.DiscardWorksetsOnDetach): usingWorksetConfigurationOption = False output() output("\t" + "Worksets will be discarded upon detach.") else: usingWorksetConfigurationOption = True if usingWorksetConfigurationOption: worksetConfigurationOptionDescription = ( "Close All" if batchRvtConfig.WorksetConfigurationOption == BatchRvt.WorksetConfigurationOption.CloseAllWorksets else "Open All" if batchRvtConfig.WorksetConfigurationOption == BatchRvt.WorksetConfigurationOption.OpenAllWorksets else "Open Last Viewed") output() output("\t" + "Worksets Configuration: " + worksetConfigurationOptionDescription) if batchRvtConfig.AuditOnOpening: output() output("\t" + "Revit files will be audited on opening.") return aborted
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: