Scripting | graphicLayerOptions : Changing visibility of graphicLayer will change ID number of placed graphic
Problem Description:
If you change the visibility of a graphicLayer of a placed graphic, could be a PDF, a PSD, an InDesign page or a AI file, the ID number of the placed graphic will change. The result of this is, that "everyItem().doSomething" with object graphicLayer will not work at all.
Steps to Reproduce:
1. Place a graphic with some graphic layers.
2. Access the graphic layers of the graphic by scripting and try to change eg. currentVisibility for all graphic layers in one go.
Frame holding the graphic is selected. The script snippet below should do this easily. However, it is not!
Note:
In case of a placed InDesign page or a PDF exported from an InDesign document with layers intact, all InDesign layers are nested in one "layer group" so we have to look after graphicLayers[0] (that's the "layer group") and add graphicLayers.everyItem() to access all sub-layers.
app.selection[0].graphics[0].graphicLayerOptions.graphicLayers[0].graphicLayers.everyItem().currentVisibility = false;
Actual Result:
Error message thrown. In my German InDesign this is:
"Die angeforderte Aktion konnte nicht ausgeführt werden, da das Objekt nicht mehr existiert."
This is the $ID/ObjectDeletedError
Expected Result:
No error message. The visibility of all graphic layers should change.
Any Workarounds:
Loop the graphic layers. But do so that every time you do not access a reference to the graphic by its ID number.
Something like that will work:
var layerLength = app.selection[0].graphics[0].graphicLayerOptions.graphicLayers[0].graphicLayers.length;
for(var n=0;n<layerLength;n++)
{
$.writeln( n+"\t"+app.selection[0].graphics[0].id );
app.selection[0].graphics[0].graphicLayerOptions.graphicLayers[0].graphicLayers[n].currentVisibility = false;
};
The following will NOT work:
var graphicLayers = app.selection[0].graphics[0].graphicLayerOptions.graphicLayers[0].graphicLayers.everyItem().getElements();
for(var n=0;n<graphicLayers.length ;n++)
{
graphicLayers[n].currentVisibility = false;
};
Why will that not work?
See into the results in the JavaScript Console with $.writeln( n+"\t"+app.selection[0].graphics[0].id ); from the loop that is working.
Everytime you change currentVisibility of a graphicLayer the ID of the graphic is changing. That means the object is not itself anymore.
Here some sample output from the JavaScript Console with one of my sample files:
/*
Result:
0 325
1 331
2 337
3 343
4 349
*/
You can see that the graphic began with a ID number of 325, after changing currentVisibility of the first graphic layer it suddenly became ID 331 and so on.
Read about this scripting issue in the InDesign Scripting Forum here:
"Place specific pdf layer into indesign with javascript"
Yuliascript 18.06.2018
https://forums.adobe.com/message/10452540#10452540
Also here a thread from 2012:
"Activating object layers basing on document layers"
Marco Lugli 14.12.2012
https://forums.adobe.com/message/4920745#4920745
Also see attached documents with a placed sample PDF:
PlacedPDFwithLayers-13.1.0.76.zip
Download link from my Dropbox:
https://www.dropbox.com/s/hfsspv5ddxaakvy/PlacedPDFwithLayers-13.1.0.76.zip?dl=0
FWIW: Did this bug report also at Bug ID - ID-4208697.
Regards,
Uwe Laubender
( ACP )
Thanks for reporting the issue. We are reviewing it
-InDesign Team
-
Uwe Laubender commented
Also see:
Relink multiple images in one go
Jon Hidden-Coley
Mar 05, 2020
https://community.adobe.com/t5/indesign-discussions/relink-multiple-images-in-one-go/td-p/10964659Regards,
Uwe Laubender
( Adobe Community Expert ) -
Uwe Laubender commented
NOTE: For this thread from 2012 use the link below, the one I posted is not valid anymore in the current Adobe InDesign Forum:
"Activating object layers basing on document layers"
Marco_Lugli, Dec 14, 2012
https://community.adobe.com/t5/indesign/activating-object-layers-basing-on-document-layers/td-p/4653912Regards,
Uwe Laubender
( ACP )