Function to control page specific layers

Engaged ,
Nov 27, 2018

Copy link to clipboard

Copied

I am running this at the document level and it is being executed by a bookmark calling the function.

function oneFourOne() {

    var ocgSchematicArray = this.getOCGs(this.pageNum);

    // Look through all the layers on this page

    for (var i = 0; i < ocgSchematicArray.length; i++) {

        // Find the layer name that matches the defined wire color

        if (ocgSchematicArray.name == "141 (Lt Orange)") {

            // If the layer is turned on...

            if (ocgSchematicArray.state == true) {

                // Turn the layer off

                ocgSchematicArray.state = false;

            }

            // If the layer is turned off...

            else if (ocgSchematicArray.state == false) {

                // Turn the layer on

                ocgSchematicArray.state = true;

            }

        }

    }

}

If I have 2 different bookmarks and this layer exist on 2 different pages... can I make it so the function is only controlling the specific page the layer is on?

So in the picture above the 141 - Page 2 and 141 - Page 4 currently run the function oneFourOne();

I know my script is allowing it to currently turn layers on and off no matter what page. I am wanting to make it specific.

If I am on page 4 and click the 141 - Page 2 button... I don't want it to turn off the layer on that page.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

128

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Most Valuable Participant ,
Nov 27, 2018

Copy link to clipboard

Copied

Your script doesn't turn layers on or off no matter what page they're on. It does so to the current page that is being viewed.

That's done by the parameter you provide to the getOCGs method (line #2).

If you want it to be a specific page number, instead of the current page, then change it from:

this.getOCGs(this.pageNum);

To something like:

this.getOCGs(1);

The code above will only retrieve the layers on page 2 (note the numbers are zero-based).

You might want to pass that value as an argument to the function itself, which will make it possible to re-use it for multiple bookmarks.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Nov 27, 2018

Copy link to clipboard

Copied

You use this.getOCGs(this.pageNum);

This returns all layers on the current page. Looks like that you must change your function.

Likes

Translate

Translate

Report

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