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?
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.
Copy link to clipboard
Copied
It's a "real" shadow from the image, not generated
Copy link to clipboard
Copied
What with the names of the layers?
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.
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
}
};
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:
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:
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?
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
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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.
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?
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?
By @ril3ydx
Yes. But you'll have to wait for @rob day to modify the code.
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
}
};
Copy link to clipboard
Copied
yes
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.
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.
By @Eugene Tyson
Targeting isn't a problem - Image, PDF and INDD have extra property:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#GraphicLayerOption.html
Then you can get names of the layers and process only links with those layers.
Copy link to clipboard
Copied
All the images are PSD and they all have the same identical structure and layers.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
How to adapt this information into the script earlier provided?
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) {}
}
}
}
Copy link to clipboard
Copied
"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.
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
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?