How do I get a text range contents in specific layer only?

Participant ,
Dec 30, 2020

Copy link to clipboard

Copied

Currently I have two layers in an AI document.

Layer name = Custom1

Layer name = Custom2

 

In each one of these layers I have a specific text range with the contents

TEST1 and TEST2

 

Custom1 has TEST1 text and Custom2 has TEST2

How do I select the contents of the specific layer?

 

I can select the specific layer like so:

  var aDoc = app.activeDocument;
  aDoc.layers.getByName(layerName);

The only way I can get the text range contents is like so:

aDoc.activeLayer.textFrames[0].textRange.contents

But this is gives me the textFrames from the entire document so [0] in the index gives for the document not the layer.

How can I get the textRange.contents of a specific layer only?

 

var layerz = app.activeDocument.layers;
alert( layerz["Custom1"].textFrames[0].textRange.contents );  // TEST1
alert( layerz["Custom2"].textFrames[0].textRange.contents );  // TEST2

 

TOPICS
Scripting

Views

34

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

How do I get a text range contents in specific layer only?

Participant ,
Dec 30, 2020

Copy link to clipboard

Copied

Currently I have two layers in an AI document.

Layer name = Custom1

Layer name = Custom2

 

In each one of these layers I have a specific text range with the contents

TEST1 and TEST2

 

Custom1 has TEST1 text and Custom2 has TEST2

How do I select the contents of the specific layer?

 

I can select the specific layer like so:

  var aDoc = app.activeDocument;
  aDoc.layers.getByName(layerName);

The only way I can get the text range contents is like so:

aDoc.activeLayer.textFrames[0].textRange.contents

But this is gives me the textFrames from the entire document so [0] in the index gives for the document not the layer.

How can I get the textRange.contents of a specific layer only?

 

var layerz = app.activeDocument.layers;
alert( layerz["Custom1"].textFrames[0].textRange.contents );  // TEST1
alert( layerz["Custom2"].textFrames[0].textRange.contents );  // TEST2

 

TOPICS
Scripting

Views

35

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 30, 2020 0
Engaged ,
Dec 30, 2020

Copy link to clipboard

Copied

 

var layerz = app.activeDocument.layers;
alert( layerz["Custom1"].textFrames[0].textRange.contents );  // TEST1
alert( layerz["Custom2"].textFrames[0].textRange.contents );  // TEST2

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 30, 2020 0
Most Valuable Participant ,
Dec 30, 2020

Copy link to clipboard

Copied

  1. Is TEST1 (or TEST2) the whole (only) contents - or only a part of the contents of the textFrame in your layer?
  2. Are there any other textFrames in the corresponding layers?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 30, 2020 0
Resources