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.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
How do we help with scripting docs and examples?
Moderators: Víctor Paredes, Belgarath, slowtiger
Re: How do we help with scripting docs and examples?
D.R. Greenlaw
Artist/Partner - Little Green Dog | Little Green Dog Channel on Vimeo | Greenlaw's Demo Reel 2020 Edtion
Artist/Partner - Little Green Dog | Little Green Dog Channel on Vimeo | Greenlaw's Demo Reel 2020 Edtion
- hayasidist
- Posts: 3526
- Joined: Wed Feb 16, 2011 8:12 pm
- Location: Kent, England
Re: How do we help with scripting docs and examples?
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#changesGreenlaw wrote: ↑Sun Jan 17, 2021 5:18 pmThanks! 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.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
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
Re: How do we help with scripting docs and examples?
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.)
D.R. Greenlaw
Artist/Partner - Little Green Dog | Little Green Dog Channel on Vimeo | Greenlaw's Demo Reel 2020 Edtion
Artist/Partner - Little Green Dog | Little Green Dog Channel on Vimeo | Greenlaw's Demo Reel 2020 Edtion
- strider2000
- Posts: 506
- Joined: Sat Mar 07, 2015 5:14 pm
- Contact:
Re: How do we help with scripting docs and examples?
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.
Here's how I'd start:
@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.
If someone's not very familiar with scripts at all, they can start with an intro video I make a long time ago.
- https://www.youtube.com/watch?v=0Pwa83G ... YL&index=1
- it's about 8 minutes long
- my playlist https://www.youtube.com/playlist?list=P ... SXddTOrGYL describes some scripts I've created
- I'm sure there may be better stuff out there, but I haven't looked for tutorials in a long time, so I haven't checked if other sources are available.
- I know Greenlaw is way past wanting that video Just sharing for any readers, completely new to scripts.
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.
- 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
@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.
Re: How do we help with scripting docs and examples?
@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!
D.R. Greenlaw
Artist/Partner - Little Green Dog | Little Green Dog Channel on Vimeo | Greenlaw's Demo Reel 2020 Edtion
Artist/Partner - Little Green Dog | Little Green Dog Channel on Vimeo | Greenlaw's Demo Reel 2020 Edtion
- hayasidist
- Posts: 3526
- Joined: Wed Feb 16, 2011 8:12 pm
- Location: Kent, England
Re: How do we help with scripting docs and examples?
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"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.
- strider2000
- Posts: 506
- Joined: Sat Mar 07, 2015 5:14 pm
- Contact:
Re: How do we help with scripting docs and examples?
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
Re: How do we help with scripting docs and examples?
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.
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.
D.R. Greenlaw
Artist/Partner - Little Green Dog | Little Green Dog Channel on Vimeo | Greenlaw's Demo Reel 2020 Edtion
Artist/Partner - Little Green Dog | Little Green Dog Channel on Vimeo | Greenlaw's Demo Reel 2020 Edtion
- strider2000
- Posts: 506
- Joined: Sat Mar 07, 2015 5:14 pm
- Contact:
Re: How do we help with scripting docs and examples?
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.
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.
Re: How do we help with scripting docs and examples?
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.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".
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.
D.R. Greenlaw
Artist/Partner - Little Green Dog | Little Green Dog Channel on Vimeo | Greenlaw's Demo Reel 2020 Edtion
Artist/Partner - Little Green Dog | Little Green Dog Channel on Vimeo | Greenlaw's Demo Reel 2020 Edtion