Visual Basic Customization

Visual Basic Customization

Reply
Mentor
Amremad
Posts: 216
Registered: ‎08-24-2010
Message 1 of 6 (1,214 Views)
Accepted Solution

How Can I create a menu Using VBA

1214 Views, 5 Replies
02-05-2013 05:23 AM

How Can I create a menu like file & edit & view using VBA

Take a look ath this page

http://www.cad.dp.ua/stats/a_vba/index.php

Choose English language at the very top right in this page , then

scroll down to "AutoCAD Objects" --> "Menus and Toolbars"

thank you very much

 

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 the VBA equivalent of "ESC ESC _open "
openMacro = Chr(3) + Chr(3) + "_open "
Set newMenuItem = newMenu.AddMenuItem(newMenu.Count + 1, "Open", openMacro)
' Display the menu on the menu bar
newMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.Count + 1)

 

 

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 6 (1,195 Views)

Re: How Can I create a menu Using VBA

02-10-2013 12:05 AM in reply to: Amremad

Take a look ath this page

http://www.cad.dp.ua/stats/a_vba/index.php

Choose English language at the very top right in this page , then

scroll down to "AutoCAD Objects" --> "Menus and Toolbars"

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Mentor
Amremad
Posts: 216
Registered: ‎08-24-2010
Message 3 of 6 (1,190 Views)

Re: How Can I create a menu Using VBA

02-10-2013 12:30 AM in reply to: Amremad

thank you very much

 

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 the VBA equivalent of "ESC ESC _open "
 openMacro = Chr(3) + Chr(3) + "_open "

 Set newMenuItem = newMenu.AddMenuItem(newMenu.Count + 1, "Open", openMacro)

 ' Display the menu on the menu bar
 newMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.Count + 1)

 

 

*Expert Elite*
jdkriek
Posts: 528
Registered: ‎03-29-2007
Message 4 of 6 (1,163 Views)

Re: How Can I create a menu Using VBA

02-20-2013 07:02 AM in reply to: Amremad

Don't forget error checking :smileywink:

 

Public Sub AddMenus()
'Jonathan D. Kriek
    Dim currMenuGroup As AcadMenuGroup
    Dim newMenu As AcadPopupMenu
    Dim newMenuItem As AcadPopupMenuItem
    
    Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)
    
    On Error Resume Next
    
    'Assign new menu
    Set newMenu = currMenuGroup.Menus.Item("TrinityTools")
    
        'If menu doesn't exist then add it
        If newMenu Is Nothing Then
            Set newMenu = currMenuGroup.Menus.Add("TrinityTools")
        End If
        
            'Check if Menu is displayed on MenuBar
            If Not newMenu.OnMenuBar Then
        
                'Add the eBLoader macro to the menu
                Set newMenuItem = newMenu.AddMenuItem(newMenu.count + 1, _
                "Release To eB", "-vbarun eBLoader ")
                newMenuItem.HelpString = "Release To eB"
            
                'Add the DrawingTypeLoad macro to the menu
                Set newMenuItem = newMenu.AddMenuItem(newMenu.count + 1, _
                "Set Drawing Type", "-vbarun DrawingTypeLoad ")
                newMenuItem.HelpString = "Set Drawing Type"

                'Display the menu on the menu bar
                newMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.count + 1)
            End If
            
        'Save menu
        currMenuGroup.Save (acMenuFileCompiled)
End Sub

 

Jonathan D. Kriek

Autodesk Inventor Certified Expert
Microsoft Certified Application Developer
_____________________________________________________
Did I help you? Please choose Accept as Solution or Kudos below
Moderator
Alexander.Rivilis
Posts: 1,417
Registered: ‎04-09-2008
Message 5 of 6 (1,155 Views)

Re: How Can I create a menu Using VBA

02-20-2013 07:19 AM in reply to: jdkriek

jdkriek wrote:
       'Save menu
        currMenuGroup.Save (acMenuFileCompiled)

Since AutoCAD 2006 MenuGroup.Save do nothing, so it is impossible save menu created on fly with AutoCAD ActiveX Model.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

*Expert Elite*
jdkriek
Posts: 528
Registered: ‎03-29-2007
Message 6 of 6 (1,145 Views)

Re: How Can I create a menu Using VBA

02-20-2013 10:29 AM in reply to: Alexander.Rivilis

Alexander.Rivilis wrote:

Since AutoCAD 2006 MenuGroup.Save do nothing, so it is impossible save menu created on fly with AutoCAD ActiveX Model.


Ah, yes I forgot about the 2005 to 2006 changes.

 

Thanks, but the point of my post was error checking.

Jonathan D. Kriek

Autodesk Inventor Certified Expert
Microsoft Certified Application Developer
_____________________________________________________
Did I help you? Please choose Accept as Solution or Kudos below
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.