Action Commander tool. Key commands for actions

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

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

synthsin75 wrote:Vern, you should be able to write the hotkey number by just appending it to the action name.
Good Grief!

Stop it dude! You're making me look bad! ;) It should be a piece of cake to get the hotkey from the name of the action, just put a "-" or "_" or a special symbol to designate it... that's brilliant. My brain was off in another universe, I never would have thought of that.

It's still going to be up to the user NOT to use say... "Q" as a hot key for an action on the mac... other wise they would quit AS unintentionally. ;) That won't be as much of a problem on PC because most commands use the CTRL key.

Thanks for the help Synth!
chucky wrote:and where's Genete , the slacker?
I think Genete is off using Synfig. ;)

As what's next, got to finish the copy/paste bones script. Now that I can get to the key interpolation I can make it perfect.

I already have many uses for it both personally and commercially. It will make rigging modifications much easier now. Save the animation out, load it into the modified rig file. It was all that changing of the key interpolation that was bugging the heck out of me.


-vern
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post by Genete »

I'm not really off AS, I'm on Synfig what is different. I don't know why but I have more inspiration using Synfig than AS, and inspiration is an invaluable animator resource. Once found don't let it go! :D
-G
User avatar
synthsin75
Posts: 10267
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Post by synthsin75 »

Great script Vern. I'm so thrilled to see my little bit of code in there. (Very little bit :wink: )

There's only one suggestion I would make. When you pull down the 'insert action' tab it says 'ctrl+#'. I had forgotten what the actual modifier key was. I would suggest it say, 'alt(cmd)+#'. (Or 'cmd(alt)+#', whichever you want to favor) Since ctrl doesn't work for either platform, it may be a bit more clear to the user. :wink:

I tried finding it myself, but you must have hidden it. And what is message string 3555? I didn't find it in the AS 'Strings' file.
User avatar
synthsin75
Posts: 10267
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Post by synthsin75 »

Stop it dude! You're making me look bad!
I seriously doubt I'm going to make you look bad anytime soon, Vern. :lol:
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

synthsin75 wrote:Great script Vern. I'm so thrilled to see my little bit of code in there. (Very little bit :wink: )

There's only one suggestion I would make. When you pull down the 'insert action' tab it says 'ctrl+#'. I had forgotten what the actual modifier key was. I would suggest it say, 'alt(cmd)+#'. (Or 'cmd(alt)+#', whichever you want to favor) Since ctrl doesn't work for either platform, it may be a bit more clear to the user. :wink:

I tried finding it myself, but you must have hidden it.
Keyboard shortcuts are built in to the menu widgets in the scripting interface. It is one of the options when defining the menu.

Code: Select all

self.menu:AddItem(v, kc, self.SELECTITEM + i)
v is a variable that holds the text label for the menu. kc is a number variable that defines the hotkey or shortcut key. You have to use the "ascii" keyboard value. In this case I start with "48" which is "1" on the keyboard and increment that in the loop by adding the loop value "i" to 48.

This puts in the correct key board shortcut. It is optional and I could just as well leave it out. self.SELECTITEM is the message code. It is a variable defined in AS that you use with custom tools so the message codes won't interfere with tools in AS put in by the programmer.

The problem with the stupid key commands it that they don't do anything at all. Apparently you are expected to "put them in" but use scripting to determine how they work.

There is no way to change "CTRL" to "ALT" with the built in key commands on the PC unless I hard code it in with the string value. This would make the script more tricky because then I'd have to strip out that hotkey reference before using it as an action. It's a bunch of extra wasted effort for no real gain.

I kind of forgot about that because it displays properly on the mac (CMD + number). The display of the hotkey is platform specific. The only solution would be to completely remove the hotkey display in the menu. I would hate to jump through hoops with strings when it works perfectly without it. Hopefully people will get the hang of it and remember it is "ALT" not "CTRL".

Obviously if I update this to use the key command in the action name all of this won't matter. I would eliminate the hotkey display and just use the action name.

I still don't know why CTRL doesn't work on the PC with the numbers. Very annoying. It could be the OS uses those commands and they are blocked somehow.
And what is message string 3555? I didn't find it in the AS 'Strings' file.
I have no idea. I don't quite understand it myself.... as long as it works I'm happy. ;)

-vern
User avatar
synthsin75
Posts: 10267
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Post by synthsin75 »

Ah, thanks for clearing that up. Where do I find that kind of info, or is it just stuff you learn poking around?

Yeah you have alt shown in every UI label, so it shouldn't be a big deal.
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Have you downloaded the Moho Scripting Reference from the sticky here in the scripting forum?

viewtopic.php?t=1031

