Functions for entering and exiting a tool script

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

Moderators: Fahim, Distinct Sun, Víctor Paredes, erey, Belgarath, slowtiger

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

Functions for entering and exiting a tool script

Post by Breinmeester » Mon Jun 04, 2018 3:21 pm

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

Re: Functions for entering and exiting a tool script

Post by hayasidist » Mon Jun 04, 2018 8:05 pm

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: 7127
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Functions for entering and exiting a tool script

Post by synthsin75 » Mon Jun 04, 2018 10:10 pm

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: 294
Joined: Thu May 13, 2010 2:01 pm

Re: Functions for entering and exiting a tool script

Post by Breinmeester » Tue Jun 05, 2018 11:56 am

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