Page 1 of 2
persistant pop-up
Posted: Tue Sep 01, 2009 10:32 pm
by arfa
My toolbar is getting kinda crowded. It would be cool if there was a preference option to make it 5 tools wide. Failing that...
This may be a bit of a wildcard but is it possible to have a tool button that launced a persisting pop-up with buttons for various other tools. I recall that there was an example of this on the status bar (to include the point/smooth) and a suggestion of such a pop-up for Rudiger's nudge tools.
1: is it possible?
2: is there anyone who might be interested in doing it?
3: or, anyone who might put together a sample pop-outline that I could play with and extend?
Posted: Wed Sep 02, 2009 6:17 am
by Rudiger
Sorry, but it's not currently possible. Heyvern, Stefman, and myself investigated the possibility of doing it in this thread
A lua greenhorn's question, but to no avail. The problem is that the scripting interface is not passed to the callback function when a button in a floating dialog is pressed.
The best you can do is have a tool with a bunch of button tools in its option bar.
Posted: Wed Sep 02, 2009 1:38 pm
by arfa
Oh well, such is life. At least good to know limits. Thanks. I found the other thread useful. I will study that in more detail.
tool with a bunch of button tools in its option bar
This sounds good enough for the job.
Are there any existing code snips that I could use to get started? BTW my lua is REALLY bad

Posted: Thu Sep 03, 2009 6:48 am
by Rudiger
Look for ImageButton in the lm_curvature.lua tool to get an example on how to use it. In the HandleMessage callback function you can run any tool or menu script you want with "<script_name>:Run(moho)". You could also use OnKeyDown callbacks to assign shortcuts in the tool script to run the same tool or menu scripts. This is how I'm integrating all of my nudge buttons into a single tool.
Posted: Thu Sep 03, 2009 1:26 pm
by arfa
I will give that a go. First glance doesn't give me much of a 'eureka' feeling

but I will play about.
Great to hear that you are still nudging your nudgees along. They are soooo useful. Thanks. I look forward to any new release.
Posted: Thu Sep 03, 2009 3:29 pm
by arfa
And here it is an hour later with my lua-learning-curve on the rise
My process was a follows (thinking to launch RB_grid):
Make a copy of lm_curvature.lua
rename it ak_butts
blanket replace all name instances
resist temptation to --rem obviously unnecessary code
go to: function ak_butts:DoLayout
add in (just before the 'end')
Code: Select all
self.grid = LM.GUI.ImageButton("ScriptResources/grid", MOHO.Localize("/Scripts/Tool/grid/grid=grid"), false, self.GRID)
layout:AddChild(self.grid)
Down to: function ak_butts:HandleMessage (and this is where I think I will need a little more hand-holding)
I added:
Code: Select all
elseif (msg == self.GRID) then
rb_grid:Run(moho)
if (mesh == nil) then
return
end
but am really unfamiliar with lua 'end' syntax - and much besides.
So, the script loads.
I get the extra icon on the top status bar
peak and smooth still both work but, onclicking my new butt
I get error: M_Mesh:Group - out of range
lua:206 ... nil value
I tried deleting that elseif block but...
etc. etc. and the fog is falling
gurgle and gasp

