Script for switching multiple switches simultaneously

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

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
hayasidist
Posts: 3492
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Script for switching multiple switches simultaneously

Post by hayasidist »

ok
so...

Code: Select all

function Script(moho)

-- are we a switch layer on frame 0? N: abort

-- find a child .MASTER [?find first only?? check all and report error if >1??] [or assume first child is MASTER??] [or active child is MASTER?]

-- for each layer in .MASTER [i.e. every layer, irrespective of depth -- or will immediate children be OK?]
-- 	[or would it be better if just some (relevant) layers in MASTER are identified as "controlling" layers]
--	for each child of switch that is not .MASTER [aka slave child] [assume slave if not MASTER]
--		for each layer in slave child [again - all layers or just immediate child layers?]
--			if slave child layer name == .MASTER layer name
--				set slave child layer visibility to that of .MASTER
-- end if; end for; end for; end for
end 
((If that's the right idea then I'd be seriously tempted to make that a button script rather than a layer script since it's set-up only))
chucky
Posts: 4650
Joined: Sun Jan 28, 2007 4:24 am

Re: Script for switching multiple switches simultaneously

Post by chucky »

Ha ! that looks awesome!
I always prefer a button to embedding, so if you think it'll work then that would be so good.
So the recipe , could it be as simple as , toggle invisibility of all named the same as selected, inside the Master?
User avatar
hayasidist
Posts: 3492
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Script for switching multiple switches simultaneously

Post by hayasidist »

chucky wrote:...So the recipe , could it be as simple as , toggle invisibility of all named the same as selected, inside the Master?
that suggests that you'd select a layer in master (e.g. thin lips) - set its visibility and run a script to set all others of the same name --- so you'd need to run this as many times as you have different layers - but yes could be.
Stan
Posts: 199
Joined: Sun Apr 19, 2009 3:22 pm

Re: Script for switching multiple switches simultaneously

Post by Stan »

Just an idea. You can have a tool script that will have some functionality running within the IsRelevant or IsEnabled method - that will run automatically every time something changes in the Layers panel. You can also have a checkbox (i.e. a boolean) in the tool's panel to turn that functionality on and off.
________________________________________________________________________
https://mohoscripting.com/ - Unofficial Moho Lua scripting documentation
https://mohoscripts.com/ - The best place to publish and download scripts for Moho
User avatar
hayasidist
Posts: 3492
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Script for switching multiple switches simultaneously

Post by hayasidist »

We've got a beta doing some behind the scenes iterations right now -- should be fit for public consumption in the next couple of days.

Just to whet the appetite: This is designed for use in set-up where the same structure has many options from which a one-time choice is made at set-up (e.g. same phoneme switch for many mouths - all the phonemes have all the mouth shapes - but only one is to be visible).

-- there's one "leader" switch child (per main option) and this holds things that have their visibility _manually_ toggled on or off
-- all the other switch children get their copy of the things made visible / invisible at the click of a tool button (or the execution of a menu item)
Stan wrote:Just an idea. You can have a tool script that will have some functionality running within the IsRelevant or IsEnabled method ...


Now that is an interesting use of those routines! Hmmm ... cogs whirr ...
User avatar
synthsin75
Posts: 9935
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Script for switching multiple switches simultaneously

Post by synthsin75 »

hayasidist wrote:
Stan wrote:Just an idea. You can have a tool script that will have some functionality running within the IsRelevant or IsEnabled method ...


Now that is an interesting use of those routines! Hmmm ... cogs whirr ...
Yeah, I've used those for my auto-save script. These are called whenever you enter/leave frame zero, change a tool, change a layer, and maybe a few other things.
chucky
Posts: 4650
Joined: Sun Jan 28, 2007 4:24 am

Re: Script for switching multiple switches simultaneously

Post by chucky »

Well, I can vouch for Paul's beta so for. It does an amazing job and has already saved me a lot of time and effort, Also my file is so much neater now. I can also make changes and additions without it getting bogged down with duplicates, references and all the malarkey.
Thanks hayasidist :D
User avatar
hayasidist
Posts: 3492
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Script for switching multiple switches simultaneously

Post by hayasidist »

here it is: https://www.mediafire.com/file/uxu0vb95 ... Switch.zip

The zip file contains:
- the script .lua file
- an icon .png file
- an example .moho file (created in moho 12.3)
- readme.txt

Installation - you can put the .lua as a menu item (e.g. the <custom folder>\scripts\menu\Visibility) or along with its icon in the tool folder <custom folder>\scripts\tool

Note that this is a "set-up" script not an animation script.

any bugs etc - please say!!

[edit] this is now V2.00

activate on any group type in any parent structure -- the visibility of that group's children is propagated to children of the same name in all groups in parent
Post Reply