Close Document Python Embedded Script

Dear All,

Im working on an existing shared script by @Ben_Osborne

Blockquote
Unload Revit Links - #3 by Ben_Osborne?

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?

@john_pierson
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

image

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
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.Attributes import*

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)


#Custom tolist definition provided by Dimitar Venkov
#https://github.com/dimven/SpringNodes
def tolist(x):
	if hasattr(x,'__iter__'): return x
	else : return [x]

doc = tolist(IN[0])

revitlinktypes=list()
revitlinktypes=[]

for d in doc:
	linkcollector=FilteredElementCollector(d).OfClass(RevitLinkInstance)

	TransactionManager.Instance.ForceCloseTransaction()
	for rli in linkcollector:
		rlt=doc.GetElement(rli.GetTypeId())
		revitlinktypes.append(rlt)
		rlt.Unload(None)
	

OUT= doc

used your script but the custom nodes return the result null

image

anything i did wrong?

snapshot from custom node

image

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