How to load a menu pulldown into the current menubar

Discussion in 'AutoCAD' started by Eugene, Aug 21, 2003.

  1. Eugene

    Eugene Guest

    Simple question for those who know...After I load a partial menu, how do I
    load the Menu's pull down into the current menu group? The partial menu only
    has one pulldown named the user's logon on name.

    Option Compare Text
    Sub main()

    Dim sCurUser As String
    Dim CurrMenuGroup As AcadMenuGroup
    Dim NewMenu As AcadPopupMenu

    'Get the environment variable "username"
    sCurUser = Environ("username")

    'Load the users custom menu
    ThisDrawing.Application.MenuGroups.Load sCurUser & ".mns"

    Thanks
     
    Eugene, Aug 21, 2003
    #1
  2. Try this.

    Sub Main()
    Dim strCurUser As String
    Dim objMenuGroup As AcadMenuGroup

    strCurUser = ThisDrawing.GetVariable("LOGINNAME")
    Set objMenuGroup = MenuGroups.Load(strCurUser)
    objMenuGroup.Menus("YourMenuNameHere").InsertInMenuBar MenuBar.Count - 2
    Set objMenuGroup = Nothing
    End Sub
     
    Chuck Gabriel, Aug 21, 2003
    #2
  3. Eugene

    Eugene Guest

    Hello!
    Unless I am doing something wrong, that didnt work Chuck. When I ran debug
    it stoped at the first line;
    strCurUser = ThisDrawing.GetVariable("LOGINNAME")

    Thanks to Frank, I can sucussfully load the users menu using the code;

    Dim sCurUser As String

    'Get the environment variable "username"
    sCurUser = Environ("username")

    'Load the users custom menu
    ThisDrawing.Application.MenuGroups.Load sCurUser & ".mns"


    Now, I just cant figure how to load the popup which again will be the
    "username" in the current menubar once I have the menu loaded.

    Do I use ?
    ..InsertInMenuBar (ThisDrawing.Application.MenuBar.Count - 2)
    If so, how exactly?

    Thanks for your help
    Eugene
     
    Eugene, Aug 21, 2003
    #3
  4. I can't imagine why that line would fail, but you could always just substitute
    the following:

    strCurUser = Environ("username")

    if that worked for you before.

    As far as inserting the menu into the menu bar, the following will insert it
    right before the "Window" pulldown:

    objMenuGroup.Menus(strCurUser).InsertInMenuBar MenuBar.Count - 2

    You can insert the menu anywhere in the menu bar by changing the value
    "MenuBar.Count -2". The docs say it can be anywhere from 0 to MenuBar.Count -1.
     
    Chuck Gabriel, Aug 21, 2003
    #4
  5. When you assign the result of a function to a variable, you have to enclose the
    function arguments in parentheses.

    As a point of interest, what operating system and AutoCAD version are you using.
    I tested this code under AutoCAD 2000i on Windows 2000 Pro, before I posted it,
    and it worked just fine for me.
     
    Chuck Gabriel, Aug 21, 2003
    #5
  6. You could also try prefixing MenuGroups and MenuBar with Application like so:

    Set objMenuGroup = Application.MenuGroups.Load(strCurUser)

    and

    objMenuGroup.Menus(strCurUser).InsertInMenuBar Application.MenuBar.Count - 2

    I didn't do that, because it is implied in the version of AutoCAD VBA that I am
    using, but it might not be implied in your version. I'm sure Frank would
    denounce that as a poor coding practice, and he would be right.
     
    Chuck Gabriel, Aug 21, 2003
    #6
  7. Eugene

    Eugene Guest

    Hey Chuck
    I'm using 2000i w/ XP as the OS

    I'll try prefixing with application to see if that will help

    I really appreciate you help with this
    Thanks!

    Eugene
     
    Eugene, Aug 21, 2003
    #7
  8. Eugene

    Eugene Guest

    I tried using the prefix application...no luck , same error
    does
    Set objMenuGroup = MenuGroups.Load(strCurUser)
    load the MNS file?

    hummmmm?
     
    Eugene, Aug 21, 2003
    #8
  9. Ok. Try the following code:

    Sub LoadUserMenu()
    Dim strCurUser As String
    Dim objMenuGroup As AcadMenuGroup

    strCurUser = Environ("username")
    Debug.Print "username = " & strCurUser
    Set objMenuGroup = Application.MenuGroups.Load(strCurUser & ".mns")
    Debug.Print "Popup menus in " & objMenuGroup.Name & " menu group."
    Dim objPopupMenu As AcadPopupMenu
    For Each objPopupMenu In objMenuGroup.Menus
    Debug.Print " " & objPopupMenu.Name
    Next
    Set objPopupMenu = objMenuGroup.Menus(strCurUser)
    objPopupMenu.InsertInMenuBar Application.MenuBar.Count - 2
    Set objPopupMenu = Nothing
    Set objMenuGroup = Nothing
    End Sub


    Post back here with the output from the "Immediate" window in the VBA IDE. If
    it errors, post the exact error code and description.
     
    Chuck Gabriel, Aug 21, 2003
    #9
  10. Eugene

    Eugene Guest

    Chuck,

    I totally scrapped the project and started a fresh one with the code you
    gave me

    Sub Main()
    Dim strCurUser As String
    Dim objMenuGroup As AcadMenuGroup

    strCurUser = ThisDrawing.GetVariable("LOGINNAME")
    Set objMenuGroup = MenuGroups.Load(strCurUser)
    objMenuGroup.Menus("YourMenuNameHere").InsertInMenuBar MenuBar.Count - 2
    Set objMenuGroup = Nothing
    End Sub

    It passes everything until it hits
    objMenuGroup.Menus("YourMenuNameHere").InsertInMenuBar MenuBar.Count - 2


    If my menuname is allways equal to the user loginname can I use strCurUser
    as the menu name...so would it look like this
    objMenuGroup.Menus(strCurUser).InsertInMenuBar MenuBar.Count - 2

    Sorry for running you around in circles..I dont know why it wouldnt work in
    the old module?

    Eugene
     
    Eugene, Aug 21, 2003
    #10
  11. Eugene

    Eugene Guest

    Chuck, you are the man!
    I had a typo In my mns for the popup menu
    ***PIP1
    ID_EBurgy [EBurgy]
    ID_Channelization [&Channelization]^C^C_$I=ENTBEL.iCHAN $I=*

    not

    ***POP1
    ID_EBurgy [EBurgy]
    ID_Channelization [&Channelization]^C^C_$I=ENTBEL.iCHAN $I=*

    Thanks for everything!
    Eugene
     
    Eugene, Aug 21, 2003
    #11
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.