|
使用VLISP动态向AutoCAD菜单条中夹塞菜单条目
- [font=courier new]
- ;; 删除菜单
- (defun C:RemoveBplotMenu (/ MenuBar n i MenuItem Menu tag)
- (setq MenuBar (vla-get-menubar (vlax-get-acad-object)))
- ;; 找菜单“文件(&F)” "&File" tag: ID采用MnFile
- (setq n (vla-get-count MenuBar))
- (setq i (1- n))
- (while (and (>= i 0) ; 没有超过上限
- (/= "ID采用MnFile" (vla-get-tagstring (setq menuitem (vla-item MenuBar i)))) ; 找到"文件"菜单条
- )
- (setq i (1- i))
- )
- (if (< i 0)
- (setq i 0)
- ) ; 如果没有文件菜单, 取第一条菜单
- (setq menu (vla-item MenuBar i))
- ;;遍历文件菜单 删除原来的批量打印条目
- (setq n (vla-get-count menu))
- (setq i (1- n))
- (while (> i 0)
- (setq menuitem (vla-item menu i))
- (setq tag (vla-get-tagstring menuitem))
- (if (member tag '("ID采用mnuBatchPlot" "ID采用mnuBatchPlot2" "ID采用mnuBatchPlotPopup"))
- (vla-delete menuitem)
- )
- (setq i (1- i))
- )
- (princ)
- )
- ;; 添加菜单
- (defun C:AddBplotMenu (/ MenuBar menu menuitem bplotPopupMenu bplotmenuitem cap tag tmp i n)
- (C:RemoveBplotMenu)
- (setq MenuBar (vla-get-menubar (vlax-get-acad-object)))
- ;; 找到菜单“文件(&F)” "&File" tag: ID采用MnFile
- (setq n (vla-get-count MenuBar))
- (setq i (1- n))
- (while (and (>= i 0) ; 没有超过上限
- (/= "ID采用MnFile" (vla-get-tagstring (setq menuitem (vla-item MenuBar i)))) ; 找到"文件"菜单条
- )
- (setq i (1- i))
- )
- (if (< i 0) ; 如果没有文件菜单, 取第一条菜单
- (setq i 0)
- )
- (setq menu (vla-item MenuBar i))
- ;; 找到打印菜单项, 设置当前插入位置
- (setq i 0)
- (setq n (vla-get-count menu))
- (while (and (< i n) ; 没有超过上限
- (/= "ID采用Print" (vla-get-tagstring (setq menuitem (vla-item menu i)))) ; 找到"打印"菜单条
- )
- (setq i (1+ i))
- )
- (if (= i n) ; 如果没有找到"打印"菜单条, 插在倒数第二条.
- (setq i (- n 2))
- )
- ;; 在当前插入位置的下面一条添加批量打印条目
- (setq bplotmenuitem
- (vla-addmenuitem
- menu
- (setq i (1+ i))
- "批量打印(&B)..."
- "\003\003采用BatchPlot "
- )
- )
- (vla-put-label bplotmenuitem "(if,
- (eq,$(getvar,blockeditor),1),~)批量打印(&B)...")
- (vla-put-tagstring bplotmenuitem "ID采用mnuBatchPlot")
- (vla-put-helpstring bplotmenuitem "批量打印、批量生成布局、批量分图实用工具程序")
- ;; 再在下面创建下级批量打印实用工具子菜单
- (setq bplotPopupMenu (vla-addsubmenu menu (1+ i) "批量打印实用工具(&L)"))
- ; (vla-put-tagstring bplotPopupMenu "ID采用mnuBatchPlotPopup") ;不知道为什么不行.
- ;; 下面这段代码设置批量打印实用工具子菜单的Tag
- (setq n (vla-get-count menu))
- (setq i (1- n))
- (while (> i 0)
- (setq menuitem (vla-item menu i))
- (setq cap (vla-get-caption menuitem))
- (if (= "批量打印实用工具(&L)" cap)
- (vla-put-tagstring menuitem "ID采用mnuBatchPlotPopup")
- )
- (setq i (1- i))
- )
- (setq i 0)
-
- ;; 下面是子菜单条目
- (setq tmp
- (vla-addmenuitem
- bplotPopupMenu
- (setq i (1+ i))
- "批量打印(&C)..."
- "\003\003采用bp采用doPlot "
- )
- )
- (vla-put-label tmp "(if,
- (eq,$(getvar,blockeditor),1),~)批量打印(&C)...")
- (vla-put-helpstring tmp "批量打印图纸,直接发送到物理打印机或虚拟打印机")
- (setq tmp
- (vla-addmenuitem
- bplotPopupMenu
- (setq i (1+ i))
- "批量生成布局(&L)..."
- "\003\003采用bp采用doLayout "
- )
- )
- (vla-put-label tmp "(if,
- (eq,$(getvar,blockeditor),1),~)批量生成布局(&L)...")
- (vla-put-helpstring tmp "批量按当前的打印设置生成布局,每个图框一个布局")
- (setq tmp
- (vla-addmenuitem
- bplotPopupMenu
- (setq i (1+ i))
- "批量生成PLT文件(&P)..."
- "\003\003采用bp采用doPlotFile "
- )
- )
- (vla-put-label tmp "(if,
- (eq,$(getvar,blockeditor),1),~)批量生成PLT文件(&P)...")
- (vla-put-helpstring tmp "批量生成PLT打印文件供机房绘图仪服务器统一打印")
- (setq tmp
- (vla-addmenuitem
- bplotPopupMenu
- (setq i (1+ i))
- "批量切分图纸(&W)..."
- "\003\003采用bp采用doWblock "
- )
- )
- (vla-put-label tmp "(if,
- (eq,$(getvar,blockeditor),1),~)批量切分图纸(&W)...")
- (vla-put-helpstring tmp "自动根据图框切分图纸,每个图框一个DWG文件,供归档用")
- (setq tmp
- (vla-addmenuitem
- bplotPopupMenu
- (setq i (1+ i))
- "打印现有布局(&A)..."
- "\003\003采用bp采用doPlotLayout "
- )
- )
- (vla-put-label tmp "(if,
- (eq,$(getvar,blockeditor),1),~)打印现有布局(&A)...")
- (vla-put-helpstring tmp "按现有的布局显示顺序批量打印现有的布局空间")
- (vla-AddSeparator
- bplotPopupMenu
- (setq i (1+ i))
- )
- (setq tmp (vla-addmenuitem
- bplotPopupMenu
- (setq i (1+ i))
- "清除批量打印数据(&D)"
- "\003\003采用DeleteBPlotData "
- )
- )
- (vla-AddSeparator
- bplotPopupMenu
- (setq i (1+ i))
- )
- (vla-addmenuitem
- bplotPopupMenu
- (setq i (1+ i))
- "捐助作者支持开发(&D)"
- "\003\003采用Browser (findfile "donate.htm") "
- )
- (vla-addmenuitem
- bplotPopupMenu
- (setq i (1+ i))
- "访问软件主页(&M)"
- "\003\003采用Browser [url]http://fresco.yo2.cn/archives/92111[/url] "
- )
- (vla-addmenuitem
- bplotPopupMenu
- (setq i (1+ i))
- "批量打印帮助(&H)"
- "\003\003采用Browser (findfile "bp采用help.htm") "
- )
-
- (princ)
- )
- ;; 加载批量打印菜单
- (C:AddBplotMenu)
- (princ)[/font]
复制代码 |
|