Posted: Thu Sep 03, 2009 4:31 pm
by Rudiger
In lua, you use an "end" to end a block, normally started by and "if ... then", "for ... do", "function blah () ...", and the like. If the ends don't balance with block statements then you'll get a syntax error, well at least with versions other than 6.0. With version 6.0 the script simply won't be loaded.
With regards to your specific error, it's hard to know without seeing all of the code. Is the error occurring in the rb_grid script or the ak_butts script. One thing, you might try is changing the "if (mesh == nil) then" to "if (rb_grid:IsEnabled()) then" and put it before the rb_grid:Run(moho) line.
Posted: Thu Sep 03, 2009 5:39 pm
by heyvern
I get error: M_Mesh:Group - out of range
lua:206 ... nil value
"206" is the line in the script where the error is located. "out of range" usually means you are trying to access an item in a lua "table" like a point or bone or group, that doesn't exist. If you have 10 point groups and you try to call "group 11" you will get an "out of range" error. It could be the "nil" value is causing the out of range error. Need to see more code.
-vern
Posted: Fri Sep 04, 2009 2:05 pm
by arfa
I bit the bullet and stripped lm_curvature back to what I feel is the minimum. All a bit groping in the dark as regards lua but now I get the top status bar with peak, smooth and grid buttons. P&S both still work. Clicking grid gives error:
"attempt to index global 'rb_grid' (a nil value)"
I wonder if this is because the script (rb_grid) is not loaded and now begin to question my basic start assumption and ask:
Is it actually possible to load a script remotely? some kind of include() or, do I need to set each tool's code within this (ak_butts) script? Ie. embed rb_grid within ak_butts?
Posted: Fri Sep 04, 2009 3:11 pm
by Rudiger
arfa wrote:I bit the bullet and stripped lm_curvature back to what I feel is the minimum. All a bit groping in the dark as regards lua but now I get the top status bar with peak, smooth and grid buttons. P&S both still work. Clicking grid gives error:
"attempt to index global 'rb_grid' (a nil value)"
I wonder if this is because the script (rb_grid) is not loaded and now begin to question my basic start assumption and ask:
Is it actually possible to load a script remotely? some kind of include() or, do I need to set each tool's code within this (ak_butts) script? Ie. embed rb_grid within ak_butts?
rb_grid should be automatically loaded and globally accessible as long as it doesn't have any syntax errors of its own. I'm pretty sure that Lua is case-sensitive so make sure it shouldn't be rb_Rrid, or RB_Grid, etc.
Posted: Fri Sep 04, 2009 3:14 pm
by heyvern
The tool MUST be loaded if you call it from another tool. And yes you have to add the same code to all the tools you want this in. I ran into that problem with a script myself for colorizing bones. The colorized bones only show up if every tool has the "extra code". Not fun.
When you use functions or variables from another tool you must call it the same way you would in the other tool script. Each tool creates a global variable "table" that holds all the "stuff" for it. To access those variables or functions in a tool you must call that function with the name of the tool the same way it is called in the tools script.
For example:
At the top of "lm_translate_points.lua" tool script is this code which creates a global variable "table" that holds all of the functions and variables used by that tool:
This global table of things can be accessed by ANY OTHER tool.
The code below is used in the lm_add_point.lua script:
Code: Select all
LM_TranslatePoints:OnMouseMoved(moho, mouseEvent)
It is calling the "OnMouseMoved" function of the TRANSLATE points tool. See how it is called? Using the same code that the OTHER tool uses. That is how it works.
Here the add points tool is using the SAME variable created in the TRANSLATE points tool. That is how that variable is used in multiple tools. They all use the same variable.
If you check the "auto weld" check box in one tool it is checked in the other tool and visa versa.
------------
Look at tools and scripts that come with AS. Learning lua is only HALF the story. You then have to learn the "extra bits" in Anime Studio. The stuff that is NOT specifically "lua" but part of AS. When I was learning lua that always threw me for a loop. I was looking for stuff that had nothing to do with lua but was actually specific to AS.
-vern
Posted: Fri Sep 04, 2009 6:03 pm
by arfa
BTW - I am just using rb_grid because it is a relatively small script. I imagine the principles would apply to all tool scripts.
>> rb_grid should be automatically loaded
This is what I figured but did think that it would be loaded as a tool (from script/tool) so would auto-create a toolbar '?' icon which kind of negates this exercise - clearing space on the toolbar

