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

Indesign script to lock layers with specific names

Contributor ,
Feb 25, 2023 Feb 25, 2023

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.

TOPICS
Scripting
1.0K
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 2 Correct answers

Advisor , Feb 25, 2023 Feb 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

Translate
Advisor , Feb 27, 2023 Feb 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

Translate
Advisor ,
Feb 25, 2023 Feb 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

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
Contributor ,
Feb 25, 2023 Feb 25, 2023

Hi Mike, thank you!!!

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
Contributor ,
Feb 27, 2023 Feb 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?

 

Screenshot 2023-02-27 at 22.03.30.png

 

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
Advisor ,
Feb 27, 2023 Feb 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

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
Contributor ,
Feb 27, 2023 Feb 27, 2023
LATEST

You're a star, thank you!!!

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