Skip navigation
kdeemer
Currently Being Moderated

Help Adding Menu Items to Bridge

Mar 4, 2012 9:05 PM

I've created (modified) a couple of Bridge Scripts and finally have them working nicely. Now, I want to add a couple of Menu Commands to execute them. I tried modifying a script in the SDK, SnpAddMenuItem.jsx, which would work fine if I only had one Menu Item/Command. Here is what I have. I obviously don't understand the 'this' object or how to separate the Commands. Help much appreciated.

 

 

 

function SnpAddMenuItem()

{

          this.requiredContext = "\tAdobe Bridge must be running.\n\tExecute against Bridge CS5 as the target.\n";

          this.menuID = "snpAddMenuItem";

          this.menuCommandID = "snpAddMenuItemSub";

 

          $.level = 1; // Debugging level

}

SnpAddMenuItem.prototype.run = function()

{

          var retval = true;

          if(!this.canRun()) {

                    retval = false;

                    return retval;

          }

    var newMenu = new MenuElement( "menu", "Scanning", "after Window", this.menuID );

    var stackCommand = new MenuElement( "command", "Gather NNYY Into Stacks", "at the end of " + this.menuID, this.menuCommandID );

    var maskCommand = new MenuElement( "command", "Process Stacks into Layers", "at the end of " + this.menuID, this.menuCommandID );

          stackCommand.onSelect = function()

          {

                    var scriptFilePath = "~/Documents/Adobe Scripts/AutostackNNYY.jsx";

         var scriptFile = new File (scriptFilePath);

         $.evalFile( scriptFile );

          }

    return retval;

          maskCommand.onSelect = function()

          {

                    var scriptFilePath = "~/Documents/Adobe Scripts/StacksToLayers.jsx";

         var scriptFile = new File (scriptFilePath);

         $.evalFile( scriptFile );

          }

          return retval;

}

 

 

/**

  Determines whether snippet can be run given current context.  The snippet

  fails if these preconditions are not met:

  <ul>

  <li> Must be running in Bridge

  <li> Must only be executed once in a session

  </ul>

 

  @return True if this snippet can run, false otherwise

  @type boolean

*/

SnpAddMenuItem.prototype.canRun = function()

{

          // Must run in Bridge

          if(BridgeTalk.appName == "bridge") {

 

                    // Stop the menu element from being added again if the snippet has already run

                    if((MenuElement.find(this.menuID)) && (MenuElement.find(this.menuCommandID)))

                    {

                              $.writeln("Error:Menu element already exists!\nRestart Bridge to run this snippet again.");

                              return false;

                    }

 

                    return true;

          }

 

          // Fail if these preconditions are not met. 

          // Bridge must be running,

          // The menu must not already exist.

          $.writeln("ERROR:: Cannot run SnpAddMenuItem");

          $.writeln(this.requiredContext);

          return false;

}

 

 

/**

  "main program": construct an anonymous instance and run it,

  as long as we are not unit-testing this snippet.

*/

if(typeof(SnpAddMenuItem_unitTest ) == "undefined") {

          new SnpAddMenuItem().run();

}

 
Replies
  • Currently Being Moderated
    Mar 5, 2012 12:53 AM   in reply to kdeemer

    This will put the two commands at the bottom of the Tools menu....

     

     

    #target bridge   
       if( BridgeTalk.appName == "bridge" ) {  
    var stackCommand = new MenuElement( "command", "Gather NNYY Into Stacks", "at the end of Tools","uniqueId1");
    var maskCommand = new MenuElement( "command", "Process Stacks into Layers","at the end of Tools","uniqueId2");
    }
    stackCommand.onSelect = function () { 
    //Your code goes here
    }
    maskCommand.onSelect = function () { 
    //Your code goes here
    }
    
    
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 5, 2012 1:48 AM   in reply to Paul Riggott

    And using "-at the end of Tools" would add UI dividers if you want them… Hyphen before = above, after = below…

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points