Model cleanup - Open in background

Hi everyone

I’m creating a dynamo graph to clean up models. Short summary of what i’m trying to do:

Open file --> audit, detach, preserve worksets
Clean up file --> delete certain sheets, delete all views not on sheets, delete and unload CAD links.
Save file and close --> compact file, save as central, is workshared, relinquish.

The file opens fine, saves and closes as well. But none of the actions I have assigned is completed. If I however perform the actions on an open document they work fine. Can anybody help me resolve this issue?

I would also love to add the ability to purge the document in the process. Not just once, but until 0 elements is left. I have seen a couple post for this, but none that did the trick for me.

Any help is much appreciated.


Hi @klausvm,

All the transactions must be done in the open document in the background.
In the picture of your graph, you are currently trying to clean the current document.
I hope that makes sense.

1 Like

Almost worked like a charm. For some reason it leaves behind 1 of the sketch sheets…

Does anyone know how to implement a purge function? I’v tried with the one from the Orchid package (@erfajo), but it returns an error
“Warning: Document.Purge operation failed.
The managed object is not valid.”

I have also tried with this Python script:

how did you implement the node?

did you feed it with the proper input?

1 Like

Hi @erfajo

I got it working now. Didn’t connect it properly in the first place. It does however not completely purge the document, there are still some items left when I open the document afterwards.

there are several items you cant delete there must always be 1 view
always 1 floor
always 1 wall
and more

1 Like

Correct, this is a well-known issue… There is some problem in getting access to what can be purged. Therefore does the default value not include “materials”, for including this you need to add “true” value Document.Purge. This is written in the help for the node. But still it need to respect certain things due to the RevitAPI.

However, there is another purge node called PostCommand.Purge, this one will purge you document, but it must be used in a very specific way. This node do what you can do inside Revit.
You need to activate and run/re-run the graph until your have an idea that the document is purged. Then you need to de-activate the node. Hereafter can you verify that all is purged inside Revit. If you dont de-activate the node you will not be able to open the purge command inside Revit!
Therefore, if you want to use this node in combination with background open, you need to add the command the number of times you think is needed, and at the last node set the activate state to “false” before you close your document.

1 Like

Hi @klausvm,

Can you please let me know the name and package of the node you use here:



You can find this node in the Genius Loci package.



Thanks so much! This is a very useful package!

1 Like

Hi everyone.
This is a great script for processing multiple files in a background very fast thanks to @klausvm
I have used it in a similar way but I have been trying to delete All 3d view templates and no good solution yet.
I found a great python script that does it for you but in a current Revit document so pretty useless if needed to be used a part of this cleaning script.

I think this scripts is @Konrad_K_Sobon ( thank you so much for publishing - it works great!)
Anyone has any ideas how to adjust this script to be able to read another revit file ( I have very limited or no python skills and need this being resolved asap)

I cant seem to get this to work. Please ignore the 2 nulls. Even without them I get this error