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

Convert all text variable except those on a locked layer

Community Beginner ,
Sep 18, 2017 Sep 18, 2017

I am trying to figure out how to alter the script I have for converting all text variables to text into one that excludes any text variables on a locked layer. So far I've had no luck! The script below does expand all text variables, even those on a locked layer. Help?

Main();

function Main() {

for (i = 0; i < app.activeDocument.layers.length; i++) { 

    if(app.activeDocument.layers.visible == true && app.activeDocument.layers.locked == false) { 

        app.activeDocument.activeLayer = app.activeDocument.layers

       app.documents[0].stories.everyItem().textVariableInstances.everyItem().convertToText();

    }; 

}; 

      }

TOPICS
Scripting
925
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

correct answers 1 Correct answer

Mentor , Sep 18, 2017 Sep 18, 2017

Hi,

Your code is checking layer's property one by one but finally all doc's stories are the target, so...

better iterate through textFrames and check its itemLayer 'locked/visible' property.

Something like:

var

    mDoc = app.activeDocument,

    mFrames = mDoc.textFrames.everyItem().getElements(),

    cFrame;

  

    while (cFrame = mFrames.pop())

        if (cFrame.itemLayer.visible && !cFrame.itemLayer.locked)

            cFrame.textVariableInstances.everyItem().convertToText();

Jarek

PS. Notice that only

...
Translate
Mentor ,
Sep 18, 2017 Sep 18, 2017

Hi,

Your code is checking layer's property one by one but finally all doc's stories are the target, so...

better iterate through textFrames and check its itemLayer 'locked/visible' property.

Something like:

var

    mDoc = app.activeDocument,

    mFrames = mDoc.textFrames.everyItem().getElements(),

    cFrame;

  

    while (cFrame = mFrames.pop())

        if (cFrame.itemLayer.visible && !cFrame.itemLayer.locked)

            cFrame.textVariableInstances.everyItem().convertToText();

Jarek

PS. Notice that only 1st level textFrames are targeted - code ignores textFrames inside other objects (groups, other textFrames, etc)

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 ,
Sep 18, 2017 Sep 18, 2017

Wonderful. That works like a charm!

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
LEGEND ,
Sep 18, 2017 Sep 18, 2017

Hi,

As Jarek said, in your case, you're just … lucky!

(^/)

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
LEGEND ,
Sep 18, 2017 Sep 18, 2017
LATEST

With this, imho, you'll continue to be … lucky! … and others too! 

app.findGrepPreferences = null;

//----------------------------------------------------------------------

app.findChangeGrepOptions.includeHiddenLayers = false; 

app.findChangeGrepOptions.includeLockedLayersForFind = false; 

//----------------------------------------------------------------------

app.findGrepPreferences.findWhat = "~v";

myFound = app.activeDocument.findGrep();

var F = myFound.length;

while ( F-- ) myFound.textVariableInstances.everyItem().convertToText();

app.findGrepPreferences = null;

(^/)

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