Copy link to clipboard
Copied
I have 30 layers that I created in InDesign and exported to PDF (multiple pages). I created a dropdown menu with corresponding item lists. I want to be able to show only the layer selected from the dropdown list (plus keep the main header layer active at all times). I found this post that almost worked for me, but it kept previously selected layers active once I changed the selection. I need the the other layers to hide if the selection changes. Thank you for your time, and please take it easy on me, this is my first attempt at Javascript!
That code should have worked in your case... Try this version of it, instead:
var ocgs = this.getOCGs();
if (ocgs) {
for (var i in ocgs) {
ocgs[i].state = (ocgs[i].name==event.value);
}
}
Place this code as the custom validation script of the drop-down field and make sure to tick the option to commit the selected value immediately (under the Options tab).
[Edited: Code fixed]
Copy link to clipboard
Copied
That code should have worked in your case... Try this version of it, instead:
var ocgs = this.getOCGs();
if (ocgs) {
for (var i in ocgs) {
ocgs[i].state = (ocgs[i].name==event.value);
}
}
Place this code as the custom validation script of the drop-down field and make sure to tick the option to commit the selected value immediately (under the Options tab).
[Edited: Code fixed]
Copy link to clipboard
Copied
Thank you! Is there any way to make one of the 30 layers stay visible at all times?
Copy link to clipboard
Copied
Sure. You can add something like this before line #4 above:
if (ocgs[i].name=="Layer0") continue;
Copy link to clipboard
Copied
You have just remedied hours of searching and trial/error on my end. Much appreciated.
Copy link to clipboard
Copied
Just to confirm, with this code, when I select an item in my drop-down list, it can pull-up the info/image I have on a specific layer, right? If so, within this code, where do the names of the items in your drop-down list go, and where do the names of the layers go? I need to make the same thing happen, but don't know anything about JavaScript. TIA!
Copy link to clipboard
Copied
They don't go anywhere. The code above assumes the items in the drop-down match the names of the layers.
If that's not the case, the code will have to be adjusted accordingly.
Copy link to clipboard
Copied
Thx! That should have made it easier, but I still can't get it to work. My drop-down item and layer names are the same and I've selected "commit the selected value immediately". I copied and pasted the code into the Validate Tab, under "Run custom validation script". Are there any other sections in the Properties Menu that need to be updated to make this code work? I'm working with Acrobat Pro 2017, just in case that's relevent. TIA!
Copy link to clipboard
Copied
No, that should be enough. Can you share the file?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Sorry, my bad. There was an error in the code I posted earlier. I fixed it now. Copy it again and try again.
Copy link to clipboard
Copied
That's it! It works great 🙂 Thanks so much for the quick responses, it's good to know the community has such great support.