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

Lock layer OR other layer (if name is different)

Participant ,
Sep 07, 2014 Sep 07, 2014

Hi!

Just started to writing my first scripts and trying to get around this:

var layNam =  app.activeDocument.layers;

layNam.getByName('Info').locked = true;

layNam.getByName('Artwork'||'Graphics').locked = true;

I am working with some templates that contain two layers 'Artwork'/'Graphics' but always contain 'Info' layer. Operator OR does not seem to work here (JavaScript returns 'no such element'). My guess would be to loop through the layers, am I right?

TOPICS
Scripting
336
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
Adobe
Valorous Hero ,
Sep 07, 2014 Sep 07, 2014
LATEST

you'd be fine with just doing this (below) -- since your layers' names are already known to you.  The function puts the get-by-names into a try{}catch{} so that the script won't error-out when a name isn't found:

function test(){

    function tryLockLayer(name){

        try{

            lrs.getByName(name).locked = true;

        } catch(e) {

            return;

        }

    };

  

    var doc=app.activeDocument;

    var lrs = doc.layers;

    tryLockLayer("Artwork");

    tryLockLayer("Graphics");

    tryLockLayer("Info");

  

}

test();


also if the layers other than Info are ones you want to lock, you can just loop and lock layers whose names are not "info"

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