*UPDATED 3/1/19* Layer Shortcuts tool

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
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

*UPDATED 3/1/19* Layer Shortcuts tool

Post by synthsin75 »

This is a major update to a quick tool I wrote for a request Victor made here: http://www.lostmarble.com/forum/viewtop ... 51#p186251

This update is the same link: https://drive.google.com/uc?export=down ... yf2lql7JMx
Latest version: 2.6

With this tool selected you can assign keyboard shortcuts to instantly select specific layers. [[I've disabled keyboard shortcuts for now. This avoids errors in v13.5, until I can fix them. Workspace buttons will work without any errors.]]
The options are:
  • Available shortcuts dropdown*** - This shows a list of shortcuts that you are not using in your Moho keyboard shortcuts and are available for layer shortcuts.
  • Show checkbox* - If you have a shortcut assigned to the current layer, this will show/hide the shortcut in the layer name ("(A)LayerName"). Hide this if changing the layer name messes up any switch layer or other scripts.
  • Input field** - Enter the keyboard key you want for a shortcut. Capital letters are the shortcut shift+letter. This only allows one letter, so no need to delete. Just click in it an add the next key you want.
  • Assign button* - If you have entered an available shortcut, this button will assign it to the current layer.
  • Add to layer name checkbox - This sets whether new shortcuts add the indicator to the layer name. You can always change this later, using the Show checkbox.
  • Remove button* - This removes an assigned shortcut from the current layer.
* You can show/hide layer name indicators and assign and remove shortcuts for all selected layers at the same time.
**You can use the same shortcut for multiple layers, and hitting it will select the next layer below with that shortcut or cycle back to the top one, if you're at or below the last.
***This feature has been tested on Mac (thanks Dondo).


New features as of version 2.1
Workspace buttons:
  • Set/Remove Group button - This sets or removes the current group layer as the top layer of its group. Use this in case the top of the group you want to navigate within is inside another group.
  • Make Button button - This makes a workspace button for the current layer.
  • Type dropdown - Select the type of button to make:
    • Note Layer - This will create a note layer with the layer's name. This note layer will be created in a "SYN: Shortcut Note" group layer.
    • Text Shape - This will create a text of the layer's name. This text will be created on a "SYN: Shortcut Text" vector layer.
    • Custom Shape - This allows you to select ANY shape, on ANY layer, as a shortcut. If the layer has a Layer Color, the custom shape will be colored to match.
  • Scope dropdown - Select how new button will behave:
    • Local checkbox - If checked, the text or note shortcuts will be created at the top of the current group. This mostly exists to have shortcut buttons move with a group, if local. This can be used to keep text and note buttons near the character they apply to.
    • Universal checkbox - If checked, the button will match any layer with the same name in any group. This can be useful for setting up master shortcut buttons that work for all characters. That way instead of having a "left hand" button for each character, the same "left hand" button will work for whatever character group you are currently in.
  • Auto-collapse checkbox - If checked, layers will collapse to only expose the selected layer.
  • Selected layer dropdown - This displays the name of the current layer. This helps if you have group layers collapsed without Auto-collapse enabled (so the Layers window doesn't show the selected layer). You can also select layers using this dropdown. It will only show layers from the current group.
  • Indent - This indents the Select layer dropdown list to show the layer hierarchy. This also affects how the name is displayed in the Select layer dropdown. So with deeply nested layers, you may have to reduce the Indent to see the layer name in the dropdown. You can do this interactively, by scrolling in the Indent input.
New features as of version 2.3
  • Up/Down Arrows to select through the layers.
  • Universal checkbox - If checked, the button will match any layer with the same name in any group (behavior prior to v 2.3). This can be useful for setting up master shortcut buttons that work for all characters. That way instead of having a "left hand" button for each character, the same "left hand" button will work for whatever character group you are currently in.
  • Non-universal buttons will now ONLY select the layer they are assigned to, regardless of multiple layers with the same name, or even changing the layer name (although that won't update the button label...v2.4 will now update the note button name if the assigned layer name changes).
Notes on usage:
Selecting layers using the Selected layer dropdown requires that all the layers in the group have unique names. As of v2.3, you no longer need unique layer names for this dropdown or non-universal shortcut buttons.
If you click anywhere other than a shortcut button, it will select the group's top layer or, if that is already selected, the groups bottom layer.
When selecting custom shapes, you don't have to change layers. Just click the shape after hitting OK.
Non-local shortcuts work well with my dock layer script:
*NEW-ish* Dock Layers to workspace (Auto-dock on Windows)



For other scripters: I used os.getenv to find the user's Moho AppData folder and read which keybinding file they are using from the .user.settings file. (I think I was trying to sort this out for Dennis' MQC.) I then parse that file for used shortcuts, including whether the shortcuts use the shift modifier. There may be some extra shortcuts unavailable, because I didn't bother to avoid factory ones that had user set replacements.
I had to use my older recursive layer search, based on Fazek's method, in order to get the layers in the same order as the layer window. A repeat loop using moho.document:LayerByAbsoluteID(count) would not produce this.
Last edited by synthsin75 on Thu Aug 12, 2021 10:27 pm, edited 37 times in total.
User avatar
Víctor Paredes
Site Admin
Posts: 5646
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Re: *NEW* Layer Shortcuts tool

Post by Víctor Paredes »

This is fantastic, Wes. Thank you very much.
I just assigned the shortcut "1" to the tool and the next numbers as shortcuts for different layers.
It's quick to access and works great.

Another feature I'm enjoying is that you can assign the same shortcut to several layers. So, for instance, in the character I'm working right now, hitting "2" selects the main bone layer, but hitting it again selects different mesh layers I'm using to animate face expressions.
Image Image Image Image
Moho Product Manager

www.mohoanimation.com
Rigged animation supervisor in My father's dragon - Lead Moho artist in Wolfwalkers - Cartoon Saloon - My personal Youtube Channel
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: *NEW* Layer Shortcuts tool

Post by synthsin75 »

Glad you're liking it, Victor.

I just updated it to fix the available shortcut list not removing some user set shortcuts.
User avatar
Greenlaw
Posts: 9192
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: *NEW* Layer Shortcuts tool

Post by Greenlaw »

This sounds very useful! Bookmarking this thread and giving the tool a try it this weekend.

Thanks for sharing it, Wes!
dondo
Posts: 60
Joined: Tue Jan 15, 2019 4:45 am

Re: *NEW* Layer Shortcuts tool

Post by dondo »

I'm using a Mac and sadly it doesn't work. Console says "syn_layer_shortcuts.lua:159: attempt to concatenate a nil value"

I've confirmed that os.getenv("HOME") gives me the path to my home directory (/Users/dondo/), but I don't see a 'Moho Pro.{version}.user.settings' file there. I inspected the Moho install folder and couldn't find it there, either, and after a little web searching that suggested on the Mac it might be in ' ~/Library/Application Support/Smith Micro' but that folder doesn't exist either.

I'm pretty eager to try this script; let me know how I can help figure out where the file is. (If it would be easier and you're interested, I'd be happy to DM you my direct contact info.)
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: *NEW* Layer Shortcuts tool

Post by synthsin75 »

Try this update (same link): https://sites.google.com/site/synthsin/ ... ects=0&d=1

If that doesn't work on Mac, could you also look in "~/Library/Preferences" for a Moho folder?
You may also need to press "CMD + SHIFT + ." to show hidden folders, on Sierra or later. Otherwise this shows the long way to show hidden folders: https://ianlunn.co.uk/articles/quickly- ... mavericks/
dondo
Posts: 60
Joined: Tue Jan 15, 2019 4:45 am

Re: *NEW* Layer Shortcuts tool

Post by dondo »

[edited for clarity]

Sorry, that update didn't work. You were right, the file is in ~/Library/Preferences:

Code: Select all

dondo@Air-Dondo-2 > pwd
/Users/dondo/Library/Preferences/Smith Micro/Moho Pro/12

dondo@Air-Dondo-2 > ls
Autosave                     Moho Pro12.exporter.settings
LibraryIndex_1.db            Moho Pro12.user.settings
LibraryState.json

dondo
Posts: 60
Joined: Tue Jan 15, 2019 4:45 am

Re: *NEW* Layer Shortcuts tool

Post by dondo »

Ok, I absolutely love this script! Thanks, Syn.

So I hacked the following into line 164 to confirm that the tool works on mac:

Code: Select all

		appData = os.getenv("HOME").."/Library/Preferences/Smith Micro/" -- Mac
So since you've been so incredibly helpful, I decided to try to give a little back (as much as anything to start digging into scripting). If this is obvious, apologies in advance; I'm new to this world. :)

Since os.getEnv("OS") returns nil on my Mac, I did a little Googling and found a way to distinguish a Mac from Unix. I verified that it returns "Darwin" on my Mac (macOS Mojave, 10.14.2), and that on my Linux box it returns "Linux". The wikipedia article on `uname` suggests that all Macs use Darwin as their kernel, so that should be sufficient to distinguish the three platforms.

https://stackoverflow.com/questions/295 ... lua-script
https://en.wikipedia.org/wiki/Uname

Bringing all that together, I dropped this into the top of your script and then call it from within your HandleMessage:

Code: Select all


-- ********************************************************
-- Utility methods to figure out the path to the appdata
-- ********************************************************

function os.capture(cmd, raw)
  -- from https://stackoverflow.com/questions/295052/how-can-i-determine-the-os-of-the-system-from-within-a-lua-script
  local f = assert(io.popen(cmd, 'r'))
  local s = assert(f:read('*a'))
  f:close()
  if raw then return s end
  s = string.gsub(s, '^%s+', '')
  s = string.gsub(s, '%s+$', '')
  s = string.gsub(s, '[\n\r]+', ' ')
  return s
end

function Syn_LayerShortcuts:getOS()
	local result
	if (os.getenv("OS") ~= nil) and (string.lower(string.sub(os.getenv("OS"), 1, 3)) == "win") then
		result = "Windows"
	else -- Unix flavor, figure out if it's a mac
		local osname = os.capture('uname')
		if (osname ~= nil) and (osname == "Darwin") then
			result = "Mac"
		else
		    result = "Unix"
		end
	end
	return result
end

function Syn_LayerShortcuts:getAppDataPath()
	local appDataPath
	local os_env = self.getOS()
	if (os_env == "Windows") then
		appDataPath= os.getenv("APPDATA").."/Smith Micro/"
	elseif (os_env == "Mac") then
		appDataPath = os.getenv("HOME").."/Library/Preferences/Smith Micro/"
	else -- Unix
	    appDataPath = os.getenv("HOME").."/"
	end
	return appDataPath
end
Hope this helps; again, sorry if it's well known.
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: *NEW* Layer Shortcuts tool

Post by synthsin75 »

Thanks for the detective work, Dondo!

Since there's no Linux version, I doubt that we'll need to worry if Moho is being ran on one, as it would be running on an emulator.

But I've updated the official version with the right path for Mac.
dondo
Posts: 60
Joined: Tue Jan 15, 2019 4:45 am

Re: *NEW* Layer Shortcuts tool

Post by dondo »

Ha! Well, when they release it on Ubuntu, you are _ready_.

:)
F.M.
Posts: 497
Joined: Thu Nov 04, 2004 4:29 pm
Location: Between my ears

Re: *NEW* Layer Shortcuts tool

Post by F.M. »

Thank you for your very valuable contributions.
"and then Man created god!"
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: *NEW* Layer Shortcuts tool (huge update)

Post by synthsin75 »

Huge update, introducing Workspace Buttons.

https://sites.google.com/site/synthsin/ ... ects=0&d=1

New features as of version 2.1
Workspace buttons:
  • Set/Remove Group button - This sets or removes the current group layer as the top layer of its group. Use this in case the top of the group you want to navigate within is inside another group.
  • Make Button button - This makes a workspace button for the current layer.
  • Type dropdown - Select the type of button to make:
    • Note Layer - This will create a note layer with the layer's name. This note layer will be created in a "SYN: Shortcut Note" group layer.
    • Text Shape - This will create a text of the layer's name. This text will be created on a "SYN: Shortcut Text" vector layer.
    • Custom Shape - This allows you to select ANY shape, on ANY layer, as a shortcut. If the layer has a Layer Color, the custom shape will be colored to match.
  • Local checkbox - If checked, the text or note shortcuts will be created at the top of the current group. This mostly exists to have shortcut buttons move with a group, if local.
  • Auto-collapse checkbox - If checked, layers will collapse to only expose the selected layer.
  • Selected layer dropdown - This displays the name of the current layer. This helps if you have group layers collapsed without Auto-collapse enabled (so the Layers window doesn't show the selected layer). You can also select layers using this dropdown. It will only show layers from the current group.
Notes on usage:
Selecting layers using the Selected layer dropdown requires that all the layers in the group have unique names.
If you click anywhere other than a shortcut button, it will select the group's top layer.
You can use the same shortcuts in multiple groups. So if your groups have the same layer names, the shortcuts work for the group of the current layer. It doesn't matter if the shortcut buttons are local or not. If you can see and click them, they work for any group with those layer names.
When selecting custom shapes, you don't have to change layers. Just click the shape after hitting OK.
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: *HUGE UPDATE* Layer Shortcuts tool

Post by synthsin75 »

Version 2.1

Added the Type dropdown (described above) to avoid all the clicking. Now you just set the type of button you want to make and forget it.
User avatar
Greenlaw
Posts: 9192
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: *HUGE UPDATE* Layer Shortcuts tool

Post by Greenlaw »

Wes, the latest Layer Shortcuts tool is FANTASTIC!

ATM, I'm using it with the Note layer 'button' option and it's doing exactly what I want...and it works GREAT with a tablet. I don't understand all the options yet but what I do understand is already super useful to me. Will spend more time with it over the long weekend.

I hope I can get approval to let us use the script at work. I'm already using it in a personal animation project.

Thanks for all your clever work and generosity in sharing it! :D
User avatar
Víctor Paredes
Site Admin
Posts: 5646
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Re: *HUGE UPDATE* Layer Shortcuts tool

Post by Víctor Paredes »

Wes, this new version is amazing.
I'm loving the new buttons, specially using shapes. It's just great!

Ps: It's also funny, because in CS we were talking about a very similar concept to create shortcuts in the software. The idea was to drag a layer over the screen to have a shortcut floating there.
Image Image Image Image
Moho Product Manager

www.mohoanimation.com
Rigged animation supervisor in My father's dragon - Lead Moho artist in Wolfwalkers - Cartoon Saloon - My personal Youtube Channel
Post Reply