LM.GUI Button call a function?

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
swingsoneto
Posts: 26
Joined: Mon Feb 20, 2017 9:23 pm
Contact:

LM.GUI Button call a function?

Post by swingsoneto »

Hi all, I'm new to scripting in Lua and especially Moho. I'm not sure I understand yet, even after looking at some examples, of how to get a button in a SimpleDialog to call a function.

Some context: I'm trying to write a simple script (unless something like this exists already) to replace text in bone names or swap a bone name suffix from L <-> R. I've actually tried to repurpose the framework of an existing script (specifically Rename Smart Bone), but my code crashes Moho when I click OK. Could someone help me understand what happens after SimpleDialog:OnOk() is called? Is the rest of Run() executed? I'm trying to understand where to put my code block that iterates over bones and replaces text. Preferably, I'd like to have this in a function called by a dedicated button.

While I'm asking this question, I'm curious about something else - is there a way to send scripts to Moho for execution from an IDE? Or is the only option for script development to keep closing / re-opening Moho? :D
swingsoneto
Posts: 26
Joined: Mon Feb 20, 2017 9:23 pm
Contact:

Re: LM.GUI Button call a function?

Post by swingsoneto »

Maybe never mind the first question :D Think I'm finding my answers here - https://mohoscripting.com/script_structure

Still curious if there's a better method for script development than opening / closing Moho?
User avatar
Greenlaw
Posts: 9270
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: LM.GUI Button call a function?

Post by Greenlaw »

swingsoneto wrote: Tue Aug 22, 2023 9:58 pm Still curious if there's a better method for script development than opening / closing Moho?
Do you mean for loading/updating scripts? If so, Shift+Ctrl+Alt+L will do that.

Can't help with the other stuff, but hopefully, someone with a lot more scripting experience than I have will stop by shortly.
User avatar
SimplSam
Posts: 1048
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: LM.GUI Button call a function?

Post by SimplSam »

You can use the tool at: https://mohoscripting.com/new_script to help quickly generate script structures.

The SimpleDialog does return to Run after OK & Cancel - but you will need to use HandleMessage if you want to respond to any other button click. The tool above - creates all of that.

For IDE to Moho roundtrip - I use keyboard macros to Save Doc, Switch to Moho, Reload Moho (as shown by @Greenlaw), combined with an Elgato Stream Deck - but any keyboard macro tool should help.
Moho 14.1 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.1 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
User avatar
synthsin75
Posts: 9981
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: LM.GUI Button call a function?

Post by synthsin75 »

SimplSam wrote: Wed Aug 23, 2023 3:29 am For IDE to Moho roundtrip - I use keyboard macros to Save Doc, Switch to Moho, Reload Moho (as shown by @Greenlaw), combined with an Elgato Stream Deck - but any keyboard macro tool should help.
I don't know why I never thought to write a macro to do that. Probably save on me from miskeying reload scripts and crashing Moho....although that may be more about some of the hacks I use in several of my scripts.
swingsoneto
Posts: 26
Joined: Mon Feb 20, 2017 9:23 pm
Contact:

Re: LM.GUI Button call a function?

Post by swingsoneto »

SimplSam wrote: Wed Aug 23, 2023 3:29 am You can use the tool at: https://mohoscripting.com/new_script to help quickly generate script structures.

The SimpleDialog does return to Run after OK & Cancel - but you will need to use HandleMessage if you want to respond to any other button click. The tool above - creates all of that.

For IDE to Moho roundtrip - I use keyboard macros to Save Doc, Switch to Moho, Reload Moho (as shown by @Greenlaw), combined with an Elgato Stream Deck - but any keyboard macro tool should help.
Thank you! I just found that tool yesterday after posting this :) I noticed that the default HandleMessage function was responding to button clicks, so I was able to start piecing it together. That tool's super helpful. Thank you for the tip about macros, I'll look into that!
swingsoneto
Posts: 26
Joined: Mon Feb 20, 2017 9:23 pm
Contact:

Re: LM.GUI Button call a function?

Post by swingsoneto »

Greenlaw wrote: Tue Aug 22, 2023 10:03 pm
swingsoneto wrote: Tue Aug 22, 2023 9:58 pm Still curious if there's a better method for script development than opening / closing Moho?
Do you mean for loading/updating scripts? If so, Shift+Ctrl+Alt+L will do that.

Can't help with the other stuff, but hopefully, someone with a lot more scripting experience than I have will stop by shortly.
Oh, for real? I had no idea that was there; is that even a menu item anywhere, or is it just hidden away as a shortcut?
User avatar
Greenlaw
Posts: 9270
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: LM.GUI Button call a function?

Post by Greenlaw »

Hi,

It's a little hidden, I guess. Look at page 539 of the User Manual, under Main Window shortcuts:

Alt Shift Ctrl L - Reload Tools And Brushes.

I probably learned that from someone here in this forum years ago. Note that it changed briefly to something else during the 13.0 cycle, but reverted to Alt+Shift+Ctrl+L again with 13.5.

Hope this helps.
Post Reply