General technical questions about v3 Moi's API

 From:  Michael Gibson
8010.22 In reply to 8010.21 
Hi Marco, I'm glad that works for you. re: Scripts vs commands folder - when you put it into the script folder, that means the code is run as "instant script" which just executes your code and does nothing else. When you put it in the commands folder, it is run as a command which has various things done before the command is launched and also after the command is finished to clean up some various states.

Some of the stuff done before a command starts includes loading any associated UI from a companion .htm file, clearing any "selection transition" display, clearing "selection lock", preparing the undo manager, and recording the current geometry database revision number and current selection counter.

Some of the stuff done when a command ends includes clearing selection lock, hiding the "Calculating..." and "Calculation failed" UI, persisting control values from the controls in the UI, clearing the command UI, canceling any factories that were created in the command that were not committed, generating undo units if any geometry was created or removed during the command, and deactivating any command or command set buttons associated with that command.

So when you run as "instant script" instead of as a "command", none of those additional cleanup tasks are happening and that's why you see a difference in behavior from those. You would have to do all those cleanup things yourself if you wanted to get the exact same behavior. I'm not sure which exact thing is responsible for your particular case though. It's usually good to run things that generate or remove geometry as a command so they get undo units made for them though.

At some time in the future I might try to make some of these things happen for "instant script" as well, but it might be a bit tricky because it can be useful to run scripts that do focused tasks like adjusting the selection and you might want to have that script do that stuff while you are still running inside of an existing command.

- Michael