Copy link to clipboard
Copied
I'm doing something relatively simple. I have some code that stuffs all text layers across all project comps into an array that I declare and initialize. I'd like to simply display an alert showing the actual text content of the text layer. More specifically, I want to display the authored text content, not text content that is set by a script.
When I run this code via the ExtendScript IDE, I get an error. Here is the problematic code. Note that I have verified that the contents of my array are, in fact, text layer objects.
for (var k=0; k < myLayerArray.length; k++)
{
alert("Layer: " + myLayerArray
}
I thought this would be simple, after seeing this example from the PDF documentation.
This sets a value of some source text and displays an alert showing the new value:
var myTextDocument = new TextDocument("Happy Cake"); myTextLayer.property("Source Text").setValue(myTextDocument); alert(myTextLayer.property("Source Text").value);
But I may be missing something as the example is displaying text after it has been set by the .setValue method on the Source Text property.
If I do this:
for (var k=0; k < myLayerArray.length; k++)
{
alert("Layer: " + myLayerArray
}
I don't get an error from the IDE, and AE shows the alert, but it says ". . . with Text: undefined".
This should be relatively simple, but I can't find my answer in the documentation. Can anybody help me out?
Thanks for your time and help!
Copy link to clipboard
Copied
I think you're going to have to harvest the text before you change it with setValue().
Dan
Copy link to clipboard
Copied
Hi Dan,
Thanks for the suggestion. I have harvested all the text layers and they are in an Array. I don't want to alter or change the text, I just want to grab the values of the text it from the authored text layer and present it in an alert box. How can I achieve that?
Thanks!
Copy link to clipboard
Copied
I guess I don't understand. I thought you were trying to get the original text, before it got changed by the script. Is that not the case? If it is, then you have to get the text itself (not the text layer) before you change it.
Dan
Copy link to clipboard
Copied
How do you get the text itself without first getting the text layer?
Copy link to clipboard
Copied
OK, going back to your original question, try this:
alert("Layer: " + myLayerArray
Dan
Copy link to clipboard
Copied
Dan,
Once again you are the master. It worked perfectly. Thank you for clarifying that for me.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now