Edit freehand tool with saved settings?

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
Lukas
Posts: 1296
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Edit freehand tool with saved settings?

Post by Lukas »

Is it possible to edit the freehand tool like this: ...?

1. tool with settings set to: auto-fill=false, auto-stroke=true, auto-close=false (preferably also have it load the first brush in the brush menu)
2. tool with settings set to: auto-fill=true, auto-stroke=false, auto-close=true (and preferably set fill settings to 'soft edge 20')

I took a look at the code, and it looks like it should be easy (to set the auto-fill etc at least), but I really don't understand lua. (not yet)

I'd love to have these tools, because I need to access these settings all the time, and if they were tools I can shortcut them.

Any help is greatly appreciated! Thanks
User avatar
hayasidist
Posts: 3511
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Edit freehand tool with saved settings?

Post by hayasidist »

My thoughts on this - please feel free to diasagree or offer other ideas!

the first part - preset tool preferences - is pretty straightforward. The easy way (but not the most elegant) is simply to make a second copy of the tool script and do a global replace of LM_Freehand with (say) LM_Freehand2. Also you'll need to duplicate, reanme and mod the icon (lm_freehand.png to lm_freehand2.png) so you can tel them apart. Then you can set and store different start-up options to your heart's content. To make "permanent" changes to the default start-up options change the settings in LM_Freehand:ResetPrefs() and then reset the tool instance.

Line width is trickier because it looks as though the tool uses the default stroke width for new shapes [moho:NewShapeLineWidth() ], but to override this you have a couple of options: (quick and dirty) hardcode a line width instead of using the moho variable; or (tidier) add menu options to the LM_FreehandDialog to use the default or an input line width.

The more elegant way of selecting sets of presets would also be to mod this dialogue to have choices such as "save the settings as my profile A"; "use the seetings from my profile B" etc etc.
User avatar
Lukas
Posts: 1296
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Edit freehand tool with saved settings?

Post by Lukas »

hayasidist wrote:My thoughts on this - please feel free to diasagree or offer other ideas!

the first part - preset tool preferences - is pretty straightforward. The easy way (but not the most elegant) is simply to make a second copy of the tool script and do a global replace of LM_Freehand with (say) LM_Freehand2. Also you'll need to duplicate, reanme and mod the icon (lm_freehand.png to lm_freehand2.png) so you can tel them apart. Then you can set and store different start-up options to your heart's content.
Thanks this works great!!! Now I've got two tools who both remember their own settings. Cool! A 'freehand stroke' tool and a 'freehand fill' tool.
To make "permanent" changes to the default start-up options change the settings in LM_Freehand:ResetPrefs() and then reset the tool instance.
I can't get this to work. I put the settings in LM_Freehand:ResetPrefs(), what do you mean by "reset tool instance"?
If I change the settings for the Stroke tool to also do auto-fill, I'd like the auto-fill to be deselected again when I go to the tool again. Right now it remembers the change, so it's not actually a Stroke tool anymore...
Line width is trickier because it looks as though the tool uses the default stroke width for new shapes [moho:NewShapeLineWidth() ], but to override this you have a couple of options: (quick and dirty) hardcode a line width instead of using the moho variable; or (tidier) add menu options to the LM_FreehandDialog to use the default or an input line width.

The more elegant way of selecting sets of presets would also be to mod this dialogue to have choices such as "save the settings as my profile A"; "use the seetings from my profile B" etc etc.
Something for the future ;)
Right now quick and dirty is good enough for me, the animation style is quick and dirty too. (Even quicker if there'd be seperate stroke and fill freehand tools!!!)


Thanks!
User avatar
hayasidist
Posts: 3511
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Edit freehand tool with saved settings?

Post by hayasidist »

yes - tool option settings are preserved across invocations. whatever options you've selected are saved when the tool exits by xxx:SavePrefs(prefs); and loaded when the tool (re)starts by xxx:LoadPrefs(prefs). So to stop this, just comment out the options you don't want saved or loaded BUT/AND if you do this you'll need to change the settings in the UI routines (near the end of the script):

...
LM_Freehand.autoClose = false
LM_Freehand.autoFill = true
LM_Freehand.autoOutline = true
...

xxx:ResetPrefs() is the routine called when you click the tool icon in the top left of the screen and select "reset tool". This is what I meant by my idea about "reset" ... so ideally you'll the make values in xxx:ResetPrefs() consistent with the "first run" values in the UI
User avatar
Lukas
Posts: 1296
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Edit freehand tool with saved settings?

Post by Lukas »

That was a bit too dificult for me, but I just deleted the whole GUI part (as dirty as coding can be I guess)

The tools are perfect that way, thanks so much for your help Hayasidist!
User avatar
hayasidist
Posts: 3511
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Edit freehand tool with saved settings?

Post by hayasidist »

Lukas wrote:... I just deleted the whole GUI part (as dirty as coding can be I guess)
brutal but effective! glad to have been able to help.
User avatar
alanthebox
Posts: 214
Joined: Sat Feb 03, 2018 5:31 pm
Contact:

Re: Edit freehand tool with saved settings?

Post by alanthebox »

So glad I found this thread! It's awesome having a stroke-only tool/shortcut! My only question is (after duplicating and adjusting the lm_freehand.lua file), is it possible to have this tool appear in the "Draw" tools sidebar next to the original freehand tool, rather than appearing in the "Other" section?
User avatar
hayasidist
Posts: 3511
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Edit freehand tool with saved settings?

Post by hayasidist »

Find the tool list file in your custom content folder ...\Moho Pro\scripts\tool\_tool_list.txt COPY IT and save the copy somewhere safe …

then add a line for the filename (without the .lua) where you want it in the list e.g. the new line comes after the original freehand tool's line in the

group MOHO.Localize("/Tools/Group/Draw=Draw")

Code: Select all

tool	lm_freehand			...
tool	lm_freehand2			...
Save a copy of this edited file somewhere safe too -- it might get wiped out if you reinstall.
User avatar
alanthebox
Posts: 214
Joined: Sat Feb 03, 2018 5:31 pm
Contact:

Re: Edit freehand tool with saved settings?

Post by alanthebox »

Ahh, thanks for your help! I tried updating the tool list in the custom content folder but didn't see any change. Updating the tool list within the actual main installation directory did the trick, though!
Post Reply