Page 1 of 1

Script request: Switch indicator

Posted: Thu Feb 18, 2010 6:56 pm
by super8mm
Is there such a thing as a script that indicates a switch's selection at a glance without having to right click on a switch layer?

Posted: Thu Feb 18, 2010 9:50 pm
by Genete
How do you think it would be the interface?
An embedded script should be the solution to continuously show the used layer in the switch...
Hmmm ... maybe a note layer with an embedded script that changes its label according to the layer selected in the switch layer, inside the switch layer?...
Hmmm I have to look to the scripting interface to see if it is possible :)

-G

Posted: Thu Feb 18, 2010 10:13 pm
by super8mm
Knowing next to nothing about script protocol on my own I came up with this bogus script:

-- Title: Switch indicator
-- Script type: Embedded file
-- Function: Indicate in the work area a particular switch's selection.
-- Method: If a note's layer name is equal to the name of a switch then
-- change the value of the note to indicate the switch's layer selection.

function Layerscript(moho)

local ownlayer= moho.layer
-- Check if layer is a note layer
if (ownlayer:Type() ~= note) then return end

-- Get name of note layer
local namenote = ownlayer:Name()

-- Check if other layers are switch type layer and have the same name

local tab
local namecheck= ownlayer:Name()
local switcheck= ownlayer:Type()

if ( (namecheck == namenote) and (switcheck == switch) ) then

-- If true then get the value of the switch
local switchselect = switch:Value()
local ownlayer= moho.layer
local note:Value() = switchselect


end -- end if
end -- function

Posted: Thu Feb 18, 2010 10:19 pm
by super8mm
If you can Genete this would be an awesome script.

Posted: Thu Feb 18, 2010 10:35 pm
by Genete
There is not script interface for the Note Layer. :(
Any other idea?
-G

Posted: Thu Feb 18, 2010 11:02 pm
by super8mm
Other idea, can a script change the name of a layer?

If so then Instead of changing the note's value can you change the note's layer name or any layer's name?

Posted: Fri Feb 19, 2010 1:32 am
by super8mm
I got it!

Set all layers in the switch that are unused to the following state:

render_only=true
Hide in rendering view checked

That way only the used layer isn't grayed out. That way you can see it when the switch is expanded. And it doesn't disappear unless you choose the switch layer but the switch layer hides it anyways if it's not chosen.

Changing that state must be available... it must! :shock:

Posted: Fri Feb 19, 2010 3:18 am
by super8mm
Synthsin75 did the coding just now and here it is:

http://www.mediafire.com/?myn12tmy4y1

1-Add a note layer and place it below the switch and its layers.
2-Embed the script in the switch layer, right click the switch layer >check embed script file >select the file switcheck.lua

Now the note layer's name indicates the switch's value.

Awesome!

Note:
It does cause some slowdown during playback just change the line

moho:UpdateUI()
to
-- moho:UpdateUI()

This will make playback faster but during editing you have to click on the note layer to see it change during non playback editing of the switch layers.

Posted: Fri Feb 19, 2010 7:16 am
by Genete
Coolio!
Didn't know how to change the note layer's label string!
Well, it is done. Sorry for not do it by my self. I was in my sleep time zone ;)

-G

Posted: Sun Feb 21, 2010 12:30 am
by Genete
As the script is so short, I full copy it here to avoid it is lost.

Code: Select all

-- **************************************************
-- Original idea by Super8mm coded by Synthsin75-- **************************************************

-- Embed this script in the switch layer.
-- Add a note layer below the switch and switch layers.
-- The note layer's name will change to switch's selection.


function LayerScript(moho)
    local name = moho.layer:Name()
    local switchval = moho:LayerAsSwitch(moho.layer):SwitchValues():GetValue(moho.frame)
    local group
    if (moho.layer:Parent() ~= nil) then
        group = moho.layer:Parent()
    else
        group = moho.document
    end
    for i=0, group:CountLayers()-1 do
        local layer = group:Layer(i)
        local below = i-1
        if (tostring(layer) == tostring(moho.layer)) and (group:Layer(below):LayerType() == MOHO.LT_NOTE) then
            group:Layer(below):SetName(switchval)
        end
    end
    moho:UpdateUI()
end

Posted: Mon Feb 22, 2010 5:45 pm
by VĂ­ctor Paredes
cool script :D
thanks Super8mm and Synth!

Posted: Mon Feb 22, 2010 6:08 pm
by super8mm
Optionally you may want to use this code if you are experiencing lag during playback. Downside is you won't be able to see the changed layer switch until you click on something else first.

Code: Select all

-- **************************************************
-- Original idea by Super8mm coded by Synthsin75--
 **************************************************

-- Embed this script in the switch layer.
-- Add a note layer below the switch and switch layers.
-- The note layer's name will change to switch's selection.


function LayerScript(moho)
    local name = moho.layer:Name()
    local switchval = moho:LayerAsSwitch(moho.layer):SwitchValues():GetValue(moho.frame)
    local group
    if (moho.layer:Parent() ~= nil) then
        group = moho.layer:Parent()
    else
        group = moho.document
    end
    for i=0, group:CountLayers()-1 do
        local layer = group:Layer(i)
        local below = i-1
        if (tostring(layer) == tostring(moho.layer)) and (group:Layer(below):LayerType() == MOHO.LT_NOTE) then
            group:Layer(below):SetName(switchval)
        end
    end
--  moho:UpdateUI()
end
Thanks Genete