Batch Upgrader (Detach From Central)

revit
python
dynamo

#21

@T_Pover How would i get it to detach from central. And the current graph will upgrade files and save them as the same name. I cant figure out how to detach it and save it as a different name.

Save as Upgrader.dyn (15.0 KB)


#22

Here’s code to detach from and save as a single file where IN[0] is the file location of the Revit file you want to copy:

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 *

modelpath = FilePath(IN[0])

options = OpenOptions()
options.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets

worksharingOptions = WorksharingSaveAsOptions()
worksharingOptions.SaveAsCentral = True

SaveOptions = SaveAsOptions()
SaveOptions.SetWorksharingOptions(worksharingOptions)

newdoc = app.OpenDocumentFile(modelpath,options)
newdoc.SaveAs(r'C:\Temp\Revit_temp\newmodel.rvt',SaveOptions)

OUT = 0

#23

@T_Pover Thank you! But How can i make it save in the same location with a different name? I would like to be able to open the first file in a directory, open it, detached from central, save as a different name, and then close the document. Then move onto the next file in the directory.

This script does everything i need but detach and add “v2017” to the back of the name. I just added the highlighted part to show you what text i wanted to add. i know their isnt an IN[4] in the python script.


#24

Alright, this should work:

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]]

version = "v" + app.VersionNumber

options = OpenOptions()
options.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets

worksharingOptions = WorksharingSaveAsOptions()
worksharingOptions.SaveAsCentral = True

SaveOptions = SaveAsOptions()
SaveOptions.SetWorksharingOptions(worksharingOptions)

for file in files:
	modelpath = FilePath(file)
	newdoc = app.OpenDocumentFile(modelpath,options)
	newfile = file[:-4] + version + ".rvt"
	newdoc.SaveAs(newfile,SaveOptions)
	newdoc.Close(False)

OUT = 0

#25

Ill try it out when i get back to my PC thank you!


#26

@T_Pover It didnt work this is what i got


#27

Are you sure you’re using a central model? The error says it isn’t workshared


#28

@T_Pover Its upgrading right now

if i change

newdoc.Close(False)

to

newdoc.Close(True)

Will it close it after it upgrades and saves?


#29

Yes that will close it, but also save it, seeing as it just did a Save As there’s no need for it to save it again, thus the False value instead of True.


#30

Is it possible to add a the function for going tough warnings/errors like:

  • Removing Demensions
  • Removing Parts
  • Things like these
  • Removing linked items or ignore missing liks

image

And after it is done with upgrading it will put out a log tot the source folder?

I’m new to this all (Dynamo) but looking forward to the possibilities.

Thx all.


#31

the SaveAs method only takes 2 inputs so how could you rename, and save in a different file location?

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`Preformatted text`