Copy link to clipboard
Copied
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.
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
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
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!!
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
Hi there Joel and again thanks for the follow up. I did copy the above java script into a new action. When I run the action it shows the file to be processed and then when I hit the start it does executes the code and shows as "complete". However all the layers are still set to "on" when I right click on the layer to open up the layer properties. The Default state is still showing On for each layer. Below is a screen shot of the outcome after I run the script. This is showing Layer 1 but all the layers are showing the same. I am not sure if there is something that I should be doing in addition to the script, if you have any suggestions I would greatly appreciate it since the PDF files do contain just over a hundred different layers and it is very time consuming to open each layer and switch the default state to off!
Copy link to clipboard
Copied
Are you checking the JavaScript console for errors?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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).
Copy link to clipboard
Copied
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