Script request: Switch indicator

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
super8mm
Posts: 340
Joined: Sun Oct 12, 2008 11:22 pm

Script request: Switch indicator

Post 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?
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post 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
User avatar
super8mm
Posts: 340
Joined: Sun Oct 12, 2008 11:22 pm

Post 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
User avatar
super8mm
Posts: 340
Joined: Sun Oct 12, 2008 11:22 pm

Post by super8mm »

If you can Genete this would be an awesome script.
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post by Genete »

There is not script interface for the Note Layer. :(
Any other idea?
-G
User avatar
super8mm
Posts: 340
Joined: Sun Oct 12, 2008 11:22 pm

Post 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?
User avatar
super8mm
Posts: 340
Joined: Sun Oct 12, 2008 11:22 pm

Post 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:
User avatar
super8mm
Posts: 340
Joined: Sun Oct 12, 2008 11:22 pm

Post 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.
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post 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
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post 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
User avatar
Víctor Paredes
Site Admin
Posts: 5815
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Post by Víctor Paredes »

cool script :D
thanks Super8mm and Synth!
Image Image Image Image Image Image
Moho co-owner

Previously Rigged animation supervisor: My father's dragon, Wolfwalkers & Star Wars Visions "Screecher's Reach"
My personal Youtube Channel
User avatar
super8mm
Posts: 340
Joined: Sun Oct 12, 2008 11:22 pm

Post 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
Post Reply