Is there another way it can be loaded as a script? Other than embedding the code within ak_butts?
So, here is the full code (much cut about). All it requires for testing is an icon in Resources/ScriptResources named rb_grid.*
Peak and smooth work fine (the code is embedded) but poor old rb_grid just does dooley squat.
Code: Select all
-- a status bar 'tool to group commonly used tools - eg. camera, draw, etc
ScriptName = "ak_butts"
ak_butts = {}
ak_butts.BASE_STR = 2070
function ak_butts:Name() return "Tool buttons" end
function ak_butts:Version() return "0.1" end
function ak_butts:Description()
return MOHO.Localize("Description=Click any tool") end
function ak_butts:Creator() return "Arfa - with guidance" end
function ak_butts:UILabel()
return(MOHO.Localize("/Scripts/Tool/Tools/Tools=Tool Buttons")) end
function ak_butts:IsEnabled(moho)
if (moho:CountPoints() > 0) then
return true end
return true end
ak_butts.PEAK = MOHO.MSG_BASE
ak_butts.SMOOTH = MOHO.MSG_BASE + 1
ak_butts.RB_GRID = MOHO.MSG_BASE + 2
function ak_butts:DoLayout(moho, layout)
self.peak = LM.GUI.ImageButton("ScriptResources/peak", MOHO.Localize("/Scripts/Tool/Peak/Peak=Peak"), false, self.PEAK)
layout:AddChild(self.peak)
self.smooth = LM.GUI.ImageButton("ScriptResources/smooth", MOHO.Localize("/Scripts/Tool/Peak/Smooth=Smooth"), false, self.SMOOTH)
layout:AddChild(self.smooth)
self.rb_grid = LM.GUI.ImageButton("ScriptResources/rb_grid", MOHO.Localize("/Scripts/Tool/rb_grid/rb_grid=Zgrid"), false, self.RB_GRID)
layout:AddChild(self.rb_grid)
end
function ak_butts:HandleMessage(moho, view, msg)
local mesh = moho:Mesh() if (mesh == nil) then
return end
if (msg == self.PEAK) then
local mesh = moho:Mesh() if (mesh == nil) then
return end
moho.document:PrepUndo(moho.layer)
moho.document:SetDirty()
for i = 0, mesh:CountPoints() - 1 do
local pt = mesh:Point(i)
if (pt.fSelected) then
pt:SetCurvature(MOHO.PEAKED, moho.layerFrame)
end end
moho:NewKeyframe(CHANNEL_CURVE)
elseif (msg == self.SMOOTH) then
local mesh = moho:Mesh() if (mesh == nil) then
return
end
moho.document:PrepUndo(moho.layer)
moho.document:SetDirty()
for i = 0, mesh:CountPoints() - 1 do
local pt = mesh:Point(i)
if (pt.fSelected) then
pt:SetCurvature(MOHO.SMOOTH, moho.layerFrame)
end end
moho:NewKeyframe(CHANNEL_CURVE)
elseif (msg == self.rb_grid) then
if (rb_grid:IsEnabled()) then
rb_grid:Run(moho)
return
end
end
end
One thought I had was building in a whole bunch of tools with a set of variables at the script top so that they could be toggled.
var rb_grid = yes
var rt_nuge = yes
var fa_magnet = no
etc.
Then set rb_grid as a function with a lead qualifier:
if (rb_grid_preference=='yes') {do the whole grid block of code}
I imagine lua has this capability.
ONCE I get the template cracked.
Posted: Fri Sep 04, 2009 6:41 pm
by Rudiger
Oh, OK. It looks like we were talking at cross purposes. I though you just wanted to run button tools from the option panel, not activate tools. Maybe rb_grid doesn't have a Run function since it's a tool script and not a button script, and this is why you are getting an error.
If that's the case, I think you may be onto something with the variables idea. You could have each top-panel button toggle a variable to switch to a particular tool. You would then need to create a whole bunch of wrapper functions to catch all of the events that all of the tools require, eg
Code: Select all
function ak_butts:OnMouseMoved(moho, MouseEvent)
if self.rb_grid_active then
rb_grid:OnMouseMoved(moho, MouseEvent)
elseif rt_nudge_active then
rt_Nudge:OnMouseMoved(moho, MouseEvent)
elseif fa_magnet_active then
fa_magnet:OnMouseMoved(moho, MouseEvent)
end
end
It would be a lot of work, but you could possibly write a Lua script outside of AnimeStudio to automate this task and build your ak_butts script automatically. You might also get a slight performance hit as the wrapper function has to be run as well as the callback function for every event.
Posted: Fri Sep 04, 2009 9:21 pm
by arfa
And so the plot thickens - although it is starting to feel a bit more like congealing porridge rather than a sweet vege soup.
"talking at cross purposes"... Ain't words the funniest thing ever invented?
Yes, I was hoping to be able to put as many things as possible on the option bar - not that I would necessarily use them all. I wasn't aware of the technical distinction between tools and buttons.
>> have each top-panel button toggle a variable to switch to a particular tool
Sounds good.
>> a lot of work, but...
But is a happy suggestive alt
>> possibly write a Lua script outside of AnimeStudio to automate this task
I code in PHP so figure I could do it there.
But (of the not so happy kind) I am more vague now about exactly how to proceed than before.
>> slight performance hit
Set up one or two and see how it works. If it gets too slow then... back to the coffee machine.
So, where to from here?
I suspect that it is not so easy - whichever way it is approached. I am happy to keep putsing about with this if I continue to be fed leads. Thanks for your input thus far.
Posted: Fri Sep 04, 2009 11:40 pm
by heyvern
I'm officially lost as to what you are trying to do.
-vern