I am working on a script that will eventually be a “server” using RhinoInside with Python. Therefore, I have to use RhinoCommon methods. The program will hang out until asked to do something - then process some files and hang out some more. This will be in production and probably be running for months before the computer is restarted.
The issue that I have is that I need to really “cleanup” after one process is finished. There cannot be any objects or layers left over. The attached script is my failed attempt.
The first part removes all of the objects. Sort of. The document.Objects.Count returns the same number before and after deleting the objects but then reports zero when the next loop is run. I don’t understand why.
The second part tries to remove the layers, but I end up gaining a new layer after each run. Of course, that isn’t going work.
Can anyone point out the problems?
clearDocumentLoop.py (1.3 KB)
Here is the output from running the script:
================================================================================ Run 0
Before importing the file there are 0 objects
Trying to completely delete 206 objects
Now there are 206 objects
There are currently 7 layers in the document
[False] → Purging layer “Default” with index 0
[True] → Purging layer “Layer 01” with index 1
[True] → Purging layer “Layer 02” with index 2
[True] → Purging layer “Layer 03” with index 3
[True] → Purging layer “Layer 04” with index 4
[True] → Purging layer “Layer 05” with index 5
[True] → Purging layer “Target” with index 6
There are now 7 layers in the document
================================================================================ Run 1
Before importing the file there are 0 objects
Trying to completely delete 206 objects
Now there are 206 objects
There are currently 8 layers in the document
[False] → Purging layer “Default” with index 0
[False] → Purging layer “None” with index 1
[False] → Purging layer “None” with index 2
[False] → Purging layer “None” with index 3
[False] → Purging layer “None” with index 4
[False] → Purging layer “None” with index 5
[False] → Purging layer “None” with index 6
[True] → Purging layer “Target” with index 7
There are now 8 layers in the document
================================================================================ Run 2
Before importing the file there are 0 objects
Trying to completely delete 206 objects
Now there are 206 objects
There are currently 9 layers in the document
[False] → Purging layer “Default” with index 0
[False] → Purging layer “None” with index 1
[False] → Purging layer “None” with index 2
[False] → Purging layer “None” with index 3
[False] → Purging layer “None” with index 4
[False] → Purging layer “None” with index 5
[False] → Purging layer “None” with index 6
[False] → Purging layer “None” with index 7
[True] → Purging layer “Target” with index 8
There are now 9 layers in the document
================================================================================ Run 3
Before importing the file there are 0 objects
Trying to completely delete 206 objects
Now there are 206 objects
There are currently 10 layers in the document
[False] → Purging layer “Default” with index 0
[False] → Purging layer “None” with index 1
[False] → Purging layer “None” with index 2
[False] → Purging layer “None” with index 3
[False] → Purging layer “None” with index 4
[False] → Purging layer “None” with index 5
[False] → Purging layer “None” with index 6
[False] → Purging layer “None” with index 7
[False] → Purging layer “None” with index 8
[True] → Purging layer “Target” with index 9
There are now 10 layers in the document
================================================================================ Run 4
Before importing the file there are 0 objects
Trying to completely delete 206 objects
Now there are 206 objects
There are currently 11 layers in the document
[False] → Purging layer “Default” with index 0
[False] → Purging layer “None” with index 1
[False] → Purging layer “None” with index 2
[False] → Purging layer “None” with index 3
[False] → Purging layer “None” with index 4
[False] → Purging layer “None” with index 5
[False] → Purging layer “None” with index 6
[False] → Purging layer “None” with index 7
[False] → Purging layer “None” with index 8
[False] → Purging layer “None” with index 9
[True] → Purging layer “Target” with index 10
There are now 11 layers in the document
================================================================================ Run 5
Before importing the file there are 0 objects
Trying to completely delete 206 objects
Now there are 206 objects
There are currently 12 layers in the document
[False] → Purging layer “Default” with index 0
[False] → Purging layer “None” with index 1
[False] → Purging layer “None” with index 2
[False] → Purging layer “None” with index 3
[False] → Purging layer “None” with index 4
[False] → Purging layer “None” with index 5
[False] → Purging layer “None” with index 6
[False] → Purging layer “None” with index 7
[False] → Purging layer “None” with index 8
[False] → Purging layer “None” with index 9
[False] → Purging layer “None” with index 10
[True] → Purging layer “Target” with index 11
There are now 12 layers in the document
================================================================================ Run 6
Before importing the file there are 0 objects
Trying to completely delete 206 objects
Now there are 206 objects
There are currently 13 layers in the document
[False] → Purging layer “Default” with index 0
[False] → Purging layer “None” with index 1
[False] → Purging layer “None” with index 2
[False] → Purging layer “None” with index 3
[False] → Purging layer “None” with index 4
[False] → Purging layer “None” with index 5
[False] → Purging layer “None” with index 6
[False] → Purging layer “None” with index 7
[False] → Purging layer “None” with index 8
[False] → Purging layer “None” with index 9
[False] → Purging layer “None” with index 10
[False] → Purging layer “None” with index 11
[True] → Purging layer “Target” with index 12
There are now 13 layers in the document
================================================================================ Run 7
Before importing the file there are 0 objects
Trying to completely delete 206 objects
Now there are 206 objects
There are currently 14 layers in the document
[False] → Purging layer “Default” with index 0
[False] → Purging layer “None” with index 1
[False] → Purging layer “None” with index 2
[False] → Purging layer “None” with index 3
[False] → Purging layer “None” with index 4
[False] → Purging layer “None” with index 5
[False] → Purging layer “None” with index 6
[False] → Purging layer “None” with index 7
[False] → Purging layer “None” with index 8
[False] → Purging layer “None” with index 9
[False] → Purging layer “None” with index 10
[False] → Purging layer “None” with index 11
[False] → Purging layer “None” with index 12
[True] → Purging layer “Target” with index 13
There are now 14 layers in the document
================================================================================ Run 8
Before importing the file there are 0 objects
Trying to completely delete 206 objects
Now there are 206 objects
There are currently 15 layers in the document
[False] → Purging layer “Default” with index 0
[False] → Purging layer “None” with index 1
[False] → Purging layer “None” with index 2
[False] → Purging layer “None” with index 3
[False] → Purging layer “None” with index 4
[False] → Purging layer “None” with index 5
[False] → Purging layer “None” with index 6
[False] → Purging layer “None” with index 7
[False] → Purging layer “None” with index 8
[False] → Purging layer “None” with index 9
[False] → Purging layer “None” with index 10
[False] → Purging layer “None” with index 11
[False] → Purging layer “None” with index 12
[False] → Purging layer “None” with index 13
[True] → Purging layer “Target” with index 14
There are now 15 layers in the document
================================================================================ Run 9
Before importing the file there are 0 objects
Trying to completely delete 206 objects
Now there are 206 objects
There are currently 16 layers in the document
[False] → Purging layer “Default” with index 0
[False] → Purging layer “None” with index 1
[False] → Purging layer “None” with index 2
[False] → Purging layer “None” with index 3
[False] → Purging layer “None” with index 4
[False] → Purging layer “None” with index 5
[False] → Purging layer “None” with index 6
[False] → Purging layer “None” with index 7
[False] → Purging layer “None” with index 8
[False] → Purging layer “None” with index 9
[False] → Purging layer “None” with index 10
[False] → Purging layer “None” with index 11
[False] → Purging layer “None” with index 12
[False] → Purging layer “None” with index 13
[False] → Purging layer “None” with index 14
[True] → Purging layer “Target” with index 15
There are now 16 layers in the document