Close Document Python Embedded Script

Dear All,

Im working on an existing shared script by @Ben_Osborne

Unload Revit Links?

My question is, is there any script can be added to the exisitng script for the following functions?

After Unload>Save The File>Close Document

Ive tried to use the Ryhthm nodes and it seems to have an error.

Anyone can help? or perhaps point to the right direction? I’m lost
Need to upgrade hundreds of models from Revit 2016 to Revit 2018 but for smoother migration i need to unload all linked Revit in each individual file, hence i wanted to use dynamo+python for this exercise

Here are the dynamo definition file & custom node
UnloadAll.LinkedRevit.dyf (2.7 KB)
Unload Linked Files 2.0.dyn (6.1 KB)

What is the error you are receiving?

here is the error

Warning: One or more of the input types are not matching. Couldn’t find a version of CloseDocument that takes arguments of type (System.Object,bool)

What is the output of your python script? You need to provide the document to my node. This should be of object type Autodesk.Revit.DB.Document.

I just take @Ben_Osborne script and make a custom node


Yeah, that one doesn’t take the background opened file and it just returns a 0. Perhaps give this a try. It returns the document after committing the unload.

import clr
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.Attributes import*

import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

import Revit

#Custom tolist definition provided by Dimitar Venkov
def tolist(x):
	if hasattr(x,'__iter__'): return x
	else : return [x]

doc = tolist(IN[0])


for d in doc:

	for rli in linkcollector:

OUT= doc

used your script but the custom nodes return the result null


anything i did wrong?

snapshot from custom node


Try flattening the output of OpenDocumentFile.

Placed the flatten node but got this error.

This one should work. There isn’t any real reason to nest the Python in a custom node.

Unload Linked Files - Revised - Dynamo 2.0.dyn (9.4 KB)

1 Like

@john_pierson can you take snapshot of the custom node, my dyn setting has changed and the name is not the same anymore hence i could not read the dyn you edited

My dyn has no custom node though, it’s a python script.

1 Like

ah…i know why …im using dynamo 1.3

@john_pierson any idea how to open the dyf in 1.3 version?

Unfortunately you cannot as it is not backwards compatible. I saw your’s was named 2.0 and followed suit. I’m actually not using 2.0 myself either because of these kinds of things. Let me recreate.

eureka, i manage to recreate the script. opened it in 2.0 and replicate in 1.3.2.

thanks @john_pierson you are my dynamo godfather now

1 Like