Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
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

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
1.7K
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
LEGEND ,
May 30, 2024 May 30, 2024

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.

 

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

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

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

What with the names of the layers?

 

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

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.

 

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

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.pngexpand imageScreen Shot 37.pngexpand image

 

 

Screen Shot 39.pngexpand image

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

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.pngexpand image

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
LEGEND ,
May 31, 2024 May 31, 2024
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.pngexpand image


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? 

 

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

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

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

@ril3ydx

 

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

 

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

Screenshot 2024-05-31 at 10.59.19.pngexpand image

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

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

 

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

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?

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
LEGEND ,
May 31, 2024 May 31, 2024
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.

 

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

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

yes

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

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.

 

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
LEGEND ,
May 31, 2024 May 31, 2024
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.pngexpand image

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

RobertatIDTasker_3-1717154042166.pngexpand image

 

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

 

RobertatIDTasker_0-1717153868420.pngexpand image

 

RobertatIDTasker_1-1717153874489.pngexpand image

 

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

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

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

RobertatIDTasker_0-1717251871754.pngexpand image

 

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

How to adapt this information into the script earlier provided?

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

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) {}
}
}
}

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

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

 

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

@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);

 

 

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
LEGEND ,
Jun 01, 2024 Jun 01, 2024
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?

 

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