2 Replies Latest reply on Nov 3, 2012 3:46 PM by frameexpert

    Change a command’s position on a menu?

    Dave_009

      Hi Everyone

       

      I wrote a little Script to let FrameMaker 10 user save Version 8 fm-Files.

      The Script works good so far, but the Command is not placed a the position in the Menu where I like to have it (after the Save in the File Menu). Do I do something wrong with the PrevMenuItemInMenu?:

      var fileMenu = app.GetNamedMenu("FileMenu")
      var saveAsCmd = app.GetNamedCommand("Save");
      var newCmd=DefineCommand(1,"Save As fm 8.0" ,"Save As fm 8.0","")
      fileMenu.AddCommandToMenu(newCmd)
      newCmd.PrevMenuItemInMenu = saveAsCmd;
      
      UpdateMenus();
      
      function Command(cmd){
          switch(cmd) {
              case 1:
                  var file;
                  file  = app.ActiveBook;
                  if (!file.ObjectValid()) {
                      file = app.ActiveDoc;
                      if (!file.ObjectValid()) {
                          Alert("No active document or book found", Constants.FF_ALERT_CONTINUE_NOTE);
                      }  
                  }
                  var params = GetSaveDefaultParams();
                  var returnParamsp =new PropVals();
                  var i = GetPropIndex(params, Constants.FS_FileType);
                  params[i].propVal.ival =Constants.FV_SaveFmtBinary80;
                  file.Save(file.Name, params, returnParamsp);
                  break;
              }
      } 
      

       

      Thanks!

        • 1. Re: Change a command’s position on a menu?
          4everJang Level 3

          It seems like you cannot do this via scripting. I tried to do the entire relinking of previous and next commands before updating the menus but that gives the same result. What is still open is the option to configure a different menu set via the menu configuration files. Or creating a new menu and adding all menus from the current File menu to that new one, pushing your own command in at the right time, tne removing the old File menu. It may be a lot of work but it should be doable that way.

           

          It seems to me like Adobe needs to build some capability here for us scripters. It should not be too difficult for their programmers to add an option to AddCommandToMenu that will allow the user to specify after which menu item the new command (or submenu or separator) should go.

          • 2. Re: Change a command’s position on a menu?
            frameexpert Level 4

            I think the disconnect is that a single command can be on multiple menus. So, when you have this:

             

            var saveAsCmd = app.GetNamedCommand("Save"); 
            

             

            you get the Save command object. But before you can move it, you have to be able to specify which menu it is on. This is how it is done with FrameScript:

             

            Get Object Type(Command) Name('Save') NewVar(saveAsCmd);
            Get Object Type(Menu) Name('FileMenu') NewVar(fileMenu);
            New Command Name('SaveAsFm8') Label('Save As FM 8...') 
              NewVar(newCmd) EventProc(SaveAsFm8); 
            // Here is the missing item in ExtendScript. This identifies which 
            // menu the Save command is on before you move the new 
            // command relative to it.
            Set saveAsCmd.Menu = fileMenu;
            Set newCmd.PrevMenuItemInMenu = saveAsCmd;
            

             

            The FDK is similar in that it provides a way to identify the menu object that the existing command is on:

             

            saveAsCmd = F_ApiGetNamedObject(FV_SessionId, FO_Command, "Save");
            fileMenu = F_ApiGetNamedObject(FV_SessionId, FO_Menu, "FileMenu");
            newCmd = F_ApiDefineCommand(1, "SaveAsFm8",  "Save As FM8...", "");
            F_ApiAddCommandToMenu(fileMenu, newCmd);
            // Move the command so that it comes right after Save.
            // Notice the parent File menu is specified in the command below.
            F_ApiSetId(fileMenu, newCmd, FP_PrevMenuItemInMenu, saveAsCmd);
            

            So it appears that the missing link is the ability to specify the parent menu of the existing command. Hopefully, someone from Adobe can confirm this, and if it is the case, they can provide a fix.

             

            Rick