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.

Error Diagnosis - Model Clean Up

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?


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


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
Purge families not placed
Sequencing python nodes
Python generated warning to purge model being hidden behind Dynamo player
PostCommand Method?

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