Functions for entering and exiting a tool script

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
Breinmeester
Posts: 303
Joined: Thu May 13, 2010 2:01 pm

Functions for entering and exiting a tool script

Post 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?
User avatar
hayasidist
Posts: 3492
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Functions for entering and exiting a tool script

Post 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??
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Functions for entering and exiting a tool script

Post 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.
Breinmeester
Posts: 303
Joined: Thu May 13, 2010 2:01 pm

Re: Functions for entering and exiting a tool script

Post by Breinmeester »

Thanks, guys! I think i'll have to try a combination of your suggestions.
Post Reply