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

Search and replace text with a Metadata caption

Community Beginner ,
Jan 13, 2016 Jan 13, 2016

I have a document with a placed image in the center. I want to create a metadata caption beneath it displaying the Author of the image. I have my text box set up touching the placed image with “Replace this text” temporarily.

I choose

Type > Text Variables > Define > New

I enter the Name: Author, choose Type as Metadata Caption, and choose Author from the Metadata dropdown menu and hit OK so Author appears in my list of text Variables.

I then highlight “Replace this text” and Insert the Author text Variable to replace it, so that the caption shows the Author of whatever image I import into that graphic frame.

Anyway…..my question is - can I script this so that Javascript automatically searches the document for any instances of “Replace this text” and replaces it with a Author metadata caption?

This is my attempt, I know this is probably way off but it might make it clear what I’m trying to do.

——————————————————————

app.findTextPreferences = NothingEnum.nothing; 

app.changeTextPreferences = NothingEnum.nothing; 

 

app.findTextPreferences.findWhat = “Replace this text”; 

app.changeTextPreferences.changeTo = myDocument.textVariableInstances.add({associatedTextVariable:”Author”}); 

 

//this will show changes count 

alert(app.activeDocument.changeText().length); 

 

app.activeDocument.changeText(); 

————————————————————

I'm sure its the 4th line down where I'm going wrong - Any help would be greatly appreciated!!

Luke

TOPICS
Scripting
389
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
Mentor ,
Jan 13, 2016 Jan 13, 2016

Hi,

Script should add new textVariableInstances for each found text separately (using a loop).

For example:

app.findTextPreferences = NothingEnum.nothing;

app.changeTextPreferences = NothingEnum.nothing;

app.findTextPreferences.findWhat = "Replace this text";

var

     mDoc = app.activeDocument,

     mTextVar = mDoc.textVariables.item("Author"),

     mFound = mDoc.findText(),

     cText;

if (mTextVar.isValid)

     while (cText = mFound.pop()) {

          cText.contents = "";

          cText.textVariableInstances.add(LocationOptions.AT_BEGINNING, {associatedTextVariable: mTextVar})

          }

textVariable should be created already.

Jarek

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 Beginner ,
Jan 22, 2016 Jan 22, 2016
LATEST

Thank you so much! It works perfectly!

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