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

Get specific Children from MenuItems, Acrobat X

kentbaker
Registered: Jun 6 2008
Posts: 5
Answered

Hello,
 
Thanks in advance for any help.
 
I need to get an array from a specific menu item, and assign a variable to each. There are 50 Children in the menu item. Previously, I could just call the MenuItem as they were static. With current versions of software, the children names sometimes change.
  
So for example only, menu item "Page Navigation"
 
GoTo //menu item name is GoTo, need array of the children
** FirstPage //need to assign var1
** PrevPage //need to assign var2
** NextPage //need to assign var3
** LastPage // and so on.
** GoToPage
** endPageNavGroup
** GoBack
** GoForward
 
Then I would execute the menu item in a priveledged context using the assigned name var1.
 
Thanks for viewing
 

My Product Information:
Acrobat Pro 10.0.2, Windows
UVSAR
Expert
Registered: Oct 29 2008
Posts: 1357
Menus in the Acrobat X Family aren't all created at the moment the application loads, so developers shouldn't rely on the tree returning a predictable set of children - instead you should call the functions by their API name (this.pageNum++ instead of menu>next page).
kentbaker
Registered: Jun 6 2008
Posts: 5
Thanks for the response. I was using the GoTo menu item as an example. It is not what I need to do. I still need to get the un-predictable children of a menu item (generated by a plugin). Since it is not "factory", I do not know how to determine the API name.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Why not just create a list of the menu item language independent name, "Cname" assigned by Adobe or any added menu item by JavaScript or a 3rd party plugin:

function FancyMenuList(m, nLevel)
{
var s = "";
for (var i = 0; i < nLevel; i++) s += " ";
console.println(s + "+-" + m.cName);
if ( m.oChildren != null )
for ( var i = 0; i < m.oChildren.length; i++ )
FancyMenuList(m.oChildren[i], nLevel + 1);
}
var m = app.listMenuItems();
for ( var i=0; i < m.length; i++ ) FancyMenuList(m[i], 0);You can then look up the "Cname" to use in the 'execMenuItem' but there are some items that have been restricted.

Executing Acrobat Menu Items from JavaScript by Thom Parker.I try not use any menu item calls, since they change from version to version and you or a user gets a surprise response that in most cases is easily avoided. With the increased security, you may also need to write special application level functions.

George Kaiser

kentbaker
Registered: Jun 6 2008
Posts: 5
Thanks George,

I can generate a list of ALL the menu items. What I am struggling with is to just get the one I want. If I can get an array of just the children of the menu item I want, make each a variable, then I avoid the un-predictable naming that I am currently experiencing.

i.e acrobat loads and the first child is called menuItem_1 or menuItem_111, I will have assigned a known value to it.

I know I am not explaining myself well enough. In my dreams it would be something like:

var myArray = [app.listToolbarButtons(theMenuItemIwant.oChildren)];

Please stay tuned, I need your help
UVSAR
Expert
Registered: Oct 29 2008
Posts: 1357
Accepted Answer
The global tree returned by app.listMenuItems() is all you have - there is no inbuilt method to list only the sub-tree of a named menu node. You could modify the example from the SDK documentation (as quoted above by George) to search the tree by name and return the children of a specific node, but as I said before they may not always be there from the instant Acrobat loads.

If a C++ plugin populates a menu or toolbar, it should ideally expose the same functions via the JS API to avoid developers needing to call the menus by name. If it's a scripted extension, you can and should call the functions directly by looking at the script and replicating whatever command(s) it assigns to each menu item.