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

Is it possible to automate or create a script to duplicate links and activate/deactivate Layer Comp?

New Here ,
May 30, 2024 May 30, 2024

Copy link to clipboard

Copied

For example, if I have 50 .psd images in my file, which I need to duplicate each one, so two links for each image.

The top image needs to have only a certain group/layer activated using the Layer Comps tool, then the second link under that needs to have everything deactivated but leaving only a layer which needs to be in multiply mode.

Basically two links, one for the model, another for the model's shadow.

What's the best approach to do that?

TOPICS
How to

Views

993

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
Community Expert ,
May 30, 2024 May 30, 2024

Copy link to clipboard

Copied

What's so special with the shadow in your file that you can't generate shadow in InDesign?

 

If names of the layers are constant - then it would be fairly easy.

 

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
New Here ,
May 30, 2024 May 30, 2024

Copy link to clipboard

Copied

It's a "real" shadow from the image, not generated

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
Community Expert ,
May 30, 2024 May 30, 2024

Copy link to clipboard

Copied

What with the names of the layers?

 

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
New Here ,
May 31, 2024 May 31, 2024

Copy link to clipboard

Copied

The main layer is a group called "Modelo" and the layer for the shadow, the link under that, is called "Sombra", in all the images.

 

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
Community Expert ,
May 31, 2024 May 31, 2024

Copy link to clipboard

Copied

Hi @ril3ydx , maybe something like this where my shadow layer is named "Shadow"

 

var ln = "Shadow"
var lnk = app.activeDocument.links.everyItem().getElements()

var obj, dup, sh;
for (var i = 0; i < lnk.length; i++){
    if (lnk[i].parent.constructor.name == "Image") {
        obj = lnk[i].parent.parent
        dup = obj.duplicate();
        sh = dup.images[0].graphicLayerOptions.graphicLayers.itemByName(ln)
        sh.currentVisibility = false;
        obj.transparencySettings.blendingSettings.blendMode = BlendMode.MULTIPLY
    } 
};   

 

 

 

Screen Shot 36.pngScreen Shot 37.png

 

 

Screen Shot 39.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
New Here ,
May 31, 2024 May 31, 2024

Copy link to clipboard

Copied

Well, I tried to run your script to do a test here, just changed the values to my needs, but it immediately returned an error: 

Screenshot 2024-05-31 at 10.20.09.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
Community Expert ,
May 31, 2024 May 31, 2024

Copy link to clipboard

Copied

quote

Well, I tried to run your script to do a test here, just changed the values to my needs, but it immediately returned an error: 

Screenshot 2024-05-31 at 10.20.09.png


By @ril3ydx

 

It looks like the name of the layer you've entered doesn't exist? 

 

But in that case the error should be on the previous line? 

 

Unless missing ";"s are the problem? 

 

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
New Here ,
May 31, 2024 May 31, 2024

Copy link to clipboard

Copied

I tried to change the word in the script for the name on my file, it didn't work.

Then I tried to use the script as it is and just changed my file's layer name to meet that, but it didnt' work either..

Perhaps it's related to the ID version? I'm using 2023

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
Community Expert ,
May 31, 2024 May 31, 2024

Copy link to clipboard

Copied

@ril3ydx

 

Can you post a screenshot similar to the last one @rob day posted - with the image selected and list of layers?

 

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
New Here ,
May 31, 2024 May 31, 2024

Copy link to clipboard

Copied

Screenshot 2024-05-31 at 10.59.19.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
Community Expert ,
May 31, 2024 May 31, 2024

Copy link to clipboard

Copied

@ril3ydx

 

Your layer is in a sub-folder - not in the "root directory". 

 

That's why my tool is more universal and immune to those kind of situations. 

 

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
New Here ,
May 31, 2024 May 31, 2024

Copy link to clipboard

Copied

Yes, it is, I mentioned that in my original post, I need to activate only the group "Modelo" and then in the second link under that, deactivate everything and leave only layer "Sombra" inside the group Fundo.

is that possible?

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
Community Expert ,
May 31, 2024 May 31, 2024

Copy link to clipboard

Copied

quote

Yes, it is, I mentioned that in my original post, I need to activate only the group "Modelo" and then in the second link under that, deactivate everything and leave only layer "Sombra" inside the group Fundo.

is that possible?


By @ril3ydx

 

Yes. But you'll have to wait for @rob day to modify the code.

 

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
Community Expert ,
May 31, 2024 May 31, 2024

Copy link to clipboard

Copied

Is this the code you are running?

 

var ln = "Sombra"
var lnk = app.activeDocument.links.everyItem().getElements()

var obj, dup, sh;
for (var i = 0; i < lnk.length; i++){
    if (lnk[i].parent.constructor.name == "Image") {
        obj = lnk[i].parent.parent
        dup = obj.duplicate();
        sh = dup.images[0].graphicLayerOptions.graphicLayers.itemByName(ln)
        sh.currentVisibility = false;
        obj.transparencySettings.blendingSettings.blendMode = BlendMode.MULTIPLY
    } 
}; 

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
New Here ,
May 31, 2024 May 31, 2024

