马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="700" id="AutoNumber1" height="498">
- <tr>
- <td width="100%" height="489">
- <iframe name="I1" width="100%" height="100%" src="http://www.afralisp.com/vl/vlmenu1.htm">
- 浏览器不支持嵌入式框架或配置为不显示嵌入式框架
- </iframe>
- </td>
- </tr>
- </table>
复制代码
- (defun C:VBATOOLBARMENU (/ fn acadobj
- thisdoc menus flag
- currMenuGroup newMenu
- newMenuItem openMacro
- )
- ;; CreateMenu is a nested DEFUN that is executed if our "VbaMenu"
- ;; pulldown menu doesn't exist. A test for the presence of this
- ;; pulldown menu is done in the main code
- (defun createMenu ()
- ;; Add a new popUpMenu to currMenuGroup, i.e. to "VbaMenu"
- (setq newMenu (vla-add (vla-get-menus currMenuGroup) "V&BA Menu"))
- ;;------------------------------------------------------------------
- ;; create the first pulldown item, vbaload
- (setq
- openMacro (strcat (chr 3) (chr 3) (chr 95) "vbaload" (chr 32))
- )
- (setq newMenuItem
- (vla-addMenuItem
- newMenu
- (1+ (vla-get-count newMenu))
- "VBA &Load"
- openMacro
- )
- )
- (vla-put-helpString newMenuItem "Load a VBA Application")
- ;;------------------------------------------------------------------
- ;; create the second pulldown item, vbaide
- (setq openMacro (strcat (chr 3) (chr 3) (chr 95) "vbaide" (chr 32)))
- (setq newMenuItem
- (vla-addMenuItem
- newMenu
- (1+ (vla-get-count newMenu))
- "VBA &Editor"
- openMacro
- )
- )
- (vla-put-helpString newMenuItem "Switch to the VBA Editor")
- ;;------------------------------------------------------------------
- ;; create the third pulldown item, vbarun
- (setq openMacro (strcat (chr 3) (chr 3) (chr 95) "vbarun" (chr 32)))
- (setq newMenuItem
- (vla-addMenuItem
- newMenu
- (1+ (vla-get-count newMenu))
- "VBA &Macro"
- openMacro
- )
- )
- (vla-put-helpString newMenuItem "Run a VBA Macro")
- ;;------------------------------------------------------------------
- ;; create the fourth pulldown item, vbaman
- (setq openMacro (strcat (chr 3) (chr 3) (chr 95) "vbaman" (chr 32)))
- (setq newMenuItem
- (vla-addMenuItem
- newMenu
- (1+ (vla-get-count newMenu))
- "&VBA Manager"
- openMacro
- )
- )
- (vla-put-helpString newMenuItem "Display the VBA Manager")
- ;;------------------------------------------------------------------
- ;; insert a separator after the fourth menu item
- (vla-AddSeparator newMenu 5)
- ;;------------------------------------------------------------------
- ;; create a simple menu macro
- (setq
- openMacro (strcat (chr 3)
- (chr 3)
- (chr 95)
- "zoom"
- (chr 32)
- "w"
- (chr 32)
- )
- )
- (setq newMenuItem
- (vla-addMenuItem
- newMenu
- (1+ (vla-get-count newMenu))
- "&Zoom"
- openMacro
- )
- )
- (vla-put-helpString newMenuItem "Zoom Window")
- ;;------------------------------------------------------------------
- ;; create a menu item that loads and runs an AutoLISP routine
- (setq openMacro (strcat (chr 3)
- (chr 3)
- (chr 95)
- "(if (not c:ddvpoint) (load "ddvpoint")"
- (chr 32)
- "ddvpoint"
- )
- )
- (setq newMenuItem
- (vla-addMenuItem
- newMenu
- (1+ (vla-get-count newMenu))
- "View &Point"
- openMacro
- )
- )
- (vla-put-helpString newMenuItem "View Point")
- ;;------------------------------------------------------------------
- ;; create a menu item that calls an Image menu
- (setq openMacro (strcat (chr 3)
- (chr 3)
- (chr 95)
- "$I=image_3dobjects $I=*"
- )
- )
- (setq newMenuItem
- (vla-addMenuItem
- newMenu
- (1+ (vla-get-count newMenu))
- "&3D Objects"
- openMacro
- )
- )
- (vla-put-helpString newMenuItem "3D objects")
- ;;------------------------------------------------------------------
- ;; create a menu item with a hyperlink
- (setq openMacro (strcat (chr 3)
- (chr 3)
- (chr 95)
- "browser"
- (chr 32)
- "www.afralisp.com"
- (chr 32)
- )
- )
- (setq newMenuItem
- (vla-addMenuItem
- newMenu
- (1+ (vla-get-count newMenu))
- "&AfraLisp.com"
- openMacro
- )
- )
- (vla-put-helpString
- newMenuItem
- "Go visit this awesome place, or else!"
- )
- ;;------------------------------------------------------------------
- ;; insert the pulldown menu into the menu bar, third from the end
- (vla-insertInMenuBar
- newMenu
- (- (vla-get-count (vla-get-menuBar acadobj)) 2)
- )
- ;; re-compile the VBAMENU menu - VBAMENU.MNC
- (vla-save currMenuGroup acMenuFileCompiled)
- ;; save it as a MNS file
- (vla-save currMenuGroup acMenuFileSource)
- )
- ;; First, check to see if our menu file "VbaMenu.mns" already
- ;; exists. If it doesn't then simply make an empty file that
- ;; we can later write our menu definition to
- (setq flag nil)
- (if (not (findfile "VbaMenu.mns"))
- (progn
- (setq fn (open "VbaMenu.mns" "w"))
- (close fn)
- )
- )
- ;; Get hold of the application object - we will use it to
- ;; retrieve the menuGroups collection, which is a child object
- ;; of the application
- (setq acadobj (vlax-get-acad-object))
- ;; Get the active document - also a child of the application
- (setq thisdoc (vla-get-activeDocument acadobj))
- ;; Get all menugroups loaded into AutoCAD
- (setq menus (vla-get-menuGroups acadobj))
- ;; Now we could use VLA-ITEM to test if "VbaMenu" exists among
- ;; all loaded menugroups with (vla-item menus "VbaMenu").
- ;; Instead, as a friendly service, we want all loaded menus to
- ;; be printed to the screen and at the same time we might as well
- ;; use it to set a flag if "VbaMenu" is among the loaded menus
- (princ "\nLoaded menus: ")
- (vlax-for n menus
- (if (= (vla-get-name n) "VbaMenu")
- (setq flag T)
- )
- (terpri)
- (princ (vla-get-name n))
- )
- ;; If VbaMenu wasn't among the loaded menus then load it
- (if (null flag)
- (vla-load menus "VbaMenu.mns")
- )
- (setq currMenuGroup (vla-item menus "VbaMenu"))
- ;; If no popUpMenus exist in VbaMenu then go create one -
- ;; otherwise exit with grace. In this example we merely check
- ;; if the number of popup menus in "VbaMenu" is greater than 0.
- ;; A safer way to test for its presence would be to set up a
- ;; test for its name, "V&BA Menu":
- ;; (vla-item (vla-get-menus currMenuGroup) "V&BA Menu")
- (if (<= (vla-get-count (vla-get-menus currMenuGroup)) 0)
- (createMenu)
- (princ "\nThe menu is already loaded")
- )
- (princ)
- )
|