9 Replies Latest reply on Sep 1, 2015 10:41 AM by DrDaveJ

    RemoveMenu, not working

    DrDaveJ

      Whether I AutoRun at startup, or wait and run manually when needed,

      I add a menu to the main menu bar with this:

      //Create menu

      var myMenu = DefineMenu("Daves_ScriptingMenu", "Dave's Scripts");

      //Get the main FM document menu, so we can

      //add our custom menu, then add it.

      var fmMenu = app.GetNamedMenu ("!MakerMainMenu");

      fmMenu.AddMenuToMenu (myMenu);

      . . . I add commands, etc. that are working.

       

      The problem is removing the menu when I don't want it there.

      I'm trying this code. It appears to run, but nothing happens. And there are no

      messages generated in the Console.

      Notice I tried using the menu name as well as its label.

       

      //Get the main FM document menu, and then remove custom menu.

      var fmMenu = app.GetNamedMenu ("!MakerMainMenu");

      //Using Label

      RemoveMenu(fmMenu, "Dave's Scripts");

      //Using Name

      //RemoveMenu(fmMenu, "Daves_ScriptingMenu");

      UpdateMenus();

       

       

      Can I get a hint as to what's up here?

      Thanks,

      Dave

        • 1. Re: RemoveMenu, not working
          Russ Ward Level 4

          Dave,

           

          Some time ago, I had a similar frustration with deleting commands (that is, it didn't work). See the following post... there is a link to an FM12 patch release notes that might be informative. But I'm not sure because I never got the patch   You don't mention your version of FM, so I don't know if this will be helpful or not.

           

          Command object Delete() and CommandNum property issues

           

          Russ

          • 2. Re: RemoveMenu, not working
            DrDaveJ Level 1

            Running FM v12.0.4.445 on Win 7 pc.

            When I run the script using Run Button in script catalog, it would register my click, but nothing happened.

            Now, thinking maybe there are issues with the Script Library/Catalog, I run the script from within the Editor.

            This generates an error I had not noticed previously:

            "app.GetNamedMenu is not a function"

            However, according to the scripting guide (last updated 4/8/2014), I have this syntax correct. The line is shown in my initial post.

             

            Help please?

            Thanks,

            Dave

            • 4. Re: RemoveMenu, not working
              Russ Ward Level 4

              Dave, I can't duplicate the problem with app.GetNamedMenu(). I even copied the line directly from your post and ran it... worked fine. Are you still having the problem?

               

              Russ

              • 5. Re: RemoveMenu, not working
                DrDaveJ Level 1

                Yes, still stuck here. Here are my test conditions.

                _The menu I want to remove can get added via

                AutoRun or added manually. Results below are the same either way.

                _I can run from the Editor, with FMv12 set as connected target; and/or run from

                File Menu > Script > Run.

                _Below is  four ways I've tried to remove the daves menu.

                 

                *In all cases, the script will run, but the menu does not get removed. They all generate the console message in the editor, "Result: undefined".

                 

                (1)

                //Oiriginal attempt, using Daves Menu Label. Also tried using Menu NAME.

                var fmMenu = app.GetNamedMenu("!MakerMainMenu");

                RemoveMenu("!MakerMainMenu", "Dave's Scripts"); //Daves Menu LABEL

                fmDavesMenu.delete();  //Causes Error: "fmDavesMenu.delete is not a function".  Tried this line in all versions.

                //  In all cases, they all run without this line, but do not remove the menu.

                UpdateMenus();

                 

                (2)

                //Loading var's then addressing them to remove menu

                var fmMenu = app.GetNamedMenu("!MakerMainMenu");

                var fmDavesMenu = app.GetNamedMenu("Daves_ScriptingMenu"); //Menu NAME

                RemoveMenu(fmMenu, fmDavesMenu);

                 

                UpdateMenus();

                 

                (3)

                //Loading var's, in case they somehow need to be declared, but not

                //  using them for the removal.

                var fmMenu = app.GetNamedMenu("!MakerMainMenu");

                var fmDavesMenu = app.GetNamedMenu("Daves_ScriptingMenu"); //Menu NAME

                RemoveMenu("!MakerMainMenu", "Dave's Scripts"); //Menu LABEL

                 

                UpdateMenus();

                 

                (4)

                //Without first declaring var("!MakerMainMenu"). Tried both Remove lines, one at a time.  No Joy.

                RemoveMenu("!MakerMainMenu", "Daves_ScriptingMenu");//Menu NAME

                //RemoveMenu("!MakerMainMenu", "Dave's Scripts"); //Menu LABEL

                UpdateMenus();

                • 6. Re: RemoveMenu, not working
                  Russ Ward Level 4

                  Dave, I finally got a minute to look at this. I've discovered that the documentation on RemoveMenu() is not correct. It makes no sense to pass a menu label as an identifier, since these do not need to be unique. However, the menu Name does need to be unique, so I tried that and it worked. So, at least the documentation was accurate in that the arguments must be strings, not menu objects.

                   

                  I think this variation of your code should work... give it a try:

                   

                  (2)

                  //Loading var's then addressing them to remove menu

                  var fmMenu = app.GetNamedMenu("!MakerMainMenu");

                  var fmDavesMenu = app.GetNamedMenu("Daves_ScriptingMenu"); //Menu NAME

                  RemoveMenu(fmMenu.Name, fmDavesMenu.Name);

                   

                   

                  ...or, I guess maybe just:

                   

                  RemoveMenu("!MakerMainMenu", "Daves_ScriptingMenu");

                   

                  Russ

                  • 7. Re: RemoveMenu, not working
                    DrDaveJ Level 1

                    Alas, none of that worked.

                    You gave me ideas about mixing and matching .properties, menu names/labels, etc.  No joy.

                    Now, I am off this project and onto something else for a couple days. Will tackle this again while I am on vacation, starting Thurs/3rd.

                    My next guess is to remove Commands from the Menu, and then see if the Menu will Remove.

                     

                    Thanks for the feedback!

                    Dave

                    • 8. Re: RemoveMenu, not working
                      Russ Ward Level 4

                      It works fine here. The only other thing I could suggest is the obvious... make sure you have the right name of your menu. You could test with alert(fmDavesMenu.Label).

                       

                      Russ

                      • 9. Re: RemoveMenu, not working
                        DrDaveJ Level 1

                        Russ,

                        The obvious turns out to be the correct answer!  

                        Gee whiz. Pass me the dunce cap! Rookies, move over.

                         

                        I had the Add Menu Script located in two places.

                        1. Startup, in AppData; and
                        2. Its "Master Directory", where I keep the scripts. And where I made changes!

                        I then I wrote RemoveMenu script using menu names/labels as written/tweaked in #2, above. Totally forgetting the Startup version that actually adds the menu!

                        I copied current version of AddMenu to Startup and now, RemoveMenu works like a charm! Like so:

                        RemoveMenu("!MakerMainMenu", "Daves_ScriptingMenu"); //Menu NAME

                        UpdateMenus();

                         

                        Thanks all the help!

                        [* name withheld to protect the thick-headed  *]