Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Retrieving "Source Text" value doesn't seem to work.

Participant ,
Aug 01, 2011 Aug 01, 2011

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.name + " with Text: " + myLayerArray.property("Source Text").value);

}

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.name + " with Text: " + myLayerArray.property("text").value);

}

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!

TOPICS
Scripting
2.1K
Translate
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
Community Expert ,
Aug 01, 2011 Aug 01, 2011

I think you're going to have to harvest the text before you change it with setValue().

Dan

Translate
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
Participant ,
Aug 01, 2011 Aug 01, 2011

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!

Translate
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
Community Expert ,
Aug 01, 2011 Aug 01, 2011

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

Translate
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
Participant ,
Aug 01, 2011 Aug 01, 2011

How do you get the text itself without first getting the text layer?

Translate
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
Community Expert ,
Aug 01, 2011 Aug 01, 2011

OK, going back to your original question, try this:

alert("Layer: " + myLayerArray.name + " with Text: " + myLayerArray.property("Source Text").value.text);

Dan

Translate
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
Participant ,
Aug 02, 2011 Aug 02, 2011
LATEST

Dan,

Once again you are the master.  It worked perfectly.  Thank you for clarifying that for me.

Translate
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