Document.PurgeUnused node equivalent in API

Hi, I found this OOTB node in Dynamo, but I can’t seem to find the API equivalent.

Does anyone know how to achieve purging unused elements using the API? I did some searches on the forum, which turned up that it can only be done using a postable command. But then, how does this node achieve it? The goal is to use it with multiple documents open in the background.

Hello… think Genius Loci have a node there purge and use API…if i remember right :wink:

1 Like

Ah true! For some reason I didn’t think to look at it. Seeing that there was an OOTB node already, I assumed there would be a method in the API :grinning_face_with_smiling_eyes:

So I see that Genius Loci node basically recreates the whole purge unused logic, which is what you have to do I guess when the API doesn’t give you the ready made tools for it.

Thanks!

1 Like

Yes an amazing node :wink:

1 Like

I used the node to clear all unused things, Problem:
‘Additional number of Imported Categories’ to purge does not clear with the node.
Users would need to open it once again, only to click once on OK again.
I find that a bit inefficient.
See screenshot below:

yeah probably as in ui itself :wink: need run twice :wink: anyway you could try do that in dynam0 itself with run the same node with a transaction between, havent tried but could probably work

1 Like

How would you add a transaction inbetween? Short Phyton Script?

no just with ootb transaction nodes, but not sure it could work, not a dyn in moment but will try later

1 Like

This is my current script, if it helps you speed up things:
purge unused_shared.dyn (19.4 KB)

There is this set of code that may be useful, and may help towards what you want

2 Likes

It’s gotten way better, but even after letting the skript run twice, it sadly doesn’t remove it all:
Well, 1 click instead of 4.
image

The full code of purge elements is available here: DynamoRevit/src/Libraries/RevitNodes/Application/Document.cs at 1dbcf80e9d5580b58becf48e412408f779674e7b · DynamoDS/DynamoRevit · GitHub

Note that categories might not be caught by the performance advisor rule that finds the purgeable elements, but my gut says that wiring the first of these into a Transaction.End and then into a Transaction.Start and then into a second purge, end, start and a 3rd purge should do the trick.

That said categories are not something I would stress over as they aren’t going to impact things too much, doubly so if you’re managing them in your templates (if you’re not that’s a bigger issue than the purge tool not getting rid of them).

2 Likes