Hi all, just start dynamo scripting not long ago. Any help is much appreciated.
I am trying to achieve a series of actions in sequence without opening the actual Revit model.
The actions are:
- Open(detach from central & Audit) model while preserve all workset
- Unload all type of links
- Save as new central to another location with same name
- Relinquish all attributes
I have a bulk of models that required for these actions to be done sequentially, opening 1 model at a time and complete the actions stated above.
I had manage to complete action 1,3 & 4 but could not have any luck with 2. Picture below is the graph that i had come up with from various custom packages and the python script was drafted up by me with multiple reference, awesome learning platform here, but it has a warning of
“Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
The iterator cannot proceed due to changes made to the Element table in Revit’s database (typically, This can be the result of an Element deletion).”
Below is the script
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Import python library
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import os
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Analysis import *
# Import Revit Nodes
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
tOptions = TransactWithCentralOptions()
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
if isinstance(IN[0], list):
file = IN[0]
filename = IN[2]
else:
file = [IN[0]]
filename = [IN[2]]
newpath = IN[1]
Unloadedlinks = []
newdocpath = []
booleans = list()
oOptions = OpenOptions()
oOptions.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets
oOptions.Audit = True
worksharingOptions = WorksharingSaveAsOptions()
worksharingOptions.SaveAsCentral = True
SaveOptions = SaveAsOptions()
SaveOptions.MaximumBackups = 50
SaveOptions.SetWorksharingOptions(worksharingOptions)
SaveOptions.OverwriteExistingFile = True
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
TransactionManager.Instance.ForceCloseTransaction()
try:
for files,filenames in zip(file,filename):
modelpath = FilePath(files)
newdoc = app.OpenDocumentFile(modelpath,oOptions)
newfilepath = newpath + "\\" + filenames
newdoc.SaveAs(newfilepath,SaveOptions)
links = FilteredElementCollector(newdoc).OfClass(Autodesk.Revit.DB.RevitLinkType)
for link in links:
linkelement = newdoc.GetElement(link.GetTypeId())
try:
linkelement.Unload(None)
booleans.append(True)
except:
booleans.append(False)
newdoc.SynchronizeWithCentral(tOptions,sOptions)
newdoc.Close(True)
Unloadedlinks.append(links)
newdocpath.append(newfilepath)
OUT=[newdocpath,Unloadedlinks,booleans]
except Exception,e:
OUT = str(e)
Thanks in advance