Automating Project Setup with Python

I started over. Found this forum post with a good answer by stillgotme. Code now opens, saveas, and closes with the desired options. Now I’m moving on to changing project parameter values.

Revised code is below:

#Node Inputs
template_docs = IN[0]
project_docs = IN[1]
params_to_modify = IN[2]
new_param_values = IN[3]

#Variables
output = []

open_options = OpenOptions()
open_options.Audit = False
open_options.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets

worksharing_options = WorksharingSaveAsOptions()
worksharing_options.SaveAsCentral = True

save_options = SaveAsOptions()
save_options.MaximumBackups = 50
save_options.SetWorksharingOptions(worksharing_options)
save_options.OverwriteExistingFile = True
save_options.Compact = True

report = []

TransactionManager.Instance.ForceCloseTransaction()    

if IN[0]:
	try:
		for template_path_str in template_docs:
			#Get the save file path/name that is associated with the current template path/name
			current_doc_index = template_docs.index(template_path_str)
			project_path_str = project_docs[current_doc_index]
			#Convert trings to model paths
			template_model_path = FilePath(template_path_str)
			project_model_path = FilePath(project_path_str)
			#Open file
			newdoc = app.OpenDocumentFile(template_model_path, open_options)

			#Update ProjectInfo parameter values
			

			#SaveAs and Close file
			newdoc.SaveAs(project_model_path, save_options)
			newdoc.Close(True)

	except Exception, e:
		report.append("Exception at Open/Save Level : " + str(e))
else:
	report.append("Please attach the list of template paths to the IN[0]")
1 Like