How to add your knowledge

Adding Menu Items

    Table of contents
    No headers

    To add a menu item, create a public variable of type Autodesk.Map.IM.Forms.MenuItem. Override the ApplicationPlugIn class’s OnInitMenus method (which is triggered when the menu initialization is taking place), obtain a reference to the application menu, and insert a new menu item using the Add method of the menu’s MenuItems collection. You can then create an event handler for the new menu item and can respond to menu events. For example:

    public Autodesk.Map.IM.Forms.MenuItem myMenu = 
      new Autodesk.Map.IM.Forms.MenuItem();
     
    public override void OnInitMenus
      (object sender, Autodesk.Map.IM.Forms.Events.MenusEventArgs e)
    {
        // Get the application's project menu.
        Autodesk.Map.IM.Forms.Menu vlobMenu = 
          e.Menus.Item(Autodesk.Map.IM.Forms.ApplicationMenuType.Workspace);
     
        // Add the new menu item.
        vlobMenu.MenuItems.Add(myMenu, "My Menu Item");
     
        // Bind the events.
        myMenu.Click += new Autodesk.Map.IM.Forms.Events. 
          MenuItemClickEventHandler(myMenu_Click);
    }
     
     
    private void myMenu_Click
      (object sender, Autodesk.Map.IM.Forms.Events.MenuItemClickEventArgs e)
    {
        // Perform the plugin action here.
        this.Application.MessageBox("Menu item was clicked");
    }