Copy link to clipboard
Copied
Hi there, Could someone help me correctly write a javascript. What i want to do is get the layers to switch between themselves when another layer is toggled on. So when toggling through the layers they don't all stay on but rather switch between them.
This is the script I have so far,
var docOCGs = this.getOCGs();
for (var x=0; x < docOCGs.length; x++)
{
if(docOCGs
docOCGs
{
docOCGs
}
}
Thank you.
Copy link to clipboard
Copied
Hi,
I have not been able to test this, but could you not do something like.
var docOCGs = this.getOCGs();
for (var x=0; x < docOCGs.length; x++)
{
// make then all hidden
docOCGs
if (docOCGs
docOCGs
}
}
Hope this helps
Copy link to clipboard
Copied
This should work, but you can improve and simplify the code a bit by replacing these lines:
docOCGs
.state =false; if (docOCGs
.name == "LayerNameWeAreLookingFor") { docOCGs
.state = true; }
With just:
docOCGs
.state = (docOCGs .name == "LayerNameWeAreLookingFor");
Copy link to clipboard
Copied
Thank you but this code makes everything disappear including my template layer. It also doesn't toggle the layer off when i click on the next box. Am i doing something wrong?
Copy link to clipboard
Copied
Did you adjust the name of the layer you want to show inside the quotes?
Copy link to clipboard
Copied
Yeah i changed it to the layer i want to be toggled on and off when selecting the next layer box
Copy link to clipboard
Copied
Do you want to toggle ​all​ other layers, or just some?
Copy link to clipboard
Copied
Just some please
Copy link to clipboard
Copied
That requires a more complex script. You'll need to define a list of layers to show/hide, or of ones to ignore, and use that for in the loop.
Copy link to clipboard
Copied
I have no experience with Javascripts as I'm sure you can tell. Could you please help me with that?
Copy link to clipboard
Copied
I hope this does not come as a surprise to you, but you cannot program in JavaScript without knowing about the language. The good news is that it's not too complex to learn the basics, where it then gets more complex is to learn about the application specific functions (like e.g. layers in Acrobat). You also cannot copy and paste your way to a working solution, so do yourself a favor and start to learn JavaScript. You can find out how to do that here: Learning to Program JavaScript for Adobe Acrobat - KHKonsulting LLC
If this is the only JavaScript project you think you'll be working on for a long time, it may be easier and cheaper to just pay somebody to do this job for you.
Copy link to clipboard
Copied
I am starting to learn Javascript with some online courses and videos as i will be using javascript more frequently in the future as this is my first project of many to come. Thank you for the link its much appreciated!