help: Autoselect parent layer when pressing Z

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
keisern
Posts: 38
Joined: Mon May 01, 2006 11:05 am
Location: Norway
Contact:

help: Autoselect parent layer when pressing Z

Post by keisern »

We have pretty complex character rigs with lots of switch- and sublayers. We therefore spend a lot of time alternating between the parent (bone) layer and the sub/switchlayers.

I was wondering if it's possible to edit the manipulate bone tool script to autoselect the parent bone layer when pressing Z. Is this possible? (When in a sub-layer, the manipulate bone tool is greyed out).

Any hints appreciated!
Halvseint, animated talkshow on NRK
www.nrk.no/halvseint
User avatar
rylleman
Posts: 750
Joined: Tue Feb 15, 2005 5:22 pm
Location: sweden
Contact:

Post by rylleman »

Perhaps my "Select Parent Layer"-script may be of any help?
viewtopic.php?t=3720&highlight=parent+layer
keisern
Posts: 38
Joined: Mon May 01, 2006 11:05 am
Location: Norway
Contact:

Post by keisern »

Thanks Rylleman, this is helpful.

Now I need to find out how I can integrate your script with the LM_ManipulateBones script. The problem is that the manipulate bones tool is greyed out when a non-bone layer is selected, therefore the script doesn't seem to run.
Halvseint, animated talkshow on NRK
www.nrk.no/halvseint
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

I think the only reason that tool is "grayed out" is because its script tells it so. ;)

What you might be able to do is to modify that tool script so it is available on any layer, then when it is selected you would check the type of layer that is active and THEN run the "select parent layer" script.

-vern
keisern
Posts: 38
Joined: Mon May 01, 2006 11:05 am
Location: Norway
Contact:

Post by keisern »

Thanks heyvern,

I'm getting slightly closer :)

Right now I'm trying to mod the script to move down in the layer window. I think this is more valuable for us, adding shortcuts to move up and down in the layer window, selecting next/previous layer. But I'm having trouble with

moho:SetSelLayer()

Is there an (easy) way of setting the next layer active?

How do you know what the next layer object is? moho.layer is the current layer object, and moho.layer:Parent() is the parent. What about the child?
Halvseint, animated talkshow on NRK
www.nrk.no/halvseint
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Yikes... it's kind of complicated I think. I haven't really put much thought into how to do this so take this with a grain of salt. I will point you in the right direction in the reference but you will need to do the hard stuff on your own.

The reason I think it is complicated is because... each type of layer is handled differently. When you select a layer inside a group layer than you have to change the way you pick the layers in the script.

You need to look in the reference under a couple of different spots. GroupLayer
MohoDoc
MohoLayer
ScriptInterface

All of these entries in the reference have info about layers.

What you need for setting the setSelLayer is referenced under the MohoDoc. You need to get a layer object first:

Code: Select all

MohoLayer Layer(id)
"MohoLayer" is what you "get" when you use this. It is the MohoLayer that is the object you need to use setSelLayer().

You need this object in order to change the selected layer. You need to get the layer ID of the next or previous layers in that group.

So you would need to do something like this:

Code: Select all

    local group = moho:LayerAsGroup(layer)
Then go to the first layer in that group layer. 0 is the lowest layer. So you could get the "first" layer by using:

Code: Select all

    local layer = moho.layer
    local layerCount = group:CountLayers()
layerCount -1 would be the first layer of the group (at the top in the layers palette). The layer count is the total but the ID starts at 0... so... -1 gives the correct layer object ID.

You could do this:

Code: Select all

    moho:SetSelLayer(group:Layer(layerCount-1))
Once you get to that layer then everything changes because now you aren't on the "group" layer, you are on a layer inside it. Your script would need to account for being on a child layer. You would need to count the layers of the parent group and figure out which one is next.

I think some of this is close, but I haven't really done a lot of tool scripts. I work more with layer scripts which are a bit different. I hope I don't steer you in the wrong direction.

-vern
Post Reply