Lua basics
Moderators: Víctor Paredes, Belgarath, slowtiger
- synthsin75
- Posts: 10280
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Mmm, looks like linear is actually "0" and smooth "1" even though smooth is listed first.
Thanks for the info. At least the interpolation looks easy enough to find. Pattern: %d+%s(%d)%s aught to capture it. Well except for needing to find that line. I read that "%bxy" is the pattern for matched characters defined by x & y. In the case of keys "[]"
But the file is pretty 'landmark' sparse around keys.
Damn, I just noticed that point motion even has the actions separated by point in the file. That would be nuts to find all that.
I would suggest for your bone scripts just reading one interpolation and assuming it to be used throughout.
Also, just noticed a problem with using that "moho.document:Path ()". On a new file it will complain about not having a path. I tried to do an 'if path == nil' but couldn't get it to work right.
Thanks for the info. At least the interpolation looks easy enough to find. Pattern: %d+%s(%d)%s aught to capture it. Well except for needing to find that line. I read that "%bxy" is the pattern for matched characters defined by x & y. In the case of keys "[]"
But the file is pretty 'landmark' sparse around keys.
Damn, I just noticed that point motion even has the actions separated by point in the file. That would be nuts to find all that.
I would suggest for your bone scripts just reading one interpolation and assuming it to be used throughout.
Also, just noticed a problem with using that "moho.document:Path ()". On a new file it will complain about not having a path. I tried to do an 'if path == nil' but couldn't get it to work right.
Oops! Fixed that error.
Here's what I did to fix it:
I first created an empty string variable thePath. Gave it the value of document:Path(). If there is no document path then thePath will == "". If it doesn't then we know we got a saved document.
-----
As for finding the bones... once again... that darn naming bones problem. If all the bones are named (which they SHOULD BE in my humble opinion.) then I can find the keys by the bone name and simple parse through that section using the "[]" and "keys" as my landmarks.
The problem arises with unnamed bones. If the bones are unnamed then I can't be sure of getting the corect bone. Bones in the AS file are not saved in any type of special order. Their order can change like the wind. 7 comes before 2, 9 turns into 4. Delete bone 5 and bone 9 becomes bone 8 etc etc etc. The only way to absolutely know you got the right bone is by name... a unique name that no other bone has. that is why naming bones is such a crucial aspect with scripting.
I think if I recall correctly my save/load bones script requires that all bones be named so I should be okay.
p.s. I'm testing a new feature for my bone renamer to use the ID number for the name of unnamed bones if you haven't named them.
-vern
Here's what I did to fix it:
Code: Select all
local thePath = ""
thePath = moho.document:Path()
if (thePath ~= "") then
... etc etc etc...
-----
As for finding the bones... once again... that darn naming bones problem. If all the bones are named (which they SHOULD BE in my humble opinion.) then I can find the keys by the bone name and simple parse through that section using the "[]" and "keys" as my landmarks.
The problem arises with unnamed bones. If the bones are unnamed then I can't be sure of getting the corect bone. Bones in the AS file are not saved in any type of special order. Their order can change like the wind. 7 comes before 2, 9 turns into 4. Delete bone 5 and bone 9 becomes bone 8 etc etc etc. The only way to absolutely know you got the right bone is by name... a unique name that no other bone has. that is why naming bones is such a crucial aspect with scripting.
I think if I recall correctly my save/load bones script requires that all bones be named so I should be okay.
p.s. I'm testing a new feature for my bone renamer to use the ID number for the name of unnamed bones if you haven't named them.
-vern
- synthsin75
- Posts: 10280
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Not sure yet Chucky. I have many ideas. With Vern's help I got that meshinstance working how I wanted. There are a lot of little things about some tools I'd like to change to.
I'd really like to figure out if there is any way to make Genete's 'sort shapes' script run better, since that is the only thing keeping his 3Drig script from being very useful. It'll probably be awhile before I can inderstand any of Genete's scripts though.
Vern, that would be great if your load/save script could call your bone renamer ( through like a check box ). I'd love if it'd just rename the bones by id or something.
I'd really like to figure out if there is any way to make Genete's 'sort shapes' script run better, since that is the only thing keeping his 3Drig script from being very useful. It'll probably be awhile before I can inderstand any of Genete's scripts though.

