Good grief. I almost gave up!
What a nightmare. Anyway got the whole "undo" and "delete bones" issue resolved after physically banging my head against the computer for two days. Seriously. I banged my head against the computer until all the 1's and 0's lined up properly...
... I'm kidding.
I had a big problem with what I think is variable "scope" or table references. I have learned painfully, that tables are very tricky. Items in a lua table aren't really "stored" as distinct copies of a value. Only a reference is stored as a variable. A field in a table is just another variable. If you add the same variable in a field of two separate tables and change the value in one table the value of the other one changes. You see? The same variable reference was added to both tables. Changing one changes both...
... I did not know this thank you very much.
The fix was quite simple once I figured out the problem. I keep two copies of the bone list for groups: One for the current list, one for the undo. I just "copy" them back and forth as needed by tracing the delete bone and "undo" key command.
This is not a perfect solution yet. Still some bugs to work out. The undo command at the moment is still causing trouble. Variables aren't "reset" during an "undo" so I am limited to how far back you can go with it.
For instance:
Delete a bone. Move a bunch of bones around. Undo. The groups reset to before you deleted a bone but AS doesn't. AS is undoing the last movement of the bone. I will probably have to use some sort of "undo" flag. This would mean after deleting a bone you have to undo immediately or it won't work. Or if you delete and move bones you would have to undo all the way back to when you deleted the bone. Deleting a bone can effect nearly ALL the groups depending on the order of the bone list.
Also the "redo" menu command can't be used with bone groups. There is no key command for "redo" so no way to trace it in the script. Hopefully a future update would fix this.
I may be missing something of course. Point groups works fine with undo and redo and deletion of points even though technically it works the same way. The difference of course is that point groups are part of the application. Probably some "magic stuff" going on behind the scenes I don't have access to.
-vern