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

folder level script not recognizing open docs

AndrewAlb
Registered: Aug 16 2007
Posts: 97

I am having difficulty with a folder level script. I created a function to count all fields except buttons. In the debugger console it works fine. The problem however is that when I put the function in a folder level script and then call it from a menu item I created it returns a zero because it does not acknowledge my document(s) being opened.
 
I tested this also with app.activeDocs and I get a 0. I added the following to the function at the very beginning:
 
var a = app.activeDocs;
app.alert(a.length);
 
It returns 0 whether I have 1 or 5 files open.
  
I put the script in the app js folder but I also tried it in the user js folder.
 
I have tried "this." as well as "app.doc" syntax - but the bigger problem is that it is not recognizing document(s) being open at all.
 
can you think of any reason why this might be? Like I said it is not the code because it works fine from the debugger the problem is that the application does not recognize a document being open. I have run out of ideas...
 
might there be an issue with the order I put the functions in the file?
The order I use is as follows -
 
1) add menus
2) add individual functions
3) add function to call a group of functions (this is what my menu item enters and then calls the function - none of other functions work for the same reason but I starting with this one).
 
here is the code I am using:
  
function customcount()
{
/*custom function to count all fields except buttons. */
var dct = 0
for (var i = 0; i < this.numFields; i++)
{
 
var fname = this.getNthFieldName(i);
var f = this.getField(fname)
if (f.type !="button" )
{dct = dct++}
}
return (dct);
};

Andrew D. Albrecht, MS
Solutions Developer
ING USFS

My Product Information:
Acrobat Pro 8, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
app.activeDocs returns an array of "disclosed" documents. All the other documents are off limits for security reasons.

However, the "this" keyword should work just fine for your purpose.

As as far as ordering goes, the definitions should preceed any active code. For example, you should create the menu items last.


Here are some things to think about

1. Are you sure the functions is even being called? Place a console.println() statement in the function code.

2. What kind of error messages are you getting in the console window?

3. What happens when the "customcount()" function is defined in a folder level script and then called from the console window? Does the function exists? was there an error somewhere else that prevented the function from even being defined.

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