VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How Can I create a menu Using VBA

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Amremad
3848 Views, 6 Replies

How Can I create a menu Using VBA

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

6 REPLIES 6
Message 2 of 7
Hallex
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
Message 3 of 7
Amremad
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)

 

 

Message 4 of 7
jdkriek
in reply to: Amremad

Don't forget error checking 😉

 

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
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 5 of 7
Alexander.Rivilis
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.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 6 of 7
jdkriek
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
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 7 of 7
Steve8765
in reply to: jdkriek

Your code ran but didn't add a new menu, is there anything I'm missing?

I'm using AutoCAD 2016.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost