RhinoScript Undo reset file parameters

Hi all,
I am a beginner in Rhino script. I made a script that explode every block and groups in a 3dm file and copy all the area of all the surface in an excel file.
Then I would like my script to undo all the modification it did in the 3dm file.
I can do “undo” after the script but I would like this action to be in the script.
Do you have any solution to do that?
Best regards and thank you for your help.

If it was me, and I was just trying to get some data out of the file without modifying anything, I would try to do it “non-destructively” if possible. That is to say, avoid exploding blocks, groups etc. if you are going to want to keep them the way they were originally. Try to get the data without doing that.

At the very least, you can make a copy of the stuff and explode the copies, get your data and then delete the objects that resulted from the explosion. It’s fairly inefficient, but it leaves the file intact.

You should however be able to get inside a group with something like ObjectsByGroup(groupname) and then analyze the individual objects without affecting the group.

For block instances, it’s a bit more difficult, as the instances may have been transformed from the original block definition. In that case, I guess the simplest would still be to make a copy of the instance first, use ExplodeBlockInstance(instance_copy) to get the transformed objects, analyze them, then delete them.

–Mitch

Thank you for your answer.
That’s great idea. Still I’ve got a problem with that because in my excel table I have one column with the layer name and another column with the area for each surface.
The layer name is really important to identify the surface.
If I make a copy of every object of a file, and then I explode the groups and Blocks. How can I identify the copy object from the original one?

Nicolas

First, scripts (in fact everything in Rhino) rely on the concept of an object ID (GUID) to identify objects. Every object in a Rhino file has a unique GUID. When you copy an object, the copy has a different GUID from the original.

Next, when you make a copy of a Rhino object with something like CopyObject(obj), the copy has the same characteristics as the original - layer, color, etc… You could also get layer info from the original before copying and store it for later if you are not sure.

Last, blocks are a different animal. The block instance resides on one layer, but the objects inside the instance can reside on different layers. When you explode an instance, the result will go to the original object layer(s), not necessarily the layer the instance was on. So it depends on what layer info you want, if it’s the instance layer, you can get that before exploding, if it’s the object layer(s) you can get that after (but there may be multiple layers, depending on how you made the block originally).

HTH, --Mitch

Ok thank you.
This is pretty clear.
It would have been easier with a “undo” fonction. But if it does not exist, I’ll try to do it another way with the tips you gave me.