Sg2.9
setting the documents active...
Recent RSS
setting the documents active layer based on a selected object
From:  chris h
Date:  25. October 2012, 23:51

Hi,

I'm wondering how I would set the document.activeLayer to the layer where an object is selected?

I have the following code:
//get all text within a range of layers
var sel = document.getItems({
type: 'TextItem',
selected: true,
});

//not sure what the syntax should be here, but the following produces an error:
document.activeLayer = sel.activeLayer;

var layer = document.activeLayer;
print (layer.name);

thanks for the help!

Re: setting the documents active layer based on a selected objec
From:  pqbd
Date:  26. October 2012, 00:25

You can find an item's parent layer with item.layer property. For example:

sel=document.selectedItems;
for ( i = 0; i < sel.length; i++ ) console.log ( sel[i].layer );

Re: setting the documents active layer based on a selected objec
From:  chris h
Date:  26. October 2012, 01:00

okay, thanks.

Let's say I want to search through all type in a document and select type only on a certain layer, say a layer with the name "layer 1".

I have this so far, which I think is putting me on the way but I am obviously doing something wrong with the isDescendant(item) function as I get an error message "TypeError: cannot find function isDescendant in object TextArea"

var layer = document.activeLayer;
print(layer.name);

var sel = document.getItems({
type: 'TextItem',
selected: false,
});

for (i=0;i<sel.length;i++) {
if (layer.children.length != 0){
if (sel.isDescendant(layer)==true){
sel[i].selected = true;
}
}
}

My end goal for this is that I'd like to be able to find text in several layers specified by name and then apply different character styles to the type in each of those layers. So layer 1 would get character style A, then layer 2 would get character style B, etc.

Re: setting the documents active layer based on a selected objec
From:  pqbd
Date:  26. October 2012, 02:25

It works, you're just missing the index number of the array in your last if statement.

if (sel[i].isDescendant(layer)==true){ ...

Re: setting the documents active layer based on a selected objec
From:  chris h
Date:  26. October 2012, 18:56

knew I left something out! Thanks for the pointer =)

How would I then reference a document's character styles from the character style panel? I'm trying to set a variable to a specific character style but getting an undefined error:

var char1 = document.characterStyle["Some Character Style"];

Re: setting the documents active layer based on a selected objec
From:  pqbd
Date:  27. October 2012, 02:29

Unfortunately the document object doesn't have a characterStyle array property.

EIther you can define one in your code, or you can copy the style of an existing text item.

Re: setting the documents active layer based on a selected objec
From:  chris h
Date:  29. October 2012, 18:42

ah, okay, thanks for the info.

That would be a nice feature to see in a future update of scriptographer; it would be especially useful when a document contains many predefined (from a template.ait) character, graphic, and paragraph styles.

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
Stroke Tone Line 10.03.09