Copy link to clipboard

Copied

yes

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
Community Expert ,
May 30, 2024 May 30, 2024

Copy link to clipboard

Copied

Are all the images on a layer by themselves?

Only asking cos how to target just those images with layer comps - are they a different file format to all the other files in the document, like PSD for layer comps and TIF for evertyhing else?

 

Just thinking how would the script target.

 

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
Community Expert ,
May 31, 2024 May 31, 2024

Copy link to clipboard

Copied

quote

Are all the images on a layer by themselves?

Only asking cos how to target just those images with layer comps - are they a different file format to all the other files in the document, like PSD for layer comps and TIF for evertyhing else?

 

Just thinking how would the script target.


By @Eugene Tyson

 

Targeting isn't a problem - Image, PDF and INDD have extra property:

RobertatIDTasker_2-1717154003805.png

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#GraphicLayerOption.html

RobertatIDTasker_3-1717154042166.png

 

Then you can get names of the layers and process only links with those layers. 

 

RobertatIDTasker_0-1717153868420.png

 

RobertatIDTasker_1-1717153874489.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
New Here ,
May 31, 2024 May 31, 2024

Copy link to clipboard

Copied

All the images are PSD and they all have the same identical structure and layers.

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
Community Expert ,
Jun 01, 2024 Jun 01, 2024

Copy link to clipboard

Copied

RobertatIDTasker_0-1717251871754.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
New Here ,
Jun 01, 2024 Jun 01, 2024

Copy link to clipboard

Copied

How to adapt this information into the script earlier provided?

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
New Here ,
Jun 01, 2024 Jun 01, 2024

Copy link to clipboard

Copied

I'm trying this approach but i dont know what is wrong,
it does duplicate and set to multiply but it doesnt apply/filter the object layer options:

var folderFundo = "Fundo";
var layerFundoBranco = "Fundo Branco";
var folderModelo = "Modelo";
var lnk = app.activeDocument.links.everyItem().getElements();

for (var i = 0; i < lnk.length; i++) {
if (lnk[i].parent.constructor.name == "Image") {
var obj = lnk[i].parent.parent;

var dup = obj.duplicate();

var graphicLayerOptions = dup.images[0].graphicLayerOptions;

if (i % 2 == 0) {
try {
var fundoFolder = graphicLayerOptions.graphicLayers.itemByName(folderFundo);
if (fundoFolder.isValid && fundoFolder.constructor.name == "GraphicLayerFolder") {
fundoFolder.currentVisibility = false;
}
} catch (e) {}
} else {
try {
var modeloFolder = graphicLayerOptions.graphicLayers.itemByName(folderModelo);
if (modeloFolder.isValid && modeloFolder.constructor.name == "GraphicLayerFolder") {
modeloFolder.currentVisibility = false;
}

var fundoBrancoLayer = graphicLayerOptions.graphicLayers.itemByName(layerFundoBranco);
if (fundoBrancoLayer.isValid && fundoBrancoLayer.constructor.name == "GraphicLayer") {
fundoBrancoLayer.currentVisibility = false;
}

dup.transparencySettings.blendingSettings.blendMode = BlendMode.MULTIPLY;
} catch (e) {}
}
}
}

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
Community Expert ,
Jun 01, 2024 Jun 01, 2024

Copy link to clipboard

Copied

@ril3ydx 

 

"GraphicLayerFolder" is my own "type" that I've created for my own use to be able to let user quickly distinguish between layers and folders.

 

After you check and find your "folder" by name - you can then get a reference to your sub-layer.

 

And you shouldn't make this assumption:

 

if (i % 2 == 0) {

 

There is no guarantee that duplicated image is always 2nd in the collection of all links.

 

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
Community Expert ,
Jun 01, 2024 Jun 01, 2024

Copy link to clipboard

Copied

@ril3ydx 

 

As I'm not JS guy I can only try to help you.

 

After this is "true" - you found your folder:

 

var fundoFolder = graphicLayerOptions.graphicLayers.itemByName(folderFundo);

 

... this should then work and return layer in the folder:

 

var fundoBrancoLayer = fundoFolder.graphicLayers.itemByName(layerFundoBranco);

 

 

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
Community Expert ,
Jun 01, 2024 Jun 01, 2024

Copy link to clipboard

Copied

quote

How to adapt this information into the script earlier provided?


By @ril3ydx

 

I'm doing this by checking if GraphicLayers' GraphicLayers.Count is "> 0" - but in VB it requires recursion and I need to do it that way anyway to get a nice tree-like structure.

 

In JS, without displaying the whole structure, it probably could be done by:

var layers = dup.images[0].graphicLayerOptions.graphicLayers.everyItem().getElements();

and then iterating though all elements?

 

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