Author Topic: Ading and removing menus  (Read 2341 times)

0 Members and 1 Guest are viewing this topic.

iliekater

  • Guest
Ading and removing menus
« on: December 11, 2006, 05:03:59 PM »
Is it possible to load menus (*.mnu files) or remove them with code ? Considering that the *.mnu file is located in a support path .

TR

  • Guest
Re: Ading and removing menus
« Reply #1 on: December 11, 2006, 05:31:11 PM »
You can build the menus right in your code. Check custom_menu.dvb from {ACAD_DIR}\Sample\VBA\VBAIDEMenu\.

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: Ading and removing menus
« Reply #2 on: December 11, 2006, 05:50:08 PM »
Just know that 2007 handles menus very differently.
The code that works for 2004 will not work for 2007 and menus in 2007 are difficult.
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

iliekater

  • Guest
Re: Ading and removing menus
« Reply #3 on: December 12, 2006, 08:16:35 AM »
Oh , great ... I am supposed to write a program that should work for all users , but now I see that this is going to be impossible ...

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Ading and removing menus
« Reply #4 on: December 12, 2006, 08:43:06 AM »
Not impossible, just a whole lot of fun.  So what are you trying to do, maybe we can help
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

iliekater

  • Guest
Re: Ading and removing menus
« Reply #5 on: December 12, 2006, 10:02:03 AM »
I know it is funny replying to a VBA topic with Lisp code , but then again knowlendge is knoelenge and should not be hidden ( :lol: ) .
I found a way to easily load and remove menus :
First of all , I set the filedia system varible to 0 in order to manipulate AutoCAD by code .
The I use the MENULOAD command to load the menu I wish and then the MENUUNLOAD to remove it !
I restore the filedia value and that's it !

Well , no ... And the reason is I still haven't inserted the menu drop down in the menu line . Does anyone know how I could do that with code ?

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Ading and removing menus
« Reply #6 on: December 12, 2006, 10:19:05 AM »
Code: [Select]
Sub Example_InsertInMenuBar()
    ' This example creates a new menu called TestMenu and inserts a menu item
    ' into it. The menu is then displayed on the menu bar.
    ' To remove the menu after execution of this macro, use the Customize Menu
    ' option from the Tools menu.
   
    Dim currMenuGroup As acadMenuGroup
    Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)
   
    ' Create the new menu
    Dim newMenu As AcadPopupMenu
    Set newMenu = currMenuGroup.Menus.Add("TestMenu")
   
    ' Add a menu item to the new menu
    Dim newMenuItem As AcadPopupMenuItem
    Dim openMacro As String
    ' Assign the macro string the VB equivalent of "ESC ESC _open "
    openMacro = Chr(3) & Chr(3) & Chr(95) & "open" & Chr(32)
   
    Set newMenuItem = newMenu.AddMenuItem(newMenu.count + 1, "Open", openMacro)
   
    ' Display the menu on the menu bar
    newMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.count + 1)
   
End Sub
 
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Ading and removing menus
« Reply #7 on: December 12, 2006, 10:20:44 AM »
and removing
Code: [Select]
Sub Example_RemoveFromMenuBar()
    ' This example creates a new menu called TestMenu and inserts a menu item
    ' into it. The menu is then displayed on the menu bar, and then
    ' removed from the menu bar.
   
    Dim currMenuGroup As acadMenuGroup
    Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)
   
    ' Create the new menu
    Dim newMenu As AcadPopupMenu
    Set newMenu = currMenuGroup.Menus.Add("TestMenu")
   
    ' Add a menu item to the new menu
    Dim newMenuItem As AcadPopupMenuItem
    Dim openMacro As String
    ' Assign the macro string the VB equivalent of "ESC ESC _open "
    openMacro = Chr(3) & Chr(3) & Chr(95) & "open" & Chr(32)
   
    Set newMenuItem = newMenu.AddMenuItem(newMenu.count + 1, "Open", openMacro)
   
    ' Display the menu on the menu bar
    newMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.count + 1)
    GoSub QUERYMENU
   
    ' Remove the menu from the menu bar
    newMenu.RemoveFromMenuBar
    GoSub QUERYMENU
    Exit Sub
   
QUERYMENU:
    If newMenu.OnMenuBar Then
        MsgBox "The menu called " & newMenu.name & " is on the menu bar."
    Else
        MsgBox "The menu called " & newMenu.name & " is not on the menu bar."
    End If
    Return
       
End Sub
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

iliekater

  • Guest
Re: Ading and removing menus
« Reply #8 on: December 12, 2006, 02:32:51 PM »
Yes , I know I know ... I show this at the VBA Help while I was in the berou this afternoon . But I found an even easier method ! Using AutoLISP ! Here it is :

( menucmd "P12=+MyMenuGroup.MyMenuName" )

will load the the specified menu (MyMenuName) from a specified menu group (MyMenugroup) which should already be loaded by using the MENLOAD comand . In the example above , the menu is added before the position 12 on the menu line .

Thus with only 3 lines , one can Load , Specify pozition and Unload a menu !