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

Participant ,
Dec 30, 2020 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?

TOPICS
Scripting

Views

74

Likes

translate

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
community guidelines

correct answers 1 Correct Answer

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

Likes

translate

Translate

Translate
Enthusiast ,
Dec 30, 2020 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

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
community guidelines
Most Valuable Participant ,
Dec 30, 2020 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

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
community guidelines