[原创]使用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/> </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> (setq MenuBar (vla-get-menubar (vlax-get-acad-object)))</code></div><div><code> ;; 找菜单“文件(&F)” "&File" tag: ID_MnFile<br/> (setq n (vla-get-count MenuBar))<br/> (setq i (1- n))<br/> (while (and (>= i 0) ; 没有超过上限<br/> (/= "ID_MnFile" (vla-get-tagstring (setq menuitem (vla-item MenuBar i)))) ; 找到"文件"菜单条<br/> )<br/> (setq i (1- i))<br/> )<br/> (if (< i 0)<br/> (setq i 0)<br/> ) ; 如果没有文件菜单, 取第一条菜单<br/> (setq menu (vla-item MenuBar i))</code></div><div><code> ;;遍历文件菜单 删除原来的批量打印条目<br/> (setq n (vla-get-count menu))<br/> (setq i (1- n))<br/> (while (> i 0)<br/> (setq menuitem (vla-item menu i))<br/> (setq tag (vla-get-tagstring menuitem))<br/> (if (member tag '("ID_mnuBatchPlot" "ID_mnuBatchPlot2" "ID_mnuBatchPlotPopup"))<br/> (vla-delete menuitem)<br/> )<br/> (setq i (1- i))<br/> )</code></div><div><code> (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> (C:RemoveBplotMenu)</code></div><div><code> (setq MenuBar (vla-get-menubar (vlax-get-acad-object)))</code></div><div><code> ;; 找到菜单“文件(&F)” "&File" tag: ID_MnFile<br/> (setq n (vla-get-count MenuBar))<br/> (setq i (1- n))<br/> (while (and (>= i 0) ; 没有超过上限<br/> (/= "ID_MnFile" (vla-get-tagstring (setq menuitem (vla-item MenuBar i)))) ; 找到"文件"菜单条<br/> )<br/> (setq i (1- i))<br/> )<br/> (if (< i 0) ; 如果没有文件菜单, 取第一条菜单<br/> (setq i 0)<br/> )<br/> (setq menu (vla-item MenuBar i))</code></div><div><code> ;; 找到打印菜单项, 设置当前插入位置<br/> (setq i 0)<br/> (setq n (vla-get-count menu))<br/> (while (and (< i n) ; 没有超过上限<br/> (/= "ID_Print" (vla-get-tagstring (setq menuitem (vla-item menu i)))) ; 找到"打印"菜单条<br/> )<br/> (setq i (1+ i))<br/> )<br/> (if (= i n) ; 如果没有找到"打印"菜单条, 插在倒数第二条.<br/> (setq i (- n 2))<br/> )</code></div><div><code> ;; 在当前插入位置的下面一条添加批量打印条目<br/> (setq bplotmenuitem<br/> (vla-addmenuitem<br/> menu<br/> (setq i (1+ i))<br/> "批量打印(&B)..."<br/> "\003\003_BatchPlot "<br/> )<br/> )<br/> (vla-put-label bplotmenuitem "$(if,$(eq,$(getvar,blockeditor),1),~)批量打印(&B)...")<br/> (vla-put-tagstring bplotmenuitem "ID_mnuBatchPlot")<br/> (vla-put-helpstring bplotmenuitem "批量打印、批量生成布局、批量分图实用工具程序")</code></div><div><code> ;; 再在下面创建下级批量打印实用工具子菜单<br/> (setq bplotPopupMenu (vla-addsubmenu menu (1+ i) "批量打印实用工具(&L)"))<br/> ; (vla-put-tagstring bplotPopupMenu "ID_mnuBatchPlotPopup") ;不知道为什么不行.<br/> ;; 下面这段代码设置批量打印实用工具子菜单的Tag<br/> (setq n (vla-get-count menu))<br/> (setq i (1- n))<br/> (while (> i 0)<br/> (setq menuitem (vla-item menu i))<br/> (setq cap (vla-get-caption menuitem))<br/> (if (= "批量打印实用工具(&L)" cap)<br/> (vla-put-tagstring menuitem "ID_mnuBatchPlotPopup")<br/> )<br/> (setq i (1- i))<br/> )</code></div><div><code> (setq i 0)<br/> <br/> ;; 下面是子菜单条目<br/> (setq tmp<br/> (vla-addmenuitem<br/> bplotPopupMenu<br/> (setq i (1+ i))<br/> "批量打印(&C)..."<br/> "\003\003_bp_doPlot "<br/> )<br/> )<br/> (vla-put-label tmp "$(if,$(eq,$(getvar,blockeditor),1),~)批量打印(&C)...")<br/> (vla-put-helpstring tmp "批量打印图纸,直接发送到物理打印机或虚拟打印机")</code></div><div><code> (setq tmp<br/> (vla-addmenuitem<br/> bplotPopupMenu<br/> (setq i (1+ i))<br/> "批量生成布局(&L)..."<br/> "\003\003_bp_doLayout "<br/> )<br/> )<br/> (vla-put-label tmp "$(if,$(eq,$(getvar,blockeditor),1),~)批量生成布局(&L)...")<br/> (vla-put-helpstring tmp "批量按当前的打印设置生成布局,每个图框一个布局")</code></div><div><code> (setq tmp<br/> (vla-addmenuitem<br/> bplotPopupMenu<br/> (setq i (1+ i))<br/> "批量生成PLT文件(&P)..."<br/> "\003\003_bp_doPlotFile "<br/> )<br/> )<br/> (vla-put-label tmp "$(if,$(eq,$(getvar,blockeditor),1),~)批量生成PLT文件(&P)...")<br/> (vla-put-helpstring tmp "批量生成PLT打印文件供机房绘图仪服务器统一打印")</code></div><div><code> (setq tmp<br/> (vla-addmenuitem<br/> bplotPopupMenu<br/> (setq i (1+ i))<br/> "批量切分图纸(&W)..."<br/> "\003\003_bp_doWblock "<br/> )<br/> )<br/> (vla-put-label tmp "$(if,$(eq,$(getvar,blockeditor),1),~)批量切分图纸(&W)...")<br/> (vla-put-helpstring tmp "自动根据图框切分图纸,每个图框一个DWG文件,供归档用")</code></div><div><code> (setq tmp<br/> (vla-addmenuitem<br/> bplotPopupMenu<br/> (setq i (1+ i))<br/> "打印现有布局(&A)..."<br/> "\003\003_bp_doPlotLayout "<br/> )<br/> )<br/> (vla-put-label tmp "$(if,$(eq,$(getvar,blockeditor),1),~)打印现有布局(&A)...")<br/> (vla-put-helpstring tmp "按现有的布局显示顺序批量打印现有的布局空间")</code></div><div><code> (vla-AddSeparator<br/> bplotPopupMenu<br/> (setq i (1+ i))<br/> )</code></div><div><code> (setq tmp (vla-addmenuitem<br/> bplotPopupMenu<br/> (setq i (1+ i))<br/> "清除批量打印数据(&D)"<br/> "\003\003_DeleteBPlotData "<br/> )<br/> )</code></div><div><code><br/> (vla-AddSeparator<br/> bplotPopupMenu<br/> (setq i (1+ i))<br/> )</code></div><div><code> (vla-addmenuitem<br/> bplotPopupMenu<br/> (setq i (1+ i))<br/> "捐助作者支持开发(&D)"<br/> "\003\003_Browser (findfile \"donate.htm\") "<br/> )</code></div><div><code> (vla-addmenuitem<br/> bplotPopupMenu<br/> (setq i (1+ i))<br/> "访问软件主页(&M)"<br/> "\003\003_Browser <a href="http://fresco.yo2.cn/archives/92111"><font color="#006699">http://fresco.yo2.cn/archives/92111</font></a> "<br/> )</code></div><div><code> (vla-addmenuitem<br/> bplotPopupMenu<br/> (setq i (1+ i))<br/> "批量打印帮助(&H)"<br/> "\003\003_Browser (findfile \"bp_help.htm\") "<br/> )<br/> <br/> (princ)<br/>)</code></div><div><code>;; 加载批量打印菜单<br/>(C:AddBplotMenu)</code></div><div><code>(princ)</code></div></blockquote></div> 怎么用语句删除cad的自带菜单? 谢谢分享谢谢分享好东东,免去麻烦了{:1_1:} 沙发坐好慢慢看!! <p>好东西,严重收藏!</p> 看贴必顶,回贴是一种美德... 支持!<br/>学习!<br/> <p>好东东,免去麻烦了</p> <p>秋风大哥!</p><p>收藏!</p><p>学习了!</p> <p>太深奧了!還是想頂一下!</p> 好东西,严重收藏 同意,好东西,严重收藏,还有谢谢