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
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager

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

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

if isinstance(IN[0], list):
	files = IN[0]
else:
	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()
SaveOptions.SetWorksharingOptions(worksharingOptions)
tOptions = TransactWithCentralOptions()
rOptions = RelinquishOptions(False)

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

OUT = "Model has successfully been created"
1 Like