Opening & closing of multiple models in background while completing a set of tasks

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:

  1. Open(detach from central & Audit) model while preserve all workset
  2. Unload all type of links
  3. Save as new central to another location with same name
  4. 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 :slight_smile:

2 Likes

@Kulkul hey, sorry to disturb you but why is my post still hidden when my account is no longer on hold?

Thanks for getting back to me

@stillgotme Its on now :slight_smile:

Hey guys, any ideas?

hey guys, anyone know why i get this error “attribute ‘RevitLinkInstances’ of ‘Namespace#’ object is read-only” when i change the RevitLinkType to RevitLinkInstances in the collection line?

Well, i had solved my own issues. Thanks :slight_smile:

any thoughts on why this would happen?

1 Like

using the script above

@AdamHamilton try this instead
Detach_Unload_Save.dyn (13.8 KB)
If it still doesnt work then you will need to show me what is your input or what version of revit and dynamo you are using

2 Likes

trick is i dont want to detach…i want to Open Local - Sync - and saveas a central in new location

maybe you can start a new thread and link this post as reference since it is on different topic. then i will see what i can do to help you :slight_smile:

can any one suggest me script for opening a central file by closing all work sets, it will be quick.

Use orchid package node:

image

3 Likes

Capture

cant find the node in the package. Please suggest on the same.

The Orchid package does not use the standard Package Manager. Use the Read Me node to download and install it from the GitHub.

1 Like

Thanks Sean, I have downloaded the builds and installed it.

This package is good. But I want the file to open in my application for further checking.
I just want Revit file to open with the work sets closed, not discarded.
Please suggest some script or package for the same purpose.

Thanks.

I cant see packages in dynamo 2018 Revit. can some body please suggest me how to show this.

This script is fantastic! Could this be modified so that it closes all worksets before opening?

yes you can do that by including more opening option.