Detach Central Model and Save in New Location with New Name

Good afternoon all,

I’m hoping someone may be able to help provide some insight.

My goal is to be able to detach a “template” central model we have created, change the file name and then save it in a different location.

I was using the Clockwork Synchronize with Central along with the Save and Detached package to piece together a new python code.

I’ve gotten dynamo to find the central model, create a copy and even change the name, I know the SaveAs method requires 2 inputs so I’m not sure how to manipulate it to provide a directory name.

Any thoughts?


Please post your python code

1 Like
import clr
from Autodesk.DesignScript.Geometry import *
# Import DocumentManager and TransactionManager
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

# Import RevitAPI
import Autodesk
from Autodesk.Revit.DB import *

if isinstance(IN[0], list):
	files = IN[0]
	files = [IN[0]]

v = "R" + app.VersionNumber[2:]
jobnumber = IN[1]
projectname = IN[2]
newpath = IN[3]
options = OpenOptions()
options.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets

worksharingOptions = WorksharingSaveAsOptions()
worksharingOptions.SaveAsCentral = True

SaveOptions = SaveAsOptions()
tOptions = TransactWithCentralOptions()
rOptions = RelinquishOptions(False)

for file in files:
	modelpath = FilePath(file)
	newdoc = app.OpenDocumentFile(modelpath,options)
	newfile = file[:-42] + jobnumber + " " + projectname + " " + v + ".rvt"
	rOptions.StandardWorksets = True
	rOptions.ViewWorksets = True
	rOptions.FamilyWorksets = True
	rOptions.UserWorksets = True
	rOptions.CheckedOutElements = True
	sOptions = SynchronizeWithCentralOptions()
	sOptions.Compact = True
	newdoc.SynchronizeWithCentral(tOptions, sOptions)

OUT = "Model has successfully been created"