找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 571|回复: 0

[教学]:Visual Lisp and Menu's.

[复制链接]

已领礼包: 593个

财富等级: 财运亨通

发表于 2003-7-30 21:36:57 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×

  1. <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="700" id="AutoNumber1" height="498">
  2.   <tr>
  3.     <td width="100%" height="489">
  4.       <iframe name="I1" width="100%" height="100%" src="http://www.afralisp.com/vl/vlmenu1.htm">
  5. 浏览器不支持嵌入式框架或配置为不显示嵌入式框架
  6.       </iframe>
  7.     </td>
  8.   </tr>
  9. </table>
复制代码

  1. (defun C:VBATOOLBARMENU        (/             fn                 acadobj
  2.                          thisdoc     menus         flag
  3.                          currMenuGroup                 newMenu
  4.                          newMenuItem openMacro
  5.                         )
  6.   ;; CreateMenu is a nested DEFUN that is executed if our "VbaMenu"
  7.   ;; pulldown menu doesn't exist. A test for the presence of this
  8.   ;; pulldown menu is done in the main code
  9.   (defun createMenu ()
  10.     ;; Add a new popUpMenu to currMenuGroup, i.e. to "VbaMenu"
  11.     (setq newMenu (vla-add (vla-get-menus currMenuGroup) "V&BA Menu"))
  12.     ;;------------------------------------------------------------------
  13.     ;; create the first pulldown item, vbaload
  14.     (setq
  15.       openMacro        (strcat (chr 3) (chr 3) (chr 95) "vbaload" (chr 32))
  16.     )
  17.     (setq newMenuItem
  18.            (vla-addMenuItem
  19.              newMenu
  20.              (1+ (vla-get-count newMenu))
  21.              "VBA &Load"
  22.              openMacro
  23.            )
  24.     )
  25.     (vla-put-helpString newMenuItem "Load a VBA Application")
  26.     ;;------------------------------------------------------------------
  27.     ;; create the second pulldown item, vbaide
  28.     (setq openMacro (strcat (chr 3) (chr 3) (chr 95) "vbaide" (chr 32)))
  29.     (setq newMenuItem
  30.            (vla-addMenuItem
  31.              newMenu
  32.              (1+ (vla-get-count newMenu))
  33.              "VBA &Editor"
  34.              openMacro
  35.            )
  36.     )
  37.     (vla-put-helpString newMenuItem "Switch to the VBA Editor")
  38.     ;;------------------------------------------------------------------
  39.     ;; create the third pulldown item, vbarun
  40.     (setq openMacro (strcat (chr 3) (chr 3) (chr 95) "vbarun" (chr 32)))
  41.     (setq newMenuItem
  42.            (vla-addMenuItem
  43.              newMenu
  44.              (1+ (vla-get-count newMenu))
  45.              "VBA &Macro"
  46.              openMacro
  47.            )
  48.     )
  49.     (vla-put-helpString newMenuItem "Run a VBA Macro")
  50.     ;;------------------------------------------------------------------
  51.     ;; create the fourth pulldown item, vbaman
  52.     (setq openMacro (strcat (chr 3) (chr 3) (chr 95) "vbaman" (chr 32)))
  53.     (setq newMenuItem
  54.            (vla-addMenuItem
  55.              newMenu
  56.              (1+ (vla-get-count newMenu))
  57.              "&VBA Manager"
  58.              openMacro
  59.            )
  60.     )
  61.     (vla-put-helpString newMenuItem "Display the VBA Manager")
  62.     ;;------------------------------------------------------------------
  63.     ;; insert a separator after the fourth menu item
  64.     (vla-AddSeparator newMenu 5)
  65.     ;;------------------------------------------------------------------
  66.     ;; create a simple menu macro
  67.     (setq
  68.       openMacro        (strcat        (chr 3)
  69.                         (chr 3)
  70.                         (chr 95)
  71.                         "zoom"
  72.                         (chr 32)
  73.                         "w"
  74.                         (chr 32)
  75.                 )

  76.     )
  77.     (setq newMenuItem
  78.            (vla-addMenuItem
  79.              newMenu
  80.              (1+ (vla-get-count newMenu))
  81.              "&Zoom"
  82.              openMacro
  83.            )
  84.     )
  85.     (vla-put-helpString newMenuItem "Zoom Window")
  86.     ;;------------------------------------------------------------------
  87.     ;; create a menu item that loads and runs an AutoLISP routine
  88.     (setq openMacro (strcat (chr 3)
  89.                             (chr 3)
  90.                             (chr 95)
  91.                             "(if (not c:ddvpoint) (load "ddvpoint")"
  92.                             (chr 32)
  93.                             "ddvpoint"
  94.                     )
  95.     )
  96.     (setq newMenuItem
  97.            (vla-addMenuItem
  98.              newMenu
  99.              (1+ (vla-get-count newMenu))
  100.              "View &Point"
  101.              openMacro
  102.            )
  103.     )
  104.     (vla-put-helpString newMenuItem "View Point")
  105.     ;;------------------------------------------------------------------
  106.     ;; create a menu item that calls an Image menu
  107.     (setq openMacro (strcat (chr 3)
  108.                             (chr 3)
  109.                             (chr 95)
  110.                             "$I=image_3dobjects $I=*"
  111.                     )
  112.     )
  113.     (setq newMenuItem
  114.            (vla-addMenuItem
  115.              newMenu
  116.              (1+ (vla-get-count newMenu))
  117.              "&3D Objects"
  118.              openMacro
  119.            )
  120.     )
  121.     (vla-put-helpString newMenuItem "3D objects")
  122.     ;;------------------------------------------------------------------
  123.     ;; create a menu item with a hyperlink
  124.     (setq openMacro (strcat (chr 3)
  125.                             (chr 3)
  126.                             (chr 95)
  127.                             "browser"
  128.                             (chr 32)
  129.                             "www.afralisp.com"
  130.                             (chr 32)
  131.                     )
  132.     )
  133.     (setq newMenuItem
  134.            (vla-addMenuItem
  135.              newMenu
  136.              (1+ (vla-get-count newMenu))
  137.              "&AfraLisp.com"
  138.              openMacro
  139.            )
  140.     )
  141.     (vla-put-helpString
  142.       newMenuItem
  143.       "Go visit this awesome place, or else!"
  144.     )
  145.     ;;------------------------------------------------------------------
  146.     ;; insert the pulldown menu into the menu bar, third from the end
  147.     (vla-insertInMenuBar
  148.       newMenu
  149.       (- (vla-get-count (vla-get-menuBar acadobj)) 2)
  150.     )
  151.     ;; re-compile the VBAMENU menu - VBAMENU.MNC
  152.     (vla-save currMenuGroup acMenuFileCompiled)
  153.     ;; save it as a MNS file
  154.     (vla-save currMenuGroup acMenuFileSource)
  155.   )
  156.   ;; First, check to see if our menu file "VbaMenu.mns" already
  157.   ;; exists. If it doesn't then simply make an empty file that
  158.   ;; we can later write our menu definition to
  159.   (setq flag nil)
  160.   (if (not (findfile "VbaMenu.mns"))
  161.     (progn
  162.       (setq fn (open "VbaMenu.mns" "w"))
  163.       (close fn)
  164.     )
  165.   )
  166.   ;; Get hold of the application object - we will use it to
  167.   ;; retrieve the menuGroups collection, which is a child object
  168.   ;; of the application
  169.   (setq acadobj (vlax-get-acad-object))
  170.   ;; Get the active document - also a child of the application
  171.   (setq thisdoc (vla-get-activeDocument acadobj))
  172.   ;; Get all menugroups loaded into AutoCAD
  173.   (setq menus (vla-get-menuGroups acadobj))
  174.   ;; Now we could use VLA-ITEM to test if "VbaMenu" exists among
  175.   ;; all loaded menugroups with (vla-item menus "VbaMenu").
  176.   ;; Instead, as a friendly service, we want all loaded menus to
  177.   ;; be printed to the screen and at the same time we might as well
  178.   ;; use it to set a flag if "VbaMenu" is among the loaded menus
  179.   (princ "\nLoaded menus: ")
  180.   (vlax-for n menus
  181.     (if        (= (vla-get-name n) "VbaMenu")
  182.       (setq flag T)
  183.     )
  184.     (terpri)
  185.     (princ (vla-get-name n))
  186.   )
  187.   ;; If VbaMenu wasn't among the loaded menus then load it
  188.   (if (null flag)
  189.     (vla-load menus "VbaMenu.mns")
  190.   )
  191.   (setq currMenuGroup (vla-item menus "VbaMenu"))
  192.   ;; If no popUpMenus exist in VbaMenu then go create one -
  193.   ;; otherwise exit with grace. In this example we merely check
  194.   ;; if the number of popup menus in "VbaMenu" is greater than 0.
  195.   ;; A safer way to test for its presence would be to set up a
  196.   ;; test for its name, "V&BA Menu":
  197.   ;; (vla-item (vla-get-menus currMenuGroup) "V&BA Menu")
  198.   (if (<= (vla-get-count (vla-get-menus currMenuGroup)) 0)
  199.     (createMenu)
  200.     (princ "\nThe menu is already loaded")
  201.   )
  202.   (princ)
  203. )

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-18 06:46 , Processed in 0.168157 second(s), 37 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表