Page 1 of 1

Functions for entering and exiting a tool script

Posted: Mon Jun 04, 2018 3:21 pm
by Breinmeester
I am modding the Transform Bone tool, adding some functionality and improving usability. I want to set some parameters upon entering the script (some stuff needs to be set up, like certain bones need to be detected and labeled) and i thought i'd use the Run function for that: function LM_TransformBone:Run(moho) but it doesn't seem to work. It looks like the whole function is ignored.

Is there a way to run a function as the first thing when a tool is selected? Likewise, is there a function that can be run upon exiting the tool script, so that i can tie up some loose ends?

Re: Functions for entering and exiting a tool script

Posted: Mon Jun 04, 2018 8:05 pm
by hayasidist
I don't know of a "formal" run once on entry / exit but ...

I think NonDragMouseMove(), DoLayout() and LoadPrefs() are each called once before the script proper gets going.

Also, I think SavePrefs() is called when the tool has come to a logical break - but I think the "end" of an input-driven script is more when you stop using it and choose something else - so it's possible that SavePrefs() might get called more often than you need.

Depending on exactly what you want to set-up / clean-up OnMouseDown() and OnMouseUp() might be just as useful??

Re: Functions for entering and exiting a tool script

Posted: Mon Jun 04, 2018 10:10 pm
by synthsin75
DoLayout() is always called first when a tool is selected, so that should work for your setup.

NonDragMouseMove() and LoadPrefs() are only called when Moho starts (or scripts are reloaded).
And SavePrefs() only runs when Moho exits (or scripts reloaded).

So you probably do need to do any cleanup in OnMouseUp(), like Paul suggests.

Re: Functions for entering and exiting a tool script

Posted: Tue Jun 05, 2018 11:56 am
by Breinmeester
Thanks, guys! I think i'll have to try a combination of your suggestions.