TheSwamp
Code Red => VB(A) => Topic started by: ML on November 05, 2004, 07:50:32 PM
-
Ok, I am stomped for now, so I will ask,
Does anyone know how to insert a Pulldown Menu into the menubar?
I was able to succesfully load my menu via VBA but I can not get it to insert into The Menbar no matter what I do.
Any help is really appreciated
Thank you
Mark
-
Can you post what you have tried?
If you have reached the limit of the number of Puldowns, a new one won't be shown, I don't recall what that limit is.....
Anyway, once you have the PopupMenus collection, you can Add the menu, then AddMenuItems, then InsertInMenuBar.
-
Actually there is only 1 Pulldown involved,
I figured out how to access The Pulldown Menu Collection and I was playing with The InsertinMenuBar Property but I still had no luck inserting it. Here is the code so far
Thanks Jeff
Sub Load_MyCompany_Menu()
Dim MenuGroup As AcadMenuGroup
Dim SelectedMenuGroup As String
Dim Retval As Variant
On Error Resume Next
SelectedMenuGroup = "Path\Filename.mnc"
Set MenuGroup = ThisDrawing.Application.MenuGroups.Load(SelectedMenuGroup, False)
If MenuGroup Is Nothing Then
Retval = MsgBox("The MyCompany menu is already loaded", vbInformation, "MyCompany")
Exit Sub
Else
Retval = MsgBox("The MyCompany menu has been successfully loaded", vbInformation, "Filename")
End If
End Sub
-
Mark,
See if this helps you figure it out.....
Sub addMenuToToolBar()
Dim MenuGroup As AcadMenuGroup
Dim MenuPops As AcadPopupMenu
Set MenuGroup = ThisDrawing.Application.MenuGroups.Item("Mymenu")
On Error Resume Next
MenuGroup.Menus.Add ("TestMenu") 'This is the name of a Popup in your menu
Set MenuPops = MenuGroup.Menus.Item("TestMenu")
On Error GoTo 0
MenuPops.InsertInMenuBar 12 'insert at spot 12 in the bar
End Sub
-
The limit for menu popus is 16 ...at least in menus, I have not tested the limit programmatically
-
Hey Keith
Not to doubt you, but are you sure about that ?
Oh, I think you are referring to 16 across tHe Menubar? If so, then I am sure you are right but The 999 I think is actual POP Menus Period.
-
Cool, I will try it Jeff, thank you very much!
I see, I was getting The Collection but I wasn't telling VBA to add it to The POP Collection.
Mark
-
My thinking is that we also need to declare a variable that will hold our current menus as well so that they are not overwritten. I learned that lesson when I did the support paths module.
-
Hey Keith
Not to doubt you, but are you sure about that ?
Oh, I think you are referring to 16 across tHe Menubar? If so, then I am sure you are right but The 999 I think is actual POP Menus Period.
You can have as many pop menus defined as you want, you could conceivably have a thousand or more... BUT, AutoCAD will only display 16 on the menu bar when displayed through a defined MNU or MNS.
Outside of that, you simply exchange the pop menus for one another.
-
Ok then, what if one was a base menu and some were partial?
What you aresaying is that you can have only 16 across a menu bar.
What I was saying initially didn't involve the menu bar, it was genrally speaking about Pop Menus.
I think there is a limit of 999 but is that per menufile or in AutoCAD with all POP's combined?
Hey, we have deviated from VBA! We need to talk code in here :D
Mark
-
God, just the thought of .mnu files annoys me LOL
I was someone told me early on that .mnu files were not necessary it would have saved me a lot of pain :D
THe .mns file is all that needs to be backed up and saved as well.
Mark
-
Hi
Just for info, the below snippets come from the AutoCAD Online Help File [F1] -
<snip>
You can load and unload up to 8 partial menus and up to 16 Pop menus.
</snip>
<snip>
Pull-down menus are defined in the ***POP1 through ***POP499 menu sections, and shortcut menus are defined in the ***POP0 and ***POP500 through ***POP999 sections. A pull-down menu can contain up to 999 menu items. A shortcut menu can contain up to 499 menu items. Both limits include all menus in a hierarchy. If menu items in the menu file exceed these limits, AutoCAD ignores the extra items. If a pull-down or shortcut menu is longer than the available display space, it is truncated to fit.
</snip>
Have a good one, Mike
-
Thanks Mike, that is good info.
Going back to VBA, I don't think the above code will work with the same module that is loading the menu.
It can be done but there needs to be a different method.
I am open to suggestions
Thank you
Mark
-
Hey Jeff
I looked at your little code example above and it did help me to finally finish off what I was trying to do. I wanted to load a menugroup and insert a POP from it in The Menubar. So, I got it
I can post if anyone is interested?
Thank you
Mark
-
OK, I wanted to post this code as I have now finished it. I hope someone else will benefit from it. If you have any questions, feel free to ask.
Mark
-----------------------------------
Sub Load_and_Insert_Menu()
Dim MenuGroup As AcadMenuGroup
Dim PopMenu As AcadPopupMenu
Dim SelectedMenuGroup As String, LoadedPopMenu As String
Dim Retval As Variant
On Error Resume Next
'This part Loads the menu
SelectedMenuGroup = "K:\Directory\Directory\Directory\Menufilename.mnc" '<--- Type in the path to your menufile here.
Set MenuGroup = ThisDrawing.Application.MenuGroups.Load(SelectedMenuGroup, False)
LoadedPopMenu = ("&Pulldown")'Type in the pulldown that you want in the menubar from the above loaded menu.You must include the accelerator (&) if one exists
Set PopMenu = MenuGroup.Menus.Item(LoadedPopMenu)
'This part inserts the pulldown that you typed above in the menubar
PopMenu.InsertInMenuBar 10
If MenuGroup Is Nothing Then
Retval = MsgBox("The "pulldown Menuname" menu is already loaded", vbInformation, "Type whatever you want in the dialog box capion here")
Exit Sub
Else
Retval = MsgBox("The "pulldown Menuname" menu has been successfully loaded", vbInformation, "Type whatever you want in the dialog box capion here")
Exit Sub
End If
End Sub