Skip to main content
Known Participant
March 8, 2019
Answered

Select and move to new layer

  • March 8, 2019
  • 2 replies
  • 803 views

Hi - i was wondering if anyone can help? A while back someone kindly supplied me this script which will move all my text which has been coloured up in a specific colour to a new layer. Along with the text we also use leader lines for diagrams which are also coloured up in the same colour. Is there a way of also selecting lines that have been produced either with the pen tool or the line tool and move those to the same layer. The only thing they have in common is they are coloured up in the same colour.

Many thanks

var myDoc = app.activeDocument;

try{

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

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

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

This topic has been closed for replies.
Correct answer Sunil Yadav

Hi There,

Try This code...

var myDoc = app.activeDocument;

try{

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

    }

catch(e){

    myLayer = myDoc.layers.item('Text Black');

    }

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

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

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

Best

Sunil

2 replies

Sunil Yadav
Sunil YadavCorrect answer
Legend
March 11, 2019

Hi There,

Try This code...

var myDoc = app.activeDocument;

try{

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

    }

catch(e){

    myLayer = myDoc.layers.item('Text Black');

    }

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

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

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

Best

Sunil

Known Participant
March 11, 2019

Great - worked a treat once I'd ungrouped the elements. Out of interest would there be a way of setting the text black stroke to overprint?

Thanks again!!!!

Inspiring
March 9, 2019

Hi,

    

    Try using pageItem's constructor name to identify the items with color and then move into layer.

     line drawn by line line tool - Constructor name return as GraphicLine

     line drawn by pen tool - Constructor name return as Polygon

     var pgItm = app.selection[0]

     if(pgItm.constructor.name == "GraphicLine" || pgItm.constructor.name == "Polygon")

     {

          // code here

     }

Known Participant
March 11, 2019

Hi - thank you for your reply but unfortunately it's not working. Pretty sure it's going to be something i'm doing wrong as I'm new to scripting.