• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

JavaScript Help

Community Beginner ,
Jul 22, 2019 Jul 22, 2019

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.name == "Layer 1" ||

     docOCGs.name == "Layer 1")

          {

                    docOCGs.state = !docOCGs.state;

          }

}

Thank you.

TOPICS
Acrobat SDK and JavaScript

Views

333

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 22, 2019 Jul 22, 2019

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.state =false;

     if (docOCGs.name == "LayerNameWeAreLookingFor") {

          docOCGs.state = true;

     }

}

Hope this helps

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 22, 2019 Jul 22, 2019

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");

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 22, 2019 Jul 22, 2019

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 22, 2019 Jul 22, 2019

Copy link to clipboard

Copied

Did you adjust the name of the layer you want to show inside the quotes?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 22, 2019 Jul 22, 2019

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 22, 2019 Jul 22, 2019

Copy link to clipboard

Copied

Do you want to toggle ​all​ other layers, or just some?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 22, 2019 Jul 22, 2019

Copy link to clipboard

Copied

Just some please

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 22, 2019 Jul 22, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 24, 2019 Jul 24, 2019

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 24, 2019 Jul 24, 2019

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

LATEST

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines