Adobe 0046100128056 Scripting Guide - Page 135
graphic, and to avoid adding multiple menu choices to the context menu.
UPC - 718659087562
View all Adobe 0046100128056 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 135 highlights
CHAPTER 9: Menus A More Complex Menu-scripting Example 135 graphic, and to avoid adding multiple menu choices to the context menu. The eventListener then checks the selection to see if it contains a graphic; if so, it creates a new scriptMenuItem. //The locale-independent name (aka "key string") for the //Layout context menu is "$ID/RtMouseLayout". var myLayoutContextMenu = app.menus.item("$ID/RtMouseLayout"); //Create the event handler for the "beforeDisplay" //event of the Layout context menu. var myBeforeDisplayListener = myLayoutContextMenu.addEventListener ("beforeDisplay", myBeforeDisplayHandler, false); //This event handler checks the type of the selection. //If a graphic is selected, the event handler adds the script menu //action to the menu. function myBeforeDisplayHandler(myEvent){ if(app.documents.length != 0){ if(app.selection.length > 0){ var myObjectList = new Array; //Does the selection contain any graphics? for(var myCounter = 0; myCounter < app.selection.length; myCounter ++){ switch(app.selection[myCounter].constructor.name){ case "PDF": case "EPS": case "Image": myObjectList.push(app.selection[myCounter]); break; case "Rectangle": case "Oval": case "Polygon": if(app.selection[myCounter].graphics.length != 0){ myObjectList.push(app.selection[myCounter]. graphics.item(0)); } break; default: } } if(myObjectList.length > 0){ //Add the menu item if it does not already exist. if(myCheckForMenuItem(myLayoutContextMenu, "Create Graphic Label") == false){ myMakeLabelGraphicMenuItem(); } } else{ //Remove the menu item, if it exists. if(myCheckForMenuItem(myLayoutContextMenu, "Create Graphic Label") == true){ myLayoutContextMenu.menuItems.item("Create Graphic Label").remove(); } } } } function myMakeLabelGraphicMenuItem(){ //alert("Got to the myMakeLabelGraphicMenuItem function!"); if(myCheckForScriptMenuItem("Create Graphic Label") == false){ //alert("Making a new script menu action!"); var myLabelGraphicMenuAction = app.scriptMenuActions.add("Create Graphic Label");