Sg2.9
check for selected layers
Recent RSS
check for selected layers
From:  Doeke Wartena
Date:  12. April 2010, 22:37

I need to check if there are 2 ore more layers selected.
And just the layers, there don't have to be any objects selected.

////////

var selectedItems = document.getItems({
type: Layer,
selected: true
});

if (selectedItems.length > 1) {
print(selectedItems.length);
}

///////

The above thing doesn't work cause selected: true asks for a object to be selected.
But if i remove the line then it doesn't matter if i have a layer selected or not, it will always report 6 ( since i had 6 layers).

Is it possible?

P.S. after that i have to perform a action first on 1 of the layers and after that the other layer.

Re: check for selected layers
Date:  13. April 2010, 11:06

This looks like a bug to me - we will look into it

Re: check for selected layers
From:  Jürg Lehni
Date:  15. April 2010, 18:12

Hi Doeke,

After looking into this in depth I found out that the Illustrator SDK broke the functions to get and set the selection state of layers, and there appears to be no way around this unfortunately.

But while looking for a way to fix this I found a workaround: The 'target' marker to mark multiple layers and items can be used instead (the two concentric circles to the right of each targeted line in the layers list):

I am adding support for items marked as targets (targeted items) to Sg now, both by using item.targeted, and the targeted: flag in document.getItems().

Re: check for selected layers
From:  Jürg Lehni
Date:  15. April 2010, 18:45

In fact, you can already use this now. The following code will return all targeted layers in a list:

var layers = document.getItems({
	type: Layer,
	targeted: true
});

And the property layer.targeted will be added in the upcoming release.

Re: check for selected layers
From:  Doeke Wartena
Date:  17. April 2010, 11:50

Ok thx,

I will use the workaround.

Scripts
08.08.14, 15:24
15.05.14, 14:23
02.03.14, 19:16
18.11.13, 14:48
22.03.13, 03:05
22.02.13, 15:45
Posts
10.01.17, 16:37
19.02.16, 06:03
19.02.16, 06:00
17.01.16, 11:00
12.01.16, 13:10
25.11.15, 08:19
Script of the Moment
Hexagonal Grid Generator 16.11.11