That has everything. That is where I get all my information for scripting. I have the index page from that folder as a top link in FireFox. I usually have it open all the time for quick reference.

-vern
User avatar
synthsin75
Posts: 10267
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Post by synthsin75 »

Yeah I have that, I'm just not real good at finding things in it yet. Finally found the 'SELECTITEM' reference, but have no idea where to look for that 'kc'.
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

synthsin75 wrote:Yeah I have that, I'm just not real good at finding things in it yet. Finally found the 'SELECTITEM' reference, but have no idea where to look for that 'kc'.
I just made up "kc". It's a variable.

Code: Select all

		for i,v in pairs(aname) do
			local kc = 0
			if(i < 9) then
				kc = 48+i
			end
			self.menu:AddItem(v, kc, self.SELECTITEM + i)
		end

Half the stuff used in these scripts are just variables and coding conventions that were "made up" by someone.. uh... most likely it was Mike. They just sort of become a standard way of doing things.

For instance the variable "skel"... made up.

Code: Select all

local skel = moho:Skeleton()
I remember looking through the darn script reference searching for "skel". This was back when I knew very little about lua.

It's just an easier way to reference that long bit of code, "moho:Skeleton()". Creating short, easy to type, easy to remember variables that represent some long bit of code saves time and effort.

-vern
User avatar
synthsin75
Posts: 10267
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Post by synthsin75 »

Okay, I hadn't noticed where it was assigned, thanks.

Took me forever to figure out what 'i, v' stood for. Yeah, I'm far from contributing anything major, but at least I'm starting to understand this stuff. :wink:
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Another thing about the opening and reading of the AS file format for script use is to open the file to read it, but only advance one line at time.

For instance with the code you used for finding the actions... works perfectly. Scan all the lines in a loop, find the values and you're done.

However for my purposes I need to read in only the lines AFTER the bone name has been found (for save/load) I want to STOP the reading of lines at the point and advance through each line one at at time to find the key values.

So I will use the same thing I'm using in the load bone animation script.

The variable "fileToOpen" is opening the file represented by "path" and the "r" means it is read only.

Code: Select all

fileToOpen = io.open( path, "r" )
--------

Using the *a option would read in the whole file into the variable "hugeTextString". I now have a "copy" of the whole file in a really big string variable.

Code: Select all

hugeTextString = fileToOpen.file:read("*a")
------

Or I could use any of the other "file:read()" options:

*a - reads and returns the whole file.
*n - reads and returns the next number.
*l - reads the next line (default)
number - reads and returns exactly the number of characters represented by the number:
fileToOpen.file:read(5)

------

With no option this will read in the next line (same as *l) and assign it to "myData".

Code: Select all

myData = fileToOpen.file:read()
Or I could read in the next number in the current line:

Code: Select all

myData = fileToOpen.file:read("*n")
By using the *n I don't have to use any regex. It skips any spaces and reads the next number in the line.

------

Once I find the line in the AS file that represents the bone, I can keep reading line by line until I find "Keys". Then read those lines one at a time to get the key interpolation value.

Once one bone is done I can advance in a loop until I find the name of the NEXT bone and do it all again.

As you can see... this is why I loath parsing the file format. It isn't always easy. ;)

-vern
User avatar
synthsin75
Posts: 10267
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Post by synthsin75 »

Yeah I had read about the open modes, but wasn't sure how I'd use it. That's why I went with 'io.lines'.

I see what you're saying, but I think there is an easier way to find that interpolation. Do you really need to get it from each individual key, or would one, or even a small sample, be enough? I think most people would tend to use a single interpolation for their skeletons, but you may want it to cover any odd contingency.

I may work on this, even if just for the practice. What you discribe sounds very complicated. If that's the only way, I can see why you'd try to avoid it.

There just has to be a simpler way.

Wish me luck. :wink:
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

synthsin75 wrote:Do you really need to get it from each individual key, or would one, or even a small sample, be enough? I think most people would tend to use a single interpolation for their skeletons.
No, I want to save the actual key frame interpolation for every key. Many people leave frame 0 interpolation as the default value (smooth) and key frame 1 to start things off. Plus if you change keys later on as many people do how would they know which key interpolations are incorrect? My feeling is that just saving the first key interpolation is the same as not have any key interpolation saved.

Once the code works it's very very very fast. Lua can read strings like lightening. I will probably just read the whole file into a variable and strip it down like a stolen car for the data I need. ;)

-vern
User avatar
synthsin75
Posts: 10267
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Post by synthsin75 »

I will probably just read the whole file into a variable and strip it down like a stolen car for the data I need.
Ah, Vern's gritty world of AS scripting. Need some scripting mag wheels? Vern's your man. :lol:

Yeah, in that case I guess you have to do it that way.
Post Reply