doc.SaveAs method “The model could not be saved” exception

doc.SaveAs method “The model could not be saved” exception

p.kinczyk.859
Explorer Explorer
505 Views
2 Replies
Message 1 of 3

doc.SaveAs method “The model could not be saved” exception

p.kinczyk.859
Explorer
Explorer

Hi, i try to create "batch detached "for central files. But i have problem with “The model could not be saved” exception. I couldn’t find what cause the problem. Do you know how to go around this error? Here is my code:

 

 

import os

from Autodesk.Revit.UI.Selection import *
from Autodesk.Revit.DB import *
from pyrevit import forms
from pyrevit import output

## def / class


## Pick folder with models (input)

models_folder = forms.pick_folder(title="Pick folder where the models, to be detached, are")
print(models_folder)
models_folder_detached = forms.pick_folder(title="Pick folder where you want to save detached models")
models_paths =[]
for root, dirs, files in os.walk(models_folder):
	for revit_file in files:
		if ".rvt" in revit_file:
			models_paths.append(os.path.join(root, revit_file))
print(models_paths)

## Open doc options
open_options = OpenOptions()
open_options.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets
open_options.AllowOpeningLocalByWrongUser = True

## Save as doc options
worksharing_options = WorksharingSaveAsOptions()
worksharing_options.SaveAsCentral = True

save_as_options = SaveAsOptions()
save_as_options.SetWorksharingOptions(worksharing_options)
save_as_options.MaximumBackups = 1
save_as_options.OverwriteExistingFile = True




try:
	for revit_model in models_paths:
		try:
			print(revit_model)
			revit_model_path = ModelPathUtils.ConvertUserVisiblePathToModelPath(revit_model)
			
			doc_det = __revit__.Application.OpenDocumentFile(revit_model_path, open_options)	
			
			doc_det.SaveAs(models_folder_detached, save_as_options)
			doc_det.Close(False)
		except Exception as e:
			print(e)
except Exception as e:
	print(e)

 

Error: "The model could not be save: Acces denied" -> picture attached

Thank you for your help!

0 Likes
Accepted solutions (1)
506 Views
2 Replies
Replies (2)
Message 2 of 3

RPTHOMAS108
Mentor
Mentor
Accepted solution

Document.SaveAs requires a filename not a folder name.

 

models_folder_detached appears to be a folder.

0 Likes
Message 3 of 3

p.kinczyk.859
Explorer
Explorer

You are correct but i need to change file path format too.

try:
	models_folder_detached = models_folder_detached.replace("\\","\\\\")
	for revit_model in models_paths:
		
		try:
			
			print(revit_model)
			revit_model_path = ModelPathUtils.ConvertUserVisiblePathToModelPath(revit_model)
			doc_det = __revit__.Application.OpenDocumentFile(revit_model_path, open_options)	
			models_folder_detached_name = models_folder_detached+"\\"+str(doc_det.Title)+".rvt"
			print(models_folder_detached_name)
			doc_det.SaveAs(models_folder_detached_name, save_as_options)
			doc_det.Close(False)
		
		except Exception as e:
			print(e)
		
except Exception as e:
	print(e)
0 Likes