Skip to main content
Known Participant
February 25, 2023
Answered

Indesign script to lock layers with specific names

  • February 25, 2023
  • 1 reply
  • 1049 views

Is it possible to create a script that locks layers with specific names? All our documents have a 'CMYK' layer and occasionally a 'CMYK TOP' layer.

This topic has been closed for replies.
Correct answer Mike Bro

Hello @Davis_XI,

 

you can try either of these variations...

doc = app.documents[0];
  
try{for (var i = 0; i < doc.layers.length; i++){
    if (doc.layers[i].name == "CMYK" || doc.layers[i].name == "CMYK TOP"){
     doc.layers[i].locked = true; 
    }
  } }catch(e){} 

 

try{app.activeDocument.layers.item("CMYK").locked = true; app.activeDocument.layers.item("CMYK TOP").locked = true;}catch(e){} 

 

Regards,

Mike

1 reply

Legend
February 25, 2023

Hello @Davis_XI,

 

Here you go...

doc = app.documents[0];
  
  for (var i = 0; i < doc.layers.length; i++){
    if (doc.layers[i].name == "CMYK" || doc.layers[i].name == "CMYK TOP"){
     doc.layers[i].locked = true; 
   }
 }

Regards,

Mike

Davis_XIAuthor
Known Participant
February 27, 2023

This script is great and works perfectly if I run it with an open file but when I try and add it to my 'Batch Convert' script it errors. Is there an easy fix for this?

 

Mike BroCorrect answer
Legend
February 27, 2023

Hello @Davis_XI,

 

you can try either of these variations...

doc = app.documents[0];
  
try{for (var i = 0; i < doc.layers.length; i++){
    if (doc.layers[i].name == "CMYK" || doc.layers[i].name == "CMYK TOP"){
     doc.layers[i].locked = true; 
    }
  } }catch(e){} 

 

try{app.activeDocument.layers.item("CMYK").locked = true; app.activeDocument.layers.item("CMYK TOP").locked = true;}catch(e){} 

 

Regards,

Mike