Can a script select a layer?

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

Moderators: Fahim, Distinct Sun, Víctor Paredes, erey, Belgarath, slowtiger

Post Reply
User avatar
Víctor Paredes
Posts: 4857
Joined: Wed Jan 26, 2005 12:18 am
Location: Ireland/Chile
Contact:

Can a script select a layer?

Post by Víctor Paredes » Thu Jan 17, 2019 11:09 am

There are four or five layers I need to constantly select (in a project with hundreds), do you know if there's a way to select a layer using a button script in the tool palette?

I'm thinking on this idea:
- Put a "selection1" tag in the layer I want to select
- Have a button in the tool bar which every time I press it, it will select the layer with the "selection1" tag (I could also add a shortcut for it)

Since I have room in my tools palette, I could have several buttons referring to different tags.
Do you think that is possible?
Víctor Paredes
Former Moho Product Manager
Animator in Cartoon Saloon
My Youtube Channel - My webinars
hayasidist
Posts: 2114
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Can a script select a layer?

Post by hayasidist » Thu Jan 17, 2019 11:57 am

yes -- there's a script interface command ScriptInterface:SetSelLayer(layer, multiSelect, allowDeselect) -- scan the layers for the required tag and use it!..

e.g.

Code: Select all

function hs_sel_by_tag (moho, tag)
		if not tag then return end
		local i = 0
		repeat
			layer = moho.document:LayerByAbsoluteID(i)
			if layer then
				i = i + 1
				if layer:UserTags() == tag  then -- or contains string (e.g. use string.find)  or ..
					moho:SetSelLayer(layer) -- (or for multiselect (layer,true) and no following "break"
					break
				end
			end
		until not layer
		return
end
What I'd do is put the above into a file as utility function i.e. hs_sel_by_tag.lua goes in the utility folder

(that core code has been tested -- but it doesn't look to see if there are multiple layers with the same tag -- many ways to address that -- e.g. multi-select; or flag an error; or start from the last selected and move on rather than always start at 0; or .. depends on what you exactly want)

and the guts of the buttons are

local required_tagname = <whatever>
hs_sel_by_tag (moho, required_tagname)

you could (additionally) have a "general" button that asked the user for the required tag

Stan's new script generator should take the strain out of that!

hope that's helpful.
User avatar
synthsin75
Posts: 7084
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Can a script select a layer?

Post by synthsin75 » Thu Jan 17, 2019 6:56 pm

Not sure if this is exactly what you have in mind, but try this out, Victor: https://sites.google.com/site/synthsin/ ... ects=0&d=1

With this tool selected, if the first layer tag is a single-character (and available as a shortcut in Moho), hitting that key will select that layer.

It's up to the user to make sure the shortcuts they use are available and not duplicated, and uppercase (shift+key) and lowercase are separate shortcuts.
- Wes
ImageImageImage
User avatar
Víctor Paredes
Posts: 4857
Joined: Wed Jan 26, 2005 12:18 am
Location: Ireland/Chile
Contact:

Re: Can a script select a layer?

Post by Víctor Paredes » Thu Jan 17, 2019 7:13 pm

hayasidist wrote:yes -- there's a script interface command ScriptInterface:SetSelLayer(layer, multiSelect, allowDeselect) -- scan the layers for the required tag and use it!
(...)
Thank you very much, hayasidist!
This will be very useful for me.
synthsin75 wrote:Not sure if this is exactly what you have in mind, but try this out, Victor: https://sites.google.com/site/synthsin/ ... ects=0&d=1
With this tool selected, if the first layer tag is a single-character (and available as a shortcut in Moho), hitting that key will select that layer.
It's up to the user to make sure the shortcuts they use are available and not duplicated, and uppercase (shift+key) and lowercase are separate shortcuts.
Wes, this is just fantastic! Thank you very very much! I will start creating all my rigs with this tool in mind!
Víctor Paredes
Former Moho Product Manager
Animator in Cartoon Saloon
My Youtube Channel - My webinars
User avatar
synthsin75
Posts: 7084
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Can a script select a layer?

Post by synthsin75 » Mon Jan 21, 2019 8:36 pm

I've vastly improved this tool.
Same link: https://sites.google.com/site/synthsin/ ... ects=0&d=1
Full description here: viewtopic.php?f=12&t=32641
- Wes
ImageImageImage
User avatar
Greenlaw
Posts: 4356
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: Can a script select a layer?

Post by Greenlaw » Thu Feb 07, 2019 5:19 pm

I was just thinking there should be an easier way to select deeply nested layers, like an editable/clickable list of frequently selected layers or something like that. Then I remembered this thread.

Will give the script a try today. Sounds like it might do what I need. :)
D.R. Greenlaw
Artist/Partner - Little Green Dog | Little Green Dog Channel on Vimeo | Greenlaw's Demo Reel 2017
Lead Digital Animator, Dreamworks Animation

Image
User avatar
synthsin75
Posts: 7084
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Can a script select a layer?

Post by synthsin75 » Thu Feb 07, 2019 6:02 pm

Hopefully it's a bit faster than opening and scrolling through a list of layers.
- Wes
ImageImageImage
Post Reply