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

Indesign script to lock layers with specific names

Participant ,
Feb 25, 2023 Feb 25, 2023

Copy link to clipboard

Copied

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

Views

467

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 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

Votes

Translate

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

Votes

Translate

Translate
Advisor ,
Feb 25, 2023 Feb 25, 2023

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

Hi Mike, thank you!!!

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

LATEST

You're a star, thank you!!!

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