import clr import System clr.AddReference("System.Core") clr.ImportExtensions(System.Linq) clr.AddReference("RevitAPI") clr.AddReference("RevitAPIUI") from Autodesk.Revit.DB import * import revit_script_util from revit_script_util import Output from System.IO import Path import revit_dynamo_util import revit_file_util # This should point to your Dynamo task script (*.dyn) file. DYNAMO_SCRIPT_FILE_PATH = r"\\nas-01\3d-projects\00-Освоение\DYMANO\DYNAMO-Фадеев\Параметры_сборок\4_Обозначение-0.6.dyn" # Location to save the processed Revit files to. SAVE_FOLDER_PATH = r"\\nas-01\3d-projects\00-Освоение\DYMANO\DYNAMO-Фадеев\Журналы\211-ИНК-УКПГ2-КС\1\~Обработано" def SaveRevitFile(doc, originalRevitFilePath, saveFolderPath): # Save the Revit model / family file in the new location. revitFileName = Path.GetFileName(originalRevitFilePath) saveRevitFilePath = Path.Combine(saveFolderPath, revitFileName) if doc.IsWorkshared: # For workshared models. saveRevitModelPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(saveRevitFilePath) revit_file_util.SaveAsNewCentral( doc, saveRevitModelPath, True # NOTE: this means overwrite the existing file if it exists; set to False if this is not desired. ) revit_file_util.RelinquishAll(doc) # Need to relinquish ownership of worksets after saving as new Central file. else: # For non-workshared models and family files. revit_file_util.SaveAs( doc, saveRevitFilePath, True # NOTE: this means overwrite the existing file if it exists; set to False if this is not desired. ) return sessionId = revit_script_util.GetSessionId() uiapp = revit_script_util.GetUIApplication() # NOTE: these only make sense for batch Revit file processing mode. doc = revit_script_util.GetScriptDocument() revitFilePath = revit_script_util.GetRevitFilePath() projectFolderName = revit_script_util.GetProjectFolderName() Output() Output("Dynamo&Save script is running!") Output() Output("Saving as new Central...") # Save the Revit file to the destination folder. SaveRevitFile(doc, revitFilePath, SAVE_FOLDER_PATH) Output() Output("Saved to: " + str(doc.PathName)) Output() Output("Activating the document in the UI...") revit_file_util.OpenAndActivateDocumentFile(uiapp, doc.PathName) Output() Output("Executing Dynamo script...") # Execute the Dynamo script revit_dynamo_util.ExecuteDynamoScript(uiapp, DYNAMO_SCRIPT_FILE_PATH) Output() Output("Re-saving as Central...") # Re-save the Revit file as central (to the same save folder). SaveRevitFile(doc, doc.PathName, SAVE_FOLDER_PATH)