How do we help with scripting docs and examples?

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

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
Greenlaw
Posts: 9269
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: How do we help with scripting docs and examples?

Post by Greenlaw »

hayasidist wrote: Sun Jan 17, 2021 2:03 pm try this to take a walk through the basics of LUA: https://www.lua.org/pil/contents.html
Thanks! I had actually purchased the PDF copy of the current edition earlier in the day. Glad to hear I'm on the right track. Will take the time to explore your suggestions today. :)
User avatar
hayasidist
Posts: 3526
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: How do we help with scripting docs and examples?

Post by hayasidist »

Greenlaw wrote: Sun Jan 17, 2021 5:18 pm
hayasidist wrote: Sun Jan 17, 2021 2:03 pm try this to take a walk through the basics of LUA: https://www.lua.org/pil/contents.html
Thanks! I had actually purchased the PDF version of the book earlier in the day. Glad to hear I'm on the right track. Will make the time to explore your suggestions today. :)
I'll repeat the "Caution": you've probably got LUA 5.3 (or maybe 5.4??) in that book -- Moho currently uses 5.2 -- so what the "LUA manual" says might not work with Moho. The main enhancements in 5.3 are here: https://www.lua.org/manual/5.3/readme.html#changes

so best to avoid using them... a notable area that is now in 5.3 but has a Moho work-around (i.e. you'll need to use the Moho version not the new native LUA) for 5.2 are the bitwise functions MOHO.bit / setbit / clearbit / hasbit
User avatar
Greenlaw
Posts: 9269
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: How do we help with scripting docs and examples?

Post by Greenlaw »

You're right, I currently have 5.4.2 installed, and will make sure I'm using the 5.2 and matching reference before I go any deeper. (I should know better; ran into the same situation when taking a Python class at work.)
User avatar
strider2000
Posts: 506
Joined: Sat Mar 07, 2015 5:14 pm
Contact:

Re: How do we help with scripting docs and examples?

Post by strider2000 »

Just doing a little work on scripts today and thought about Greenlaw's questions on getting started.

If someone's not very familiar with scripts at all, they can start with an intro video I make a long time ago. Once you know that, I'd definitely go to http://mohoscripting.com. I ditto Wes' comments that it's the best reference, hands down. It's awesome. In fact it's a great place to start.

Here's how I'd start:
  • Go to the tools button and click on Create a new script.
  • Don't worry about all the checkboxes, just click on "Preview"
    • That will show you what a basic script looks like.
    • That will give you a context for understanding the script structure page Haysadist mentioned
    • You can even download the script template to start your own script.
    • As Haysadist pointed out, the script name needs to be globally unique. If it's not some other code may get run and you'll be very confused on what's going on.
  • Note that there is the button/menu and the tool tabs
    • You can compare the two to see the difference.
    • The main difference is that a tool tends to stay active, so you'll interact with the mouse.
  • Next, I'd browse the code snippets. They show examples of the kinds of things you'll do in Moho, not just unrelated lua.
  • Then I'd just browse around to understand the API (Application Programming Interface), ie the main stuff of the site.
    • When you do that, you'll eventually come across links of script examples.
    • They're on http://mohoscripts.com/, which is also totally awesome.
    • Like the main doc site, it allows you to actually view and download scripts.
From there, there's only two other things I think you need to know
  • ctrl-alt-shift-L - That's how you reload Moho after you make a script change
  • print("your own message here", myVariableHere) - You'll need this when you're debugging your scripts :)
Hope that helps. The really good thing about this approach is it's all targeted directly at Moho and if you follow the patterns there, you won't hit the > 5.2 problems :)

@Stan, given this thread, maybe it would be good to add a little getting started section, perhaps in the introduction or as a separate section. Just an idea.
Last edited by strider2000 on Tue Jan 19, 2021 3:21 pm, edited 1 time in total.
User avatar
Greenlaw
Posts: 9269
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: How do we help with scripting docs and examples?

Post by Greenlaw »

@Strider2000, I'll be sure to check out your videos. TBH, the scripting I've done is few and far between, so any refresher is helpful. Thanks for the other advice too!
User avatar
hayasidist
Posts: 3526
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: How do we help with scripting docs and examples?

