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

Script for unlocked layers only

New Here ,
Feb 03, 2017 Feb 03, 2017

Copy link to clipboard

Copied

Hi All,
I'm very new to scripting so still learning as I go.

I have picked the following script up from this forum and changed a few things within. I'm looking to move all text frames from unlocked layers to a layer named 'HIDDEN'. The problem with this script is that it won't work with any of the layers locked and I have tried many things with no success.

var myDoc = app.activeDocument;

try{

    var myLayer = myDoc.layers.add({name:"HIDDEN"}); 

}catch(e){myLayer = myDoc.layers.item('HIDDEN')};

myDoc.textFrames.everyItem().itemLayer = myLayer;

I would be grateful for any help.

Many Thanks
Gary

TOPICS
Scripting

Views

382

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

Guide , Feb 03, 2017 Feb 03, 2017

Try this.. it will move text frames only from unlocked layers

var myDoc = app.activeDocument;

var layer = myDoc.layers;

myLayer = myDoc.layers.item('HIDDEN');

if (myLayer.isValid==false){ 

var myLayer = myDoc.layers.add({name:"HIDDEN"});

for (var i =0;i<layer.length;i++){

    if(layer.locked == false){

        layer.textFrames.everyItem().itemLayer = myLayer;

    }

}

Votes

Translate

Translate
Guide ,
Feb 03, 2017 Feb 03, 2017

Copy link to clipboard

Copied

Working in my end.. what error did you get?

Votes

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
New Here ,
Feb 03, 2017 Feb 03, 2017

Copy link to clipboard

Copied

Hi I got this error.

Screen Shot 2017-02-03 at 11.52.41.png

Votes

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
Guide ,
Feb 03, 2017 Feb 03, 2017

Copy link to clipboard

Copied

Try this.. it will move text frames only from unlocked layers

var myDoc = app.activeDocument;

var layer = myDoc.layers;

myLayer = myDoc.layers.item('HIDDEN');

if (myLayer.isValid==false){ 

var myLayer = myDoc.layers.add({name:"HIDDEN"});

for (var i =0;i<layer.length;i++){

    if(layer.locked == false){

        layer.textFrames.everyItem().itemLayer = myLayer;

    }

}

Votes

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
New Here ,
Feb 03, 2017 Feb 03, 2017

Copy link to clipboard

Copied

LATEST

Thanks for your prompt and accurate response, amazing.

Gary

Votes

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
Guide ,
Feb 03, 2017 Feb 03, 2017

Copy link to clipboard

Copied

instead of try catch use this

var myDoc = app.activeDocument;

myLayer = myDoc.layers.item('HIDDEN');

if (myLayer.isValid==false){ 

var myLayer = myDoc.layers.add({name:"HIDDEN"});

myDoc.textFrames.everyItem().itemLayer = myLayer; 

Votes

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