Scripting | graphicLayerOptions : Changing visibility of graphicLayer will change ID number of placed graphic
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!
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 (that's the "layer group") and add graphicLayers.everyItem() to access all sub-layers.
app.selection.graphics.graphicLayerOptions.graphicLayers.graphicLayers.everyItem().currentVisibility = false;
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
No error message. The visibility of all graphic layers should change.
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.graphics.graphicLayerOptions.graphicLayers.graphicLayers.length;
$.writeln( n+"\t"+app.selection.graphics.id );
app.selection.graphics.graphicLayerOptions.graphicLayers.graphicLayers[n].currentVisibility = false;
The following will NOT work:
var graphicLayers = app.selection.graphics.graphicLayerOptions.graphicLayers.graphicLayers.everyItem().getElements();
for(var n=0;n<graphicLayers.length ;n++)
graphicLayers[n].currentVisibility = false;
Why will that not work?
Everytime you change currentVisibility of a graphicLayer the ID of the graphic is changing. That means the object is not itself anymore.
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:
Also here a thread from 2012:
"Activating object layers basing on document layers"
Marco Lugli 14.12.2012
Also see attached documents with a placed sample PDF:
Download link from my Dropbox:
FWIW: Did this bug report also at Bug ID - ID-4208697.
( ACP )
Thanks for reporting the issue. We are reviewing it