明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3871|回复: 4

[函数] [求助]右鍵菜單

[复制链接]
发表于 2010-2-4 15:08:00 | 显示全部楼层 |阅读模式

我是用“Mouse Reactor.lsp”改的,

SY是已加載的菜單組,在已加載的菜單組中添加快捷菜單

但我碰到兩個問題:

1.   (menucmd (strcat "P0=" "sy" ".pop2"))
      (menucmd "P0=*")

     menucmd語句中不能用別名,隻能用POPn來調用

2. (defun c:f1 ()
      (setq Item1 (sy-addCustomPopupMenu '("AA" "BB" "CC")))
      (cond ((= Item1 1)  (princ "A1"))
                ((= Item1 2)  (princ "B1"))
                ((= Item1 3)  (princ "C1"))
                )
      )

以上面為例,雖能顯示菜單,但f1執行完後才執行菜單宏

以上面兩個問題誰幫幫我,

小弟先謝了!

sy-addCustomPopupMenu 函數在2樓

 楼主| 发表于 2010-2-4 15:09:00 | 显示全部楼层
  1. (setvar "cmdecho" 0)
  2. ;;; --------------------------------------------------------------------------
  3. ;;; searches for a popup label in a popupmenu object
  4. ;;; returns the popupmenu object is it exists.
  5. (defun ac:MenuPopExist (MenuGroupObject popupLabel / dl)
  6.       (vlax-for item MenuGroupObject
  7.      (setq dl (cons (list (strcase (vla-get-NameNoMnemonic item))
  8.      item)
  9.       dl)
  10.      )
  11.       )
  12.       (cadr (assoc (strcase popuplabel) dl))
  13. )
  14. ;;; --------------------------------------------------------------------------
  15. ;;; searches for an id string label in a popupmenuitem object
  16. ;;; returns the popupmenu object is it exists.
  17. (defun ac:MenuItemLabelExist (MenuPopupObject itemLabel / dl)
  18.       (vlax-for item   MenuPopupObject
  19.      (setq dl (cons (list (strcase (vla-get-TagString item)) item)
  20.       dl)
  21.     )
  22.      )
  23.       (cadr (assoc (strcase itemLabel)  dl))
  24.   )
  25. ;;; --------------------------------------------------------------------------
  26. ;;; returns a list of all menuitem objects contained within a popupmenu object
  27. (defun ac:get-Menu-Items (popup / dl)
  28.       (if popup
  29.      (progn
  30.     (vlax-for MenuItem POpup
  31.    (setq dl (cons MenuItem dl))
  32.     )
  33.     (reverse dl)
  34.      )
  35.       )
  36. )
  37. ;;; --------------------------------------------------------------------------
  38. ;;; returns a menuObject. The parameter must be a valid menugroup
  39. (defun ac:ReturnMenuObject (MenuName / dl)
  40.       (if (menugroup MenuName)
  41.      (progn
  42.     (setq meuns (vla-get-MenuGroups (vlax-get-acad-object)))
  43.     (vlax-for Item meuns
  44.    (setq dl (cons (list (strcase (vla-get-name item)) item) dl))
  45.     )
  46.     (cadr (assoc (strcase MenuName) dl))
  47.      )
  48.       )
  49. )
  50. ;;; --------------------------------------------------------------------------
  51. ;;; Predicate for a string
  52. ;;; Returns T if successfull nil otherwise.
  53. (defun vlaxx-string-p (arg)
  54.   (and (equal (type arg) 'str))
  55.   )
  56. ;;; --------------------------------------------------------------------------
  57. ;;; Predicate for an integer
  58. ;;; Returns T if successfull nil otherwise.
  59. (defun vlaxx-integer-p (arg)
  60.   (and (equal (type arg) 'int))
  61.   )
  62. ;;; --------------------------------------------------------------------------
  63. ;;; Predicate for a real number
  64. ;;; Returns T if successfull nil otherwise.
  65. (defun vlaxx-real-p (arg)
  66.   (and (equal (type arg) 'real))
  67.   )
  68. ;;; --------------------------------------------------------------------------
  69. ;;;添加菜單項到彈出對象。此功能是相同的vla-AddMenuItem ,只是執行錯誤檢查。
  70. ;;;返回菜單項對象,如果成功。如果遇到錯誤的錯誤信息,並打印函數返回零。
  71. (defun AddMenuItem (ParentMenuObject Index Label Macro / res)
  72.       ;;(print (list ParentMenuObject Index Label Macro))
  73.       (if (and (vlaxx-string-p Label)
  74.         (or (vlaxx-integer-p Index)
  75.      (vlaxx-string-p Index)
  76.      (equal (vlax-variant-type Index) 2);; is it a variant integer? 它是一個變體整數
  77.      (equal (vlax-variant-type Index) 8);; is it a variant String? 它是一個變體字符
  78.      )
  79.         (vlaxx-string-p Macro)
  80.         )
  81.    ;; now check for pop menu Object 現在檢查彈出功能表物件
  82.    (if (and (equal (type ParentMenuObject) 'vla-object)
  83.      ;; Check if its a IAcadPopupMenu: 檢查的一個IAcadPopupMenu:
  84.      (vlax-property-available-p ParentMenuObject "ShortcutMenu")
  85.      )
  86.        (progn
  87.       (setq res (vla-AddMenuItem ParentMenuObject Index Label Macro))
  88.       )
  89.        (princ "\n錯誤:ParentMenuObject不是一個有效的功能表物件")
  90.        )
  91.    (princ "\n錯誤:索引,標籤或不正確宏")
  92.    )
  93.       res
  94.       )
  95. ;;; --------------------------------------------------------------------------
  96. ;;; Adds a specific custom popup menu 增加了一個特定的自定義彈出功能表
  97. ;;; to AutoCAD. Returns the newly created popupmenu Object. 到AutoCAD。返回新創建的彈出式功能表物件
  98. ;;(setq Item (sy-addCustomPopupMenu '("AA" "--" ">CC" "C1" "C2" "<C3" "BB")))
  99. (defun sy-addCustomPopupMenu (menulst / acadMenuObject acadPopupMenuGroup NextItem)
  100.       (UnLoadMenuGroup)
  101.       (if (or (null *Custom-Popup*)
  102.        (null (ac:get-Menu-Items *Custom-Popup*))
  103.    )
  104.      (progn
  105.     (setq acadMenuObject    (ac:ReturnMenuObject "SY")
  106.    acadPopupMenuGroup (vla-get-Menus acadMenuObject)
  107.     )
  108.     (if (not (ac:MenuPopExist acadPopupMenuGroup "Custom-Menu"))
  109.         (setq *Custom-Popup* (vla-add acadPopupMenuGroup "Custom-Menu"))
  110.     )
  111.     (setq ItemLstMun 0
  112.    Sublstmun 0
  113.    )
  114.     (foreach N menulst
  115.    (setq lstmun (1+ (vla-get-count *Custom-Popup*)))
  116.    (if (= (type N) (quote str))
  117.        (progn
  118.       (setq JudgeStr (substr N 1 1))
  119.       (cond ((= JudgeStr "-") (vla-addseparator *Custom-Popup* lstmun))
  120.      ((= JudgeStr ">")
  121.       (setq ItemLstMun (+ ItemLstMun 1))
  122.       (setq SubMenu (vla-AddSubMenu *Custom-Popup* lstmun (substr N 2)))
  123.       (setq NextItem T)
  124.       )
  125.      ((or (/= JudgeStr "-") (/= JudgeStr ">"))
  126.       (if NextItem
  127.           (progn
  128.          (if SubItemLstMun
  129.              (setq SubItemLstMun (+ SubItemLstMun 0.1))
  130.              (setq SubItemLstMun (+ ItemLstMun 0.1))
  131.              )
  132.          (setq Sublstmun (+ Sublstmun 1))
  133.          (if (= JudgeStr "<")
  134.              (setq N (substr N 2))
  135.              )
  136.          (setq NewSubItem (AddMenuItem SubMenu
  137.                          Sublstmun
  138.                          N
  139.                          (strcat (CHR 3) (CHR 3) (CHR 16) "(SetItemMun " (rtos SubItemLstMun 2 1) ")" (CHR 32) (CHR 16)))
  140.         )
  141.          (vla-put-helpstring NewSubItem N)
  142.          (if (= JudgeStr "<")
  143.              (setq NextItem nil
  144.             SubItemLstMun nil
  145.             Sublstmun 0
  146.             )
  147.              )
  148.          )
  149.           (progn
  150.          (setq ItemLstMun (+ ItemLstMun 1))
  151.          (setq NewItem (AddMenuItem *Custom-Popup*
  152.                       lstmun
  153.                       N
  154.                       ;;"(SetItemMun 3) ")
  155.                       (strcat (CHR 3) (CHR 3) (CHR 16) "(SetItemMun " (itoa ItemLstMun) ")" (CHR 32) (CHR 16)))
  156.         )
  157.          (vla-put-helpstring NewItem N)
  158.          )
  159.           )
  160.       )
  161.      )
  162.       )
  163.        )
  164.    )
  165.     ;;(vla-SaveAs acadMenuObject "d:/temp.mns"  acPartialMenuGroup)acMenuFileSource
  166.     )
  167.    )
  168.       (menucmd (strcat "P0=" "sy" ".pop2"))
  169.       (menucmd "P0=*")
  170.       (princ)
  171.   )
  172. ;;; --------------------------------------------------------------------------
  173. ;;; disables the custom popup menu 禁用自定義彈出菜單
  174. (defun UnLoadMenuGroup ()
  175.       (if *Custom-Popup*
  176.      (progn
  177.     (mapcar 'vla-delete (ac:get-Menu-Items *Custom-Popup*))
  178.     (menucmd "p0=acad.pop0") ;;;返回到acad系統pop0
  179.      )
  180.       )
  181.       (princ)
  182. )
  183. (defun c:f1 ()
  184.       (setq Item1 (sy-addCustomPopupMenu '("AA" "BB" "CC")))
  185.       (cond ((= Item1 1)  (princ "A1"))
  186.      ((= Item1 2)  (princ "B1"))
  187.      ((= Item1 3)  (princ "C1"))
  188.      )
  189.       )
  190. (defun SetItemMun (Value)
  191.       (setq Item Value)
  192. )
发表于 2010-2-4 16:12:00 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2010-2-5 08:57:00 | 显示全部楼层

AutoCAD右键快捷菜单动态自定义、加载、调用函数

http://www.xdcad.net/forum/showthread.php?s=&threadid=614571

 楼主| 发表于 2010-2-5 17:58:00 | 显示全部楼层

如果用他個程序就不自已寫了,就想學習寫一個,可惜想了好久沒搞出來,所以請高手指點一下

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-10-1 23:29 , Processed in 0.176903 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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