;;;从AutoCAD 2013 Active Reference帮助中code Examples中提取
;;;本源代码由 xshrimp 2013.2.20 搜集整理,版权归原作者所有!
(vl-load-com)
(defun c:Example_OnMenuBar()
;; 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.
(setq acadObj (vlax-get-acad-object))
(setq currMenuGroup (vla-Item (vla-get-MenuGroups acadObj) 0))
;; Create the new menu
(setq newMenu (vla-Add (vla-get-Menus currMenuGroup) "TestMenu"))
;; Add a menu item to the new menu
;; Assign the macro string the VB equivalent of "ESC ESC _open "
(setq openMacro (strcat (Chr 3) (Chr 3) (Chr 95) "open" (Chr 32)))
(setq newMenuItem (vla-AddMenuItem newMenu (1+ (vla-get-Count newMenu)) "Open" openMacro))
;; Display the menu on the menu bar
(vla-InsertInMenuBar newMenu (1+ (vla-get-Count (vla-get-MenuBar acadObj))))
(if (= (vla-get-OnMenuBar newMenu) :vlax-true)
(alert (strcat "The menu called " (vla-get-Name newMenu) " is on the menu bar."))
(alert (strcat "The menu called " (vla-get-Name newMenu) " is not on the menu bar."))
)
;; Remove the menu from the menu bar
(vla-RemoveMenuFromMenuBar (vla-get-Menus currMenuGroup) "TestMenu")
(if (= (vla-get-OnMenuBar newMenu) :vlax-true)
(alert (strcat "The menu called " (vla-get-Name newMenu) " is on the menu bar."))
(alert (strcat "The menu called " (vla-get-Name newMenu) " is not on the menu bar."))
)
)