Vern, that would be great if your load/save script could call your bone renamer ( through like a check box ). I'd love if it'd just rename the bones by id or something.
- synthsin75
- Posts: 10280
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Okay, I've figured out my next scripting mission. I think this is possible, but it'll probably take me quite some time to figure it all out.
I can understand how some people may not feel comfortable with changing thing in their AS instalation folders. Tools must be added to the toollist.txt to use shortcuts, etc.
This will be more useful to newbies since most pros are use to adding tools and stuff.
I plan to start out by just making it possible to change the tool shortcuts from within AS. I can read in the tool list and write changes to it. I may need to figure out how to write a backup though, just in case.
If that much works, then I want to make it possible to add tool and menu scripts from within AS. I think it may even be possible to point it to the script you want to add, and automatically add it to the tool list as well.
Granted all this is going to be quite the undertaking for a scripting newbie like myself, but I think it will make handling scripts seem much more integrated.
Also I should be able to add an error checking for duplicated shortcut key, which you have to do yourself in the text file.
Wish me luck, I have a feeling I'm going to need it.
I can understand how some people may not feel comfortable with changing thing in their AS instalation folders. Tools must be added to the toollist.txt to use shortcuts, etc.
This will be more useful to newbies since most pros are use to adding tools and stuff.
I plan to start out by just making it possible to change the tool shortcuts from within AS. I can read in the tool list and write changes to it. I may need to figure out how to write a backup though, just in case.
If that much works, then I want to make it possible to add tool and menu scripts from within AS. I think it may even be possible to point it to the script you want to add, and automatically add it to the tool list as well.
Granted all this is going to be quite the undertaking for a scripting newbie like myself, but I think it will make handling scripts seem much more integrated.
Also I should be able to add an error checking for duplicated shortcut key, which you have to do yourself in the text file.
Wish me luck, I have a feeling I'm going to need it.

- synthsin75
- Posts: 10280
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Question...
Is there any easy way to get the AS installation folder path? I could assume a standard installation locale, but my own isn't standard (i.e. C:\Program Files\e frontier). I assume even this assumption would be trouble for a different OS.
God forbid I have to try to figure out a progressive replacement search for a valid path. I really hope there is an easy way to get this, like there is for the current document.
Is there any easy way to get the AS installation folder path? I could assume a standard installation locale, but my own isn't standard (i.e. C:\Program Files\e frontier). I assume even this assumption would be trouble for a different OS.
God forbid I have to try to figure out a progressive replacement search for a valid path. I really hope there is an easy way to get this, like there is for the current document.

I can't think of an easy way to do this but to get started why bother? Just have the user navigate to the file and open it. If later WE figure out a way to do this you can add it in.synthsin75 wrote:Question...
Is there any easy way to get the AS installation folder path? I could assume a standard installation locale, but my own isn't standard (i.e. C:\Program Files\e frontier). I assume even this assumption would be trouble for a different OS.
God forbid I have to try to figure out a progressive replacement search for a valid path. I really hope there is an easy way to get this, like there is for the current document.
Tools can have preferences that work the same each time AS is opened. So the path to the scripts folder could be saved after the user locates it that first time. Each time they open AS that path is loaded.
This should be a cool script and very easy to do really (easy is a relative term compared to other scripts like bone groups and save/load animtion). The _tool_list file is very structured and very simple. Tools themselves are PLAIN FREAKING TEXT, which means the user could even select a tool from one location and "copy" it to the tool folder.
I see this using a pop-up window interface. You could load all the tools from the list into scrolling "text lists" in groups for each type (vector, bones, layer etc.) Use the lists to add and remove items etc etc.
You can simply make a backup first before making edits. Just read it in and save it to file with a ".bak" extension. Your script could have button to read that in and load the defaults like a reset button.
I've gotten pretty good at designing pop up windows for AS. Found a few tricks from other scripters that streamline it a bit. I can help with that if you need it. Designing those popups can really twist your brain.
There is one big thing that might be an issue... permissions for copying and changing the application folder of AS. It could be that doing this from the AS script interface might cause trouble. A simple test first would be the best thing.
-vern
- synthsin75
- Posts: 10280
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Chucky, I think that the tool palette layout is hard coded to be vertical, so probably no changing that.
Good idea Vern. The user finds the path once and then it is loaded with the script from there on. I should have thought of that considering it was what I was doing with that first read script.
Yeah I though of the tool list because of its very structured format.
Yeah I'll have to test it thoroughly. Does "UpdateUI" work like ctrl-F5? Or can ctrl-F5 be keyed by a script? If I can't do either of these, I guess I'd need to add a 'ctrl-F5 to update hotkeys' UI alert.
And I'm sure I'll have plenty of questions about the pop-up menu/s.
Good idea Vern. The user finds the path once and then it is loaded with the script from there on. I should have thought of that considering it was what I was doing with that first read script.
Yeah I though of the tool list because of its very structured format.
Yeah I'll have to test it thoroughly. Does "UpdateUI" work like ctrl-F5? Or can ctrl-F5 be keyed by a script? If I can't do either of these, I guess I'd need to add a 'ctrl-F5 to update hotkeys' UI alert.
And I'm sure I'll have plenty of questions about the pop-up menu/s.

That's another possible cool feature.... maybe... if it's coded carefully.
Instead of having to use separate utility scripts for "fancy" stuff it could be possible to copy and paste utility code directly to the LM utility script. This could make things a lot simpler.
---
Synth, I don't think you can send the CTRL f5 command through a script. The update ui only refreshes things like key frame markers when you key a bone or vector. It doesn't reload the tools.
I don't see this as a problem either. Many programs require a complete restart to reload new tools and plugins; Photohsop, Flash, etc. You could tell the user to use CTRL f5 on their own, but it would be good to warn them this can cause a crash. I would prefer having them restart to avoid the negative connotations of potentially crashing AS.
-vern
Instead of having to use separate utility scripts for "fancy" stuff it could be possible to copy and paste utility code directly to the LM utility script. This could make things a lot simpler.
---
Synth, I don't think you can send the CTRL f5 command through a script. The update ui only refreshes things like key frame markers when you key a bone or vector. It doesn't reload the tools.
I don't see this as a problem either. Many programs require a complete restart to reload new tools and plugins; Photohsop, Flash, etc. You could tell the user to use CTRL f5 on their own, but it would be good to warn them this can cause a crash. I would prefer having them restart to avoid the negative connotations of potentially crashing AS.
-vern
- synthsin75
- Posts: 10280
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Thanks Genete, I hadn't thought about the utilities yet. I'll get to that. Right now I'm just working on changing the shortcuts.
I see your point Vern. I'll probably tell the user to use ctrl-F5 for the shortcut changes, but when I get it to do the rest, I'll probably take your advice and prompt the user to restart.
I have found out one interesting thing. You can append anything you want to the _tool_list.txt. It seems as long as it isn't the expected format AS just ignores it. So once the user sets the path for this script, that space would be open for use.
I see your point Vern. I'll probably tell the user to use ctrl-F5 for the shortcut changes, but when I get it to do the rest, I'll probably take your advice and prompt the user to restart.
I have found out one interesting thing. You can append anything you want to the _tool_list.txt. It seems as long as it isn't the expected format AS just ignores it. So once the user sets the path for this script, that space would be open for use.

I'd be careful with that. Just a warning. You wold be better off saving specific prefs for the tool using the "ScriptPrefs" class. You can store as much information as you want in the tool preferences. Basically you create variables that are named for the tool script and assign strings or values to those variables. As many as you need. When AS launches those prefs are loaded immediately.synthsin75 wrote: I have found out one interesting thing. You can append anything you want to the _tool_list.txt. It seems as long as it isn't the expected format AS just ignores it. So once the user sets the path for this script, that space would be open for use.
It would be PERFECT for this script idea. You could save all kinds of info in there like lists of tools and path to a "default download" folder where a user has downloaded other scripts.
The only question mark I see would be tool icons. I don't know if lua could copy and paste or move an image file to a new location. Maybe it can.
-vern
- synthsin75
- Posts: 10280
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Haven't come across ScriptPrefs yet, sounds like just the thing. Thanks. Yeah, I haven't done any testing with the images yet.
Idea: The lua console can at least access relative paths when printing lua errors. If I could figure out how to access these, like make each cause an error and somehow return those paths to an index
, then I could automatically find all of the script names in the 'Tools' folder.
I'm trying to figure out how to do most of this without a lot of user input so it seems like its integrated. The problem with this approach is that I don't know how to find the script names for one not already on the tool list.
As usual, I maybe making this a bit too hard. But I'll get there.
Idea: The lua console can at least access relative paths when printing lua errors. If I could figure out how to access these, like make each cause an error and somehow return those paths to an index

I'm trying to figure out how to do most of this without a lot of user input so it seems like its integrated. The problem with this approach is that I don't know how to find the script names for one not already on the tool list.
As usual, I maybe making this a bit too hard. But I'll get there.

- synthsin75
- Posts: 10280
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Something odd here.
Hotkeys test script
Works good so far, but if I uncomment the io.lines bit at the end, I lose the 'path' and first two lines of the 'read all'. I'm guessing that this is running into the automatic garbage collection of lua. But I may be missing something else.
Hotkeys test script
Works good so far, but if I uncomment the io.lines bit at the end, I lose the 'path' and first two lines of the 'read all'. I'm guessing that this is running into the automatic garbage collection of lua. But I may be missing something else.