Post by hayasidist »

strider2000 wrote: Sun Jan 17, 2021 11:10 pm ...given this thread, maybe it would be good to add a little getting started section, perhaps in the introduction or as a separate section. Just an idea.
I've expanded the "introduction" section to include the main points of my posts above... please let me know if you have comments / suggestions for improvement // spotted typos // or "that's just plain wrong"
User avatar
strider2000
Posts: 506
Joined: Sat Mar 07, 2015 5:14 pm
Contact:

Re: How do we help with scripting docs and examples?

Post by strider2000 »

Ok. I've finally uploaded my first scripts to http://mohoscripts.com/latest They consist of
  • a script to rename styles
  • a script to reassign styles
They both depend on a utility script that I also uploaded called msDialog. That just makes it easy to create simple dialogs. I've added youtube videos for each, but here are some older videos as well, before I knew how to make scripts available.
User avatar
Greenlaw
Posts: 9269
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: How do we help with scripting docs and examples?

Post by Greenlaw »

Oh, yeah! Thank you for creating this script. I've had to run through this procedure manually many times and it can get tedious.

I wish it was possible to simply change a style's ID from within the Styles window. Way back before I understood how Styles really worked, I thought it was name-based, which caused a lot of headaches for me when I was asked to animate scenes with hundreds of cats. I mistakenly thought, "Okay, so I'll just duplicate the Style and change name of it for each cat variant, and we're done". Of course, it turned out to be more complicated than that. Eventually, I figured out a system like what you described but I still had to rename a bunch of styles manually for each cat variant. It would be so much easier if I could just edit the Style ID directly, and then batch rename like your script does.

Come to think of it, can you add the ability to change the Style IDs in your script? It would be great to be able to enter my own ID but even a random ID generator (like what I assume the importer uses) would probably work fine. Just a thought.

Anyway, your script will definitely remove some of the tedium the next time I have to do this.

On a related topic, your video clearly demonstrates the need for a Styles manager window, as well as a Bones manager window and better Actions manager window. I think something like that is the logical next step in Moho's evolution.
User avatar
strider2000
Posts: 506
Joined: Sat Mar 07, 2015 5:14 pm
Contact:

Re: How do we help with scripting docs and examples?

Post by strider2000 »

Hi Greenlaw,
I hope the script helps :) I use them all the time. I'm not 100% clear on what you mean by " change a style's ID". I can think of several different interpretations. Of course, you're correct, that two styles can have the exact same name, but different IDs and thus are different styles. I don't know what actually tracks the fUUID, so I'd be very hesitant to just create one, unless there's a known fUUID generator. I think the exact workflow would be something people would need to know, in order to create the best tool.

For me, whenever I create a new character, I rename their styles, based on the character name. True they don't have unique IDs, but I just unlink shared styles when I import. If, for the cats, you're wanting to have just one character, but import it as various versions, I think it would be best to have a combination of my two scripts built into Moho's import. Namely, rename and reassign. I think the unlink is doing the reassign already. But right now it doesn't allow you to rename styles, so you get a mess of duplicate names :( If, when you unlink, it allows you to rename, or perhaps enumerate the styles then, importing "cat" would result in styles like "Fluffy cat" and "Tiger Cat", or "Butch" and "Sally" or "cat 1", "cat 2", cat 3".

I haven't played with FileImport, but that may be a possibility.
User avatar
Greenlaw
Posts: 9269
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: How do we help with scripting docs and examples?

Post by Greenlaw »

strider2000 wrote: Sat Jan 23, 2021 8:27 pm I hope the script helps :) I use them all the time. I'm not 100% clear on what you mean by " change a style's ID".
Oh, sure...I meant basically what happens to the Styles when you import a project and enable Unlinked Shared Styles. Before I understood what this did, I was looking for the ID in the project file in a text editor and changing it there...talk about tedious! I think it was Chucky who finally pointed this import option out to me. :)

But, I was wondering if the ID change could be made (optionally) at the same time when the styles are being renamed by your script. Then, when the file is saved to, say, the 'master' file, it could update any projects using that 'master' file as a rig reference. (I think. I'd have to go through the motions to be sure I'm not missing something here.) Anyway, just a thought.
Post Reply