秋枫 发表于 2009-6-20 19:27:00

[原创]使用VLISP动态向AutoCAD菜单条中夹塞菜单条目

<p></p><p><a href="http://fresco.yo2.cn/archives/642094#more-642094">http://fresco.yo2.cn/archives/642094#more-642094</a></p><p><a title="Permanent Link to 使用VLISP动态向AutoCAD菜单条中夹塞菜单条目" href="http://fresco.yo2.cn/archives/642094" rel="bookmark">使用VLISP动态向AutoCAD菜单条中夹塞菜单条目</a>Posted by Fresco in <a title="查看 原创作品 的全部文章" href="http://fresco.yo2.cn/archives/category/works" rel="category tag"><font color="#006699">原创作品</font></a><br/>&nbsp;</p><div class="post-content"><p><a href="http://image-001.yo2cdn.com/wp-content/uploads/33/3374/2007/11/2007-11-25_183807.gif" target="_blank"><img class="alignnone size-full wp-image-555723" title="Batchplot 3.2.2 菜单图片" height="359" alt="Batchplot 3.2.2 菜单图片" src="http://image-001.yo2cdn.com/wp-content/uploads/33/3374/2007/11/2007-11-25_183807.gif" width="508"/></a></p><p>程序思路就是利用ActiveX对像模型提供的方法和属性。<br/>目前的问题:设置条目的图标和快捷键(比如Ctrl+Shift+P)不知如何实现。</p><p></p><p><code>源代码:</code></p><p></p><p><code></code></p><div><code>AddBplotMenu.lsp</code></div><blockquote><div><code>;; 删除菜单</code></div><div><code>(defun C:RemoveBplotMenu (/ MenuBar n i MenuItem Menu tag)</code></div><div><code>&nbsp; (setq MenuBar (vla-get-menubar (vlax-get-acad-object)))</code></div><div><code>&nbsp; ;; 找菜单“文件(&amp;F)” "&amp;File" tag: ID_MnFile<br/>&nbsp; (setq n (vla-get-count MenuBar))<br/>&nbsp; (setq i (1- n))<br/>&nbsp; (while (and (&gt;= i 0)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; 没有超过上限<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (/= "ID_MnFile" (vla-get-tagstring (setq menuitem (vla-item MenuBar i)))) ; 找到"文件"菜单条<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp; (setq i (1- i))<br/>&nbsp; )<br/>&nbsp; (if (&lt; i 0)<br/>&nbsp;&nbsp;&nbsp; (setq i 0)<br/>&nbsp; )&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; 如果没有文件菜单, 取第一条菜单<br/>&nbsp; (setq menu (vla-item MenuBar i))</code></div><div><code>&nbsp; ;;遍历文件菜单 删除原来的批量打印条目<br/>&nbsp; (setq n (vla-get-count menu))<br/>&nbsp; (setq i (1- n))<br/>&nbsp; (while (&gt; i 0)<br/>&nbsp;&nbsp;&nbsp; (setq menuitem (vla-item menu i))<br/>&nbsp;&nbsp;&nbsp; (setq tag (vla-get-tagstring menuitem))<br/>&nbsp;&nbsp;&nbsp; (if (member tag '("ID_mnuBatchPlot" "ID_mnuBatchPlot2" "ID_mnuBatchPlotPopup"))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (vla-delete menuitem)<br/>&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp; (setq i (1- i))<br/>&nbsp; )</code></div><div><code>&nbsp; (princ)<br/>)</code></div><div><code>;; 添加菜单</code></div><div><code>(defun C:AddBplotMenu (/ MenuBar menu menuitem bplotPopupMenu bplotmenuitem cap tag tmp i n)</code></div><div><code>&nbsp; (C:RemoveBplotMenu)</code></div><div><code>&nbsp; (setq MenuBar (vla-get-menubar (vlax-get-acad-object)))</code></div><div><code>&nbsp; ;; 找到菜单“文件(&amp;F)” "&amp;File" tag: ID_MnFile<br/>&nbsp; (setq n (vla-get-count MenuBar))<br/>&nbsp; (setq i (1- n))<br/>&nbsp; (while (and (&gt;= i 0)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; 没有超过上限<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (/= "ID_MnFile" (vla-get-tagstring (setq menuitem (vla-item MenuBar i)))) ; 找到"文件"菜单条<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp; (setq i (1- i))<br/>&nbsp; )<br/>&nbsp; (if (&lt; i 0)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; 如果没有文件菜单, 取第一条菜单<br/>&nbsp;&nbsp;&nbsp; (setq i 0)<br/>&nbsp; )<br/>&nbsp; (setq menu (vla-item MenuBar i))</code></div><div><code>&nbsp; ;; 找到打印菜单项, 设置当前插入位置<br/>&nbsp; (setq i 0)<br/>&nbsp; (setq n (vla-get-count menu))<br/>&nbsp; (while (and (&lt; i n)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; 没有超过上限<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (/= "ID_Print" (vla-get-tagstring (setq menuitem (vla-item menu i)))) ; 找到"打印"菜单条<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp; (setq i (1+ i))<br/>&nbsp; )<br/>&nbsp; (if (= i n)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; 如果没有找到"打印"菜单条, 插在倒数第二条.<br/>&nbsp;&nbsp;&nbsp; (setq i (- n 2))<br/>&nbsp; )</code></div><div><code>&nbsp; ;; 在当前插入位置的下面一条添加批量打印条目<br/>&nbsp; (setq bplotmenuitem<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (vla-addmenuitem<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; menu<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq i (1+ i))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "批量打印(&amp;B)..."<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "\003\003_BatchPlot "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp; )<br/>&nbsp; (vla-put-label bplotmenuitem "$(if,$(eq,$(getvar,blockeditor),1),~)批量打印(&amp;B)...")<br/>&nbsp; (vla-put-tagstring bplotmenuitem "ID_mnuBatchPlot")<br/>&nbsp; (vla-put-helpstring bplotmenuitem "批量打印、批量生成布局、批量分图实用工具程序")</code></div><div><code>&nbsp; ;; 再在下面创建下级批量打印实用工具子菜单<br/>&nbsp; (setq bplotPopupMenu (vla-addsubmenu menu (1+ i) "批量打印实用工具(&amp;L)"))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; (vla-put-tagstring bplotPopupMenu "ID_mnuBatchPlotPopup") ;不知道为什么不行.<br/>&nbsp; ;; 下面这段代码设置批量打印实用工具子菜单的Tag<br/>&nbsp; (setq n (vla-get-count menu))<br/>&nbsp; (setq i (1- n))<br/>&nbsp; (while (&gt; i 0)<br/>&nbsp;&nbsp;&nbsp; (setq menuitem (vla-item menu i))<br/>&nbsp;&nbsp;&nbsp; (setq cap (vla-get-caption menuitem))<br/>&nbsp;&nbsp;&nbsp; (if (= "批量打印实用工具(&amp;L)" cap)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (vla-put-tagstring menuitem "ID_mnuBatchPlotPopup")<br/>&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp; (setq i (1- i))<br/>&nbsp; )</code></div><div><code>&nbsp; (setq i 0)<br/>&nbsp;<br/>&nbsp; ;; 下面是子菜单条目<br/>&nbsp; (setq tmp<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (vla-addmenuitem<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bplotPopupMenu<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq i (1+ i))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "批量打印(&amp;C)..."<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "\003\003_bp_doPlot "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp; )<br/>&nbsp; (vla-put-label tmp "$(if,$(eq,$(getvar,blockeditor),1),~)批量打印(&amp;C)...")<br/>&nbsp; (vla-put-helpstring tmp "批量打印图纸,直接发送到物理打印机或虚拟打印机")</code></div><div><code>&nbsp; (setq tmp<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (vla-addmenuitem<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bplotPopupMenu<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq i (1+ i))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "批量生成布局(&amp;L)..."<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "\003\003_bp_doLayout "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp; )<br/>&nbsp; (vla-put-label tmp "$(if,$(eq,$(getvar,blockeditor),1),~)批量生成布局(&amp;L)...")<br/>&nbsp; (vla-put-helpstring tmp "批量按当前的打印设置生成布局,每个图框一个布局")</code></div><div><code>&nbsp; (setq tmp<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (vla-addmenuitem<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bplotPopupMenu<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq i (1+ i))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "批量生成PLT文件(&amp;P)..."<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "\003\003_bp_doPlotFile "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp; )<br/>&nbsp; (vla-put-label tmp "$(if,$(eq,$(getvar,blockeditor),1),~)批量生成PLT文件(&amp;P)...")<br/>&nbsp; (vla-put-helpstring tmp "批量生成PLT打印文件供机房绘图仪服务器统一打印")</code></div><div><code>&nbsp; (setq tmp<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (vla-addmenuitem<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bplotPopupMenu<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq i (1+ i))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "批量切分图纸(&amp;W)..."<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "\003\003_bp_doWblock "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp; )<br/>&nbsp; (vla-put-label tmp "$(if,$(eq,$(getvar,blockeditor),1),~)批量切分图纸(&amp;W)...")<br/>&nbsp; (vla-put-helpstring tmp "自动根据图框切分图纸,每个图框一个DWG文件,供归档用")</code></div><div><code>&nbsp; (setq tmp<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (vla-addmenuitem<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bplotPopupMenu<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq i (1+ i))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "打印现有布局(&amp;A)..."<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "\003\003_bp_doPlotLayout "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp; )<br/>&nbsp; (vla-put-label tmp "$(if,$(eq,$(getvar,blockeditor),1),~)打印现有布局(&amp;A)...")<br/>&nbsp; (vla-put-helpstring tmp "按现有的布局显示顺序批量打印现有的布局空间")</code></div><div><code>&nbsp; (vla-AddSeparator<br/>&nbsp;&nbsp;&nbsp; bplotPopupMenu<br/>&nbsp;&nbsp;&nbsp; (setq i (1+ i))<br/>&nbsp; )</code></div><div><code>&nbsp; (setq tmp (vla-addmenuitem<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bplotPopupMenu<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (setq i (1+ i))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "清除批量打印数据(&amp;D)"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "\003\003_DeleteBPlotData "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp; )</code></div><div><code><br/>&nbsp; (vla-AddSeparator<br/>&nbsp;&nbsp;&nbsp; bplotPopupMenu<br/>&nbsp;&nbsp;&nbsp; (setq i (1+ i))<br/>&nbsp; )</code></div><div><code>&nbsp; (vla-addmenuitem<br/>&nbsp;&nbsp;&nbsp; bplotPopupMenu<br/>&nbsp;&nbsp;&nbsp; (setq i (1+ i))<br/>&nbsp;&nbsp;&nbsp; "捐助作者支持开发(&amp;D)"<br/>&nbsp;&nbsp;&nbsp; "\003\003_Browser (findfile \"donate.htm\") "<br/>&nbsp; )</code></div><div><code>&nbsp; (vla-addmenuitem<br/>&nbsp;&nbsp;&nbsp; bplotPopupMenu<br/>&nbsp;&nbsp;&nbsp; (setq i (1+ i))<br/>&nbsp;&nbsp;&nbsp; "访问软件主页(&amp;M)"<br/>&nbsp;&nbsp;&nbsp; "\003\003_Browser <a href="http://fresco.yo2.cn/archives/92111"><font color="#006699">http://fresco.yo2.cn/archives/92111</font></a> "<br/>&nbsp; )</code></div><div><code>&nbsp; (vla-addmenuitem<br/>&nbsp;&nbsp;&nbsp; bplotPopupMenu<br/>&nbsp;&nbsp;&nbsp; (setq i (1+ i))<br/>&nbsp;&nbsp;&nbsp; "批量打印帮助(&amp;H)"<br/>&nbsp;&nbsp;&nbsp; "\003\003_Browser (findfile \"bp_help.htm\") "<br/>&nbsp; )<br/>&nbsp;<br/>&nbsp; (princ)<br/>)</code></div><div><code>;; 加载批量打印菜单<br/>(C:AddBplotMenu)</code></div><div><code>(princ)</code></div></blockquote></div>

