Script request: Switch indicator
Moderators: Víctor Paredes, Belgarath, slowtiger
Script request: Switch indicator
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?
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
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
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
-- 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
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!
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!

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.
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.
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
- Víctor Paredes
- Site Admin
- Posts: 5815
- Joined: Wed Jan 26, 2005 12:18 am
- Location: Barcelona/Chile
- Contact:
cool script
thanks Super8mm and Synth!

thanks Super8mm and Synth!






Moho co-owner
Previously Rigged animation supervisor: My father's dragon, Wolfwalkers & Star Wars Visions "Screecher's Reach"
My personal Youtube Channel
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.
Thanks Genete
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