I plagiarized the python code in the save document node, and the open document code mentioned here:
to work with an array of documents and paths…
import clr
# Add references to RevitAPI and RevitServices
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
# Import necessary modules
from RevitServices.Persistence import DocumentManager
from Autodesk.Revit.DB import Document, ModelPathUtils, OpenOptions, DetachFromCentralOption, SaveAsOptions
# Input parameters
document_paths = IN[0] # List of document file paths
save_paths = IN[1] # List of target save paths
def open_and_save_documents(document_paths, save_paths):
result = []
for doc_path, save_path in zip(document_paths, save_paths):
# Open the document
doc = DocumentManager.Instance.CurrentDBDocument
app = doc.Application
model_path = ModelPathUtils.ConvertUserVisiblePathToModelPath(doc_path)
open_options = OpenOptions()
open_options.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets
doc_on_disk = app.OpenDocumentFile(model_path, open_options)
# Save the document
path_to_save = save_path # No extension added
save_options = SaveAsOptions()
save_options.OverwriteExistingFile = True
try:
doc_on_disk.SaveAs(path_to_save, save_options)
result.append((True, doc_on_disk))
except:
result.append((False, doc_on_disk))
return result
# Call the function to open and save documents
result = open_and_save_documents(document_paths, save_paths)
# Output the results
OUT = result