Batch Detatch & SaveAsCentral (Non-Editable Worksets)

amazing @jacob.small ! sync after save with relinquish all just did the trick

attached final script (with rationalized inputs)

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 *

clr.AddReference("System")
from System.Collections.Generic import List

# collect inputs
if isinstance(IN[0], list):
	files = IN[0]
	filenames = IN[2]
else:
	files = [IN[0]]
	filenames = [IN[2]]

newPath = IN[1]


#shortings and options
options = OpenOptions()
options.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets

worksharingOptions = WorksharingSaveAsOptions()
worksharingOptions.SaveAsCentral = True

SaveOptions = SaveAsOptions()
SaveOptions.SetWorksharingOptions(worksharingOptions)

tOptions = TransactWithCentralOptions()

rOptions = RelinquishOptions(False)
rOptions.StandardWorksets = True
rOptions.ViewWorksets = True
rOptions.FamilyWorksets = True
rOptions.UserWorksets = True
rOptions.CheckedOutElements = True

sOptions = SynchronizeWithCentralOptions()
sOptions.SetRelinquishOptions(rOptions)
sOptions.Compact = True
sOptions.SaveLocalBefore = True
sOptions.SaveLocalAfter = True

allPaths=[]

#run through all files
for file,filename in zip(files,filenames):
	
	#Detatch
	modelpath = FilePath(file)
	newdoc = app.OpenDocumentFile(modelpath,options)
	
	#CloseWorksets
	collector = FilteredWorksetCollector(newdoc).OfKind(WorksetKind.UserWorkset)
	
	#iDs = []	
	iDs = [c.Id for c in collector] #python list
	wsIds = List[WorksetId](iDs) #convert to icollection
	wsClose = WorksharingUtils.CheckoutWorksets(newdoc,wsIds)
	
	#Rename
	newfile = newPath +"\\"+ filename
				# + version + ".rvt"
				
	#SaveAsCentral
	newdoc.SaveAs(newfile,SaveOptions)
	newdoc.SynchronizeWithCentral(tOptions,sOptions)
	newdoc.Close(False)
	allPaths.append(newfile)

OUT =  allPaths

Kudos to @stillgotme and @brunocassol as the breadcrumb lead me to the excellent opening&closing of multiple models in background while completeing a set of tasks

3 Likes