Page 1 of 1
					
				LM.GUI Button call a function?
				Posted: Tue Aug 22, 2023 10:50 am
				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?  

 
			 
			
					
				Re: LM.GUI Button call a function?
				Posted: Tue Aug 22, 2023 1:58 pm
				by swingsoneto
				Maybe never mind the first question  

  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?
 
			 
			
					
				Re: LM.GUI Button call a function?
				Posted: Tue Aug 22, 2023 2:03 pm
				by Greenlaw
				swingsoneto wrote: ↑Tue Aug 22, 2023 1: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.
 
			 
			
					
				Re: LM.GUI Button call a function?
				Posted: Tue Aug 22, 2023 7:29 pm
				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.
 
			 
			
					
				Re: LM.GUI Button call a function?
				Posted: Tue Aug 22, 2023 7:41 pm
				by synthsin75
				SimplSam wrote: ↑Tue Aug 22, 2023 7:29 pm
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.
 
			 
			
					
				Re: LM.GUI Button call a function?
				Posted: Wed Aug 23, 2023 5:53 am
				by swingsoneto
				SimplSam wrote: ↑Tue Aug 22, 2023 7:29 pm
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!
 
			 
			
					
				Re: LM.GUI Button call a function?
				Posted: Wed Aug 23, 2023 5:56 am
				by swingsoneto
				Greenlaw wrote: ↑Tue Aug 22, 2023 2:03 pm
swingsoneto wrote: ↑Tue Aug 22, 2023 1: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?
 
			 
			
					
				Re: LM.GUI Button call a function?
				Posted: Wed Aug 23, 2023 9:37 am
				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.