How to set group masking to "hide all"?

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
ponysmasher
Posts: 370
Joined: Wed Aug 04, 2004 6:23 pm
Location: Los Angeles
Contact:

How to set group masking to "hide all"?

Post by ponysmasher »

I've managed to set other settings of layers with a script but not that.

How are you supposed to write it?
User avatar
Rai López
Posts: 2298
Joined: Sun Aug 08, 2004 5:41 am
Location: Spain
Contact:

Post by Rai López »

If you only want to set that setting, without get into GUI's and similar, I think you can look at the bottom of the "scripts/menu/Layer Effects/lm_layershadow.lua script to figure it out. Fortunately, you'll be able to find (generally) something closely related (or not) with you are treating to do somewhere inside all that AS scripts, so always it worths to take some time scrutinizing them before star to write blindly. A mine of wisdom and (saved) time ;).
...
User avatar
heyvern
Posts: 7043
Joined: Thu Sep 01, 2005 8:49 pm

Post by heyvern »

I think it's kind of tricky. Are you using the script reference HTML help files availabe in the script forum? Very handy.

Here's the description in the reference to change the masking of a group layer:
void SetGroupMask(mask)

Sets the group's masking mode. See group masking mode constants.
Return value: none mask (int): the group's masking mode
The first thing you need is the layer reference. If you have done scripty things with layers than you know how to get the layer reference. Then you have to tell lua what type of layer it should be used as:
GroupLayer LayerAsGroup(layer)

Converts a generic layer object into a group layer.
Return value (GroupLayer): a GroupLayer object layer (MohoLayer): the layer to cast
So if you've done a lot of scripting you know this part:

Code: Select all

local layer = moho.layer
That is the current layer selected. If that layer is a group layer and you want to change the masking tell lua what type of layer you want the current layer to be referenced as:

Code: Select all

layer = moho:LayerAsGroup(layer)
Once you've done that you can do group layer stuff to "layer". Even if "layer" was a group layer, AS lua isn't going to know that. You have to tell it specifically to work with a group layer.

Now you can set the masking... I hope this works. Haven't tested it but it's the same as other layer type stuff I've done before.

Code: Select all

layer:SetGroupMask(2)
This should set the masking mode of the current layer to "hide all". In the script reference the following are listed as masking options.
The following constants are used to define the masking that happens within a group.


GROUP_MASK_NONE - No masking
GROUP_MASK_SHOW_ALL - Turn on masking, initially showing all sub-layers
GROUP_MASK_HIDE_ALL - Turn on masking, initially hiding all sub-layers
remember that you need an INTEGER for the masking reference. The numbers always start with 0 so "hide all" would be 2:

Hope this is not too confusing. ;)

-vern
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 7:27 am
Location: España / Spain

Post by Genete »

Now you can set the masking... I hope this works. Haven't tested it but it's the same as other layer type stuff I've done before.

Code: Select all

layer:SetGroupMask(2)
This should set the masking mode of the current layer to "hide all". In the script reference the following are listed as masking options.
The following constants are used to define the masking that happens within a group.


GROUP_MASK_NONE - No masking
GROUP_MASK_SHOW_ALL - Turn on masking, initially showing all sub-layers
GROUP_MASK_HIDE_ALL - Turn on masking, initially hiding all sub-layers
I would use:

Code: Select all

layer:SetGroupMask(GROUP_MASK_HIDE_ALL)
because in the future that value can change and if you hard code the value you are assuming that they won't change. That's the reason those constants are defined. Also the code is more "human readable" ;)
-G
ponysmasher
Posts: 370
Joined: Wed Aug 04, 2004 6:23 pm
Location: Los Angeles
Contact:

Post by ponysmasher »

Thank you for all the help, it works now!

I was doing it like this: layer:SetGroupMask(GROUP_MASK_HIDE_ALL)
But realized it had to be: layer:SetGroupMask(MOHO.GROUP_MASK_HIDE_ALL)

It does say that in the documentation on closer inspection... :oops:

Doing it Verns way, layer:SetGroupMask(2), worked as well of course.
User avatar
heyvern
Posts: 7043
Joined: Thu Sep 01, 2005 8:49 pm

Post by heyvern »

I have found that some of the constants in other areas of the reference don't work using the "text" version. I forget which one it was but I spent ages bug testing my code only to find that using the integer worked but the text didn't.

So, if down the road it's not working... check that. ;)

-vern
Post Reply