lxl304712346 发表于 2024-9-5 23:33:27

怎么用语句删除cad的自带菜单?

wmh-3816 发表于 2023-8-26 19:22:51

谢谢分享谢谢分享

goo007 发表于 2020-4-6 00:26:48


好东东,免去麻烦了{:1_1:}

aicr317 发表于 2009-6-20 20:51:00

沙发坐好慢慢看!!

clh521 发表于 2009-6-20 21:06:00

<p>好东西,严重收藏!</p>

chpmould 发表于 2009-6-21 08:47:00

看贴必顶,回贴是一种美德...

dinosaurhxe2 发表于 2009-6-21 21:59:00

支持!<br/>学习!<br/>

happyboy75 发表于 2009-6-22 17:00:00

<p>好东东,免去麻烦了</p>

5061220 发表于 2009-8-22 17:00:00

<p>秋风大哥!</p><p>收藏!</p><p>学习了!</p>

zhanzhe 发表于 2009-8-22 17:03:00

<p>太深奧了!還是想頂一下!</p>

xiaoma1023 发表于 2009-8-22 23:00:00

好东西,严重收藏

zwqgdhl 发表于 2011-7-17 09:02:39

同意,好东西,严重收藏,还有谢谢
页: [1] 2 3
查看完整版本: [原创]使用VLISP动态向AutoCAD菜单条中夹塞菜单条目