Skip to main content
Participant
October 10, 2018
Answered

Layer Properties - Default State always OFF

  • October 10, 2018
  • 4 replies
  • 2072 views

I would like to see if anyone is able to provide some assistance with configuring the Default State within the Layer Properties to always be "off".  I create PDF's from AutoCAD that contain several layers (more than 50) that I would like for them to initially be turned off and then have the option to turn them on one at a time.  Currently when I create the PDF's I manually go into the layer property for each layer and manually set the Default State to OFF.  However this is very time consuming and when modifications are needed to the project and new PDF's are created this process is started all over again.  Thus taking hours to perform a simple task.  I am hoping that there is someone that can provide some assistance with how to automate this simple task or maybe there is a configuration setting that I just have not discovered to set this value to off as a standard default setting.

This topic has been closed for replies.
Correct answer timl_TMD-Design

Great news!!  I actually did get it to work but had to use the original code and modify it just slightly.  Below is what I have used successfully!

var doc=app.activeDocs[0];

var ocgArray = doc.getOCGs();

for (var i = 1; i < ocgArray.length; i++) {

    ocgArray.state = false;

    ocgArray.initState = false;

}

Thank you to all of you for the help and assistance in this!  This is a huge time saver!!!!!!!!!!

Thanks

Tim

4 replies

timl_TMD-DesignAuthorCorrect answer
Participant
October 15, 2018

Great news!!  I actually did get it to work but had to use the original code and modify it just slightly.  Below is what I have used successfully!

var doc=app.activeDocs[0];

var ocgArray = doc.getOCGs();

for (var i = 1; i < ocgArray.length; i++) {

    ocgArray.state = false;

    ocgArray.initState = false;

}

Thank you to all of you for the help and assistance in this!  This is a huge time saver!!!!!!!!!!

Thanks

Tim

Participant
October 15, 2018

thanks for all the help.  Unfortunately nothing has worked!  This is so very frustrating that what appears to be a simple setting is not so simple!!  Thanks again for those that have tried to offer their assistance.

Karl Heinz  Kremer
Community Expert
Community Expert
October 15, 2018

Based on what I've seen in the previous answers, this should have worked - assuming you had a correct "doc" variable. Depending on how you use this, you may be able to just replace "doc" with "this". That would work for example when you run the code in the JavaScript console, or in a custom command or an action.

In which context are you running the script?

TSN was asking for any potential error messages in the Javascript console. Do you see any error messages? You can bring up the console using Ctrl-J (or Cmd-J on a Mac).

BarlaeDC
Community Expert
Community Expert
October 14, 2018

HI,

I think there needs to be an additional line of code as the variable "doc" is not defined.

I think you need to add this code at the start of the code.

var doc = app.activeDocs[0];

Hope this helps

Malcolm

Joel Geraci
Community Expert
Community Expert
October 10, 2018

Add the following code to an Acrobat Action or Custom Command

var ocgArray = doc.getOCGs();

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

    ocgArray.initState.constants.states.off;

}

Participant
October 10, 2018

Thanks Joel for the assistance.  Unfortunately the code did not work as I was hoping.  I am actually not sure what it has done to the PDF.  When I took the code and created a Custom Command with this code and ran it on the PDF the layers are still set to be “On” under the Layer Properties – Default State.  This is what I was hoping to be able to have some code that would turn every layer (all with unique names) to the “Off” state.  Currently I have to click on each layer and go into the layer properties and turn each one from “On” to “Off”.  This is very much time consuming!!

Joel Geraci
Community Expert
Community Expert
October 10, 2018

Well, that'll teach me to copy code directly out of the documentation without testing it.

The code below works. You will need to have at least one OCG on by default but this will turn all of them off except the first.

var ocgArray = doc.getOCGs();

for (var i = 1; i < ocgArray.length; i++) {

    app.alert(ocgArray.name)

    ocgArray.state = false;

    ocgArray.initState = false;

}