These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Persistent or global variable

StevenD
Registered: Oct 6 2006
Posts: 368

I'm trying to figure out how to get a value in a field in a custom dialog to stick each time the dialog script is run until it is changed. Then when the script is run again the new value is there.
 
I'm not getting it.

StevenD

My Product Information:
Acrobat Pro Extended 9.4.3, Windows
UVSAR
Expert
Registered: Oct 29 2008
Posts: 1357
As per the Acrobat SDK documentation:

global.radius = 8; // Declare radius to be a global variable
global.setPersistent("radius", true); // Now say it’s persistent across sessions

(some time later...)

console.println("The value of global.radius is" + global.radius);


(and to kill it...)

delete global.radius;


Note that you can only set persistence on booleans, numbers and strings; and there's a very small storage limit.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Hi Steven,
The dialog value is getting re-initialized for one of two reasons.

1. The entire dialog object is being recreated
2. the "initialize" member of the dialog object is setting the value.

For #1, make sure the dialog object is defined only once. If this is a document, then the dialog object should be defined in a document level script, if this is a folder level script, then the dialog object should be defined in the main body of code, not within a function.

If #2 is the issue, make sure value acquired when the dialog is closed, is then used to initialize the dialog field when it is restarted. I do this by adding a member to the dialog object for each value that will be passed in and out of the dialog. This member is used to initialize the dialog values and to capture the value on close. If the dialog object is not reinitialized, then this value remains stable.






Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

StevenD
Registered: Oct 6 2006
Posts: 368
Thanks guys for the responses. I'm afraid I'm not as proficient at coding as you guys so I'm struggling trying to make sense of this stuff. Thanks for the input.

I'm trying to create own PDF Splitter and am running the current version as a batch in Acrobat 9 and eventually want to run it via a tool bar button.

StevenD

StevenD
Registered: Oct 6 2006
Posts: 368
Is there an example that shows how #2 works that I can look at and try to decipher?

StevenD

Jack Sparrow
Registered: Dec 7 2011
Posts: 2
Per your question about adding a toolbar button to Acrobat. See Thom's post:

Executing Acrobat Menu Items from JavaScript.by Thom Parker
¯
Jun 30, 2008
Topics: JavaScript
http://acrobatusers.com/tutorials/2008/06/executing_menu_items_from_javascript

Search this forum and read to learn is my advice. It has helped me out immensely.

I've created a lot of buttons (really labels) to the Add-on Tools Toolbar to automate many redundant procedures.

Jack