Looping through selected layers

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
lehtiniemi
Posts: 107
Joined: Mon Jan 14, 2013 3:18 pm

Looping through selected layers

Post by lehtiniemi »

I tried to look for a way to access selected layers, all I found was CountSelectedLayers(GroupLayer *group). I tried passing it an argument, like so:

Code: Select all

local layerList
moho.document:CountSelectedLayers(layerList)
However, layerList won't contain selected layers after this call. How do I use it or is there some other way?
User avatar
synthsin75
Posts: 9972
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Looping through selected layers

Post by synthsin75 »

CountSelectedLayers does not populate the empty variable. You need to assign it a variable:

local selLayerCount = moho.document:CountSelectedLayers(moho.document)

You can also specify a particular group layer instead of the whole document.
To count through them:

for i=0, moho.document:CountSelectedLayers(moho.document)-1 do
lehtiniemi
Posts: 107
Joined: Mon Jan 14, 2013 3:18 pm

Re: Looping through selected layers

Post by lehtiniemi »

synthsin75 wrote:CountSelectedLayers does not populate the empty variable. You need to assign it a variable:

local selLayerCount = moho.document:CountSelectedLayers(moho.document)

You can also specify a particular group layer instead of the whole document.
To count through them:

for i=0, moho.document:CountSelectedLayers(moho.document)-1 do
Ah, thanks! Hmm but how do I access the selected layers? CountSelectedLayers doesn't tell me which layers are selected.
User avatar
synthsin75
Posts: 9972
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Looping through selected layers

Post by synthsin75 »

lehtiniemi wrote:Ah, thanks! Hmm but how do I access the selected layers? CountSelectedLayers doesn't tell me which layers are selected.

Code: Select all

for i=0, moho.document:CountSelectedLayers(moho.document)-1 do
     local layer = moho.document:GetSelectedLayer(i)
lehtiniemi
Posts: 107
Joined: Mon Jan 14, 2013 3:18 pm

Re: Looping through selected layers

Post by lehtiniemi »

synthsin75 wrote:
lehtiniemi wrote:Ah, thanks! Hmm but how do I access the selected layers? CountSelectedLayers doesn't tell me which layers are selected.

Code: Select all

for i=0, moho.document:CountSelectedLayers(moho.document)-1 do
     local layer = moho.document:GetSelectedLayer(i)
Thanks!!!
Post Reply