尘缘一生 发表于 2024-3-9 21:26:13

菜单系统的加载速度问题

本帖最后由 尘缘一生 于 2024-3-12 10:54 编辑

下面以《三领设计 V3.0》菜单系统测试如下:

一:主要以COMMAND 方式写法
这种写法,速度较慢,但慢的不明显,差别不大,较低版本CAD支持广泛
;;删除菜单----(一级)------
(defun delmenu ()
(sl:del-fil (strcat sl-path0 "\\" "SLMENU.cuix"))
(sl:del-fil (strcat sl-path0 "\\" "SLMENU.bak.cuix"))
(sl:del-fil (strcat sl-path0 "\\" "SLMENU.mns"))
(sl:del-fil (strcat sl-path0 "\\" "SLMENU.mnr"))
(sl:del-fil (strcat sl-path0 "\\" "SLMENU_light.mnr"))
)
;;菜单显示程序----(一级)------
(defun slmenuk (/ i menuk k1 k2 k3 k4 k5 k6 k7 k8 k9 k10 k11 s1)
(setq
    k1 (slmsg "下拉MENU" "┰MENU" "downMENU")
    k2 (slmsg "图标菜单" "瓜夹垫虫" "IconMenu")
    k3 (slmsg "展开" "甶秨" "open")
    k4 (slmsg "开" "秨" "open")
    k5 (slmsg "关" "闽" "close")
    k6 (slmsg "SL-绘制" "SL-酶籹" "SL-draw")
    k7 (slmsg "SL-钢筋" "SL-葵惮" "SL-steelbar")
    k8 (slmsg "SL-查询-缩放" "SL-琩高-罽" "SL-query-zoom")
    k9 (slmsg "SL-编辑" "SL-絪胯" "SL-edit")
    k10 (slmsg "SL-常用" "SL-盽ノ" "SL-Common")
    k11 (slmsg "SL-文件" "SL-ゅン" "SL-file")
)
(setq menuk (readkey (strcat sl-path0 "\\" "main.ini") k2))
(command "-toolbar" k11 "S")
(if (or (= menuk nil) (= menuk k4))
    (progn
      (rwritekey (strcat sl-path0 "\\" "main.ini") k2 k4)
      (command "-toolbar" k6 "S") ; 显示工具栏
      (command "-toolbar" k7 "S")
      (command "-toolbar" k8 "S")
      (command "-toolbar" k9 "S")
      (command "-toolbar" k10 "S")
    )
    (progn
      (rwritekey (strcat sl-path0 "\\" "main.ini") k2 k5)
      (command "-toolbar" k6 "H")
      (command "-toolbar" k7 "H")
      (command "-toolbar" k8 "H")
      (command "-toolbar" k9 "H")
      (command "-toolbar" k10 "H")
    )
)
(setq s1 (readkey (strcat sl-path0 "\\" "main.ini") k1))
(if (or (= s1 nil) (= s1 k3))
    (progn
      (setq s1 k3)
      (rwritekey (strcat sl-path0 "\\" "main.ini") k1 k3)
    )
)
(if (>= (setq i (vla-get-count (vla-get-menubar *Acad*))) 16) (setq i 16))
(if (= s1 k3) ;展开
    (progn
      (menucmd (strcat "p" (itoa (1+ i)) "=+SLMENU.POP1"))
      (menucmd (strcat "p" (itoa (+ i 2)) "=+SLMENU.POP2"))
      (menucmd (strcat "p" (itoa (+ i 3)) "=+SLMENU.POP3"))
      (menucmd (strcat "p" (itoa (+ i 4)) "=+SLMENU.POP4"))
      (menucmd (strcat "p" (itoa (+ i 5)) "=+SLMENU.POP5"))
      (menucmd (strcat "p" (itoa (+ i 6)) "=+SLMENU.POP6"))
      (menucmd (strcat "p" (itoa (+ i 7)) "=+SLMENU.POP7"))
      (menucmd (strcat "p" (itoa (+ i 8)) "=+SLMENU.POP8"))
    )
    (menucmd (strcat "p" (itoa (1+ i)) "=+SLMENU.POP1"))
)
)
;;下拉菜单开关--k: t 展开 nil 合并----(一级)----
(defun showxlmenu (k / k1 k2 k3)
(setq
    k1 (slmsg "下拉MENU" "┰MENU" "downMENU")
    k2 (slmsg "展开" "甶秨" "open")
    k3 (slmsg "合并" "" "close")
)
(if (= k t)
    (rwritekey (strcat sl-path0 "\\" "main.ini") k1 k2)
    (rwritekey (strcat sl-path0 "\\" "main.ini") k1 k3)
)
(menu00)
)
;;图标菜单开关-----(一级)------
;;kt 开 nil 关
(defun opmenu (k / k1 k2 k3)
(setq
    k1 (slmsg "图标菜单" "瓜夹垫虫" "IconMenu")
    k2 (slmsg "开" "秨" "open")
    k3 (slmsg "关" "闽" "close")
)
(if (= k t)
    (rwritekey (strcat sl-path0 "\\" "main.ini") k1 k2)
    (rwritekey (strcat sl-path0 "\\" "main.ini") k1 k3)
)
(menu00)
)
;;专业设置--k: t 建筑 nil 机械----(一级)----
(defun showzymenu (k / k1 k2 k3)
(setq
    k1 (slmsg "专业" "盡穨" "major")
    k2 (slmsg "建筑" "縱" "Architecture")
    k3 (slmsg "机械" "诀瘪" "Mechanical")
)
(if (= k t)
    (rwritekey (strcat sl-path0 "\\" "main.ini") k1 k2)
    (rwritekey (strcat sl-path0 "\\" "main.ini") k1 k3)
)
(menu00)
)
;;加载菜单------
(defun menu00 (/ s s1 k k1 k2 k3 ofa)
(setq ofa (getvar "FILEDIA"))
(setvar "FILEDIA" 0)
(if (menugroup "SLMENU")
    (command "MENUUNLOAD" "SLMENU")
)
(setq
    k1 (slmsg "下拉MENU" "┰MENU" "downMENU")
    k2 (slmsg "专业" "盡穨" "major")
    k3 (slmsg "图标菜单" "瓜夹垫虫" "IconMenu")
)
(if (= (readkey (strcat sl-path0 "\\" "main.ini") k1) nil)
    (rwritekey (strcat sl-path0 "\\" "main.ini") k1 (slmsg "展开" "甶秨" "open"))
)
(if (= (readkey (strcat sl-path0 "\\" "main.ini") k2) nil)
    (rwritekey (strcat sl-path0 "\\" "main.ini") k2 (slmsg "建筑" "縱" "Architecture"))
)
(if (= (readkey (strcat sl-path0 "\\" "main.ini") k3) nil)
    (rwritekey (strcat sl-path0 "\\" "main.ini") k3 (slmsg "开" "秨" "open"))
)
(setq k (slmsg "版本" "セ" "version"))
(cond
    ((getcname "tpscale")
      (setq s (slmsg "天正" "ぱタ" "TianzhengDesign"))
    )
    ((getcname "sascl")
      (setq s (slmsg "浩辰" "疎ò" "TaochenDesign"))
    )
    ((= $Lgver 1) ;简体
      (setq s "简体中文")
    )
    ((= $Lgver 2) ;繁体版
      (setq s "羉砰いゅ")
    )
    ((= $Lgver 3) ;英文
      (setq s "Englishversion")
    )
)
(setq s1 (readkey (strcat sl-path0 "\\" "main.ini") k))
(if (or (/= s1 s) (= nil s1))
    (rwritekey (strcat sl-path0 "\\" "main.ini") k s)
)
(delmenu) ;需要删除
(cond
    ((= $Lgver 1); (/= (getcname "sascl") nil)) ;;CAD是简体中文版包括浩辰中望
      (load (strcat sl-path0 "\\" "Support" "\\" "slmenu-bz.VLX"))
    )
    ((= $Lgver 2) ;繁体版
      (load (strcat sl-path0 "\\" "Support" "\\" "slmenu-ft.VLX"))
    )
    ((= $Lgver 3) ;英文版
      (load (strcat sl-path0 "\\" "Support" "\\" "slmenu-en.VLX"))
    )
)
(command "MENULOAD" (strcat sl-path0 "\\" "SLMENU.mns"))
(slmenuk) ;菜单显示, 此处确保显示正确
(setvar "FILEDIA" ofa)
)二:第二种,函数写法
这种写法,较快,但有限,三领系统,快0.1秒,低版本CAD可能支持有问题;;======【菜单系统开始】========

;;菜单列表---(一级)----
;;返回 ("ACAD" "APPMANAGER" "SLMENU")
(defun sl:MenuGroups-ListAll (/ out)
(vl-catch-all-apply
    (function
      (lambda ()
      (vlax-for each (vla-get-menugroups *Acad*)
          (setq out (cons (vla-get-name each) out))
      )
      )
    )
)
(if out (reverse out) (setq out '("ACAD" "APPMANAGER")))
out
)
;;菜单是否存在
;;(sl:MenuGroup-Exists-p "SLMENU")
;;返回 2 (菜单序列 0 1 2) 不存在返回nil
(defun sl:MenuGroup-Exists-p (mgroup / lst)
(setq lst (sl:MenuGroups-ListAll))
(if (member (strcase mgroup) (mapcar 'strcase lst))
    (vl-position mgroup lst)
)
)
;;卸载菜单----(一级)---
;;(Menu-Unload "SLMENU")
(defun Menu-Unload (mgroup / omg)
(if (and
      (sl:MenuGroup-Exists-p mgroup)
      (setq omg (vla-item (vla-get-menugroups *Acad*) mgroup))
      )
    (progn
      (vla-unload omg)
      (vlax-release-object omg)
      T
    )
)
)
;;加载菜单----(一级)----
;;(Menu-load "SLMENU")
(defun Menu-load (mgroup)
(if (not (sl:MenuGroup-Exists-p mgroup))
    (vlax-release-object (vla-load (vla-get-menugroups *Acad*) mgroup))
)
)
;;工具条Vla集合---(一级)----
;;(sl:Toolbars "SLMENU")
(defun sl:Toolbars (mgroup)
(if (sl:MenuGroup-Exists-p mgroup)
    (vla-get-toolbars (vla-item (vla-get-menugroups *Acad*) (vl-position (strcase mgroup) (mapcar 'strcase (sl:MenuGroups-ListAll)))))
)
)
;;工具条列表----(一级)------
;;(sl:ToolbarsList "SLMENU")->("SL-常用" "SL-文件" "SL-查询-缩放" "SL-编辑" "SL-绘制" "SL-钢筋")
(defun sl:ToolbarsList (mgroup / tb out)
(if (setq tb (sl:Toolbars mgroup))
    (vlax-for each tb
      (setq out (cons (vla-get-name each) out))
    )
)
(if tb (vlax-release-object tb))
(reverse out)
)
;;工具条是否存在---(一级)-----
;;(sl:Toolbar-Exists-p "SLMENU" "SL-钢筋")
;返回 0 (工具条序列 0 1 2) 不存在返回 nil
(defun sl:Toolbar-Exists-p (mgroup tbname)
(if (and
      (sl:MenuGroup-Exists-p mgroup)
      (member (strcase tbname) (mapcar 'strcase (sl:ToolbarsList mgroup)))
      )
    (vl-position tbname (sl:ToolbarsList mgroup))
    nil
)
)
;;指定工具条----(一级)-------
;;(sl:Toolbar "SLMENU" "SL-钢筋")
(defun sl:Toolbar (mgroup tbname / loc)
(if (setq loc (sl:Toolbar-Exists-p mgroup tbname))
    (vla-item (sl:Toolbars mgroup) loc)
    nil
)
)
;;显示指定工具条----(一级------
;;(sl:Toolbar-Show "SLMENU" "SL-钢筋") 将显示SL-钢筋工具条
(defun sl:Toolbar-Show (mgroup tbname / tb)
(if (and (setq tb (sl:Toolbar mgroup tbname)) (= (vla-get-visible tb) :vlax-false))
    (progn
      (vla-put-visible tb :vlax-true)
      (vlax-release-object tb)
      T
    )
    nil
)
)
;;隐藏指定工具条---(一级)-----
;;(sl:Toolbar-Hide "SLMENU" "SL-钢筋") 将显示SL-钢筋工具条
(defun sl:Toolbar-Hide (mgroup tbname / tb)
(if (and (setq tb (sl:Toolbar mgroup tbname)) (= (vla-get-visible tb) :vlax-true))
    (progn
      (vla-put-visible tb :vlax-false)
      (vlax-release-object tb)
      T
    )
    nil
)
)
;;删除菜单----(一级)------
(defun delmenu ()
(sl:del-fil (strcat sl-path0 "\\" "SLMENU.cuix"))
(sl:del-fil (strcat sl-path0 "\\" "SLMENU.bak.cuix"))
(sl:del-fil (strcat sl-path0 "\\" "SLMENU.mns"))
(sl:del-fil (strcat sl-path0 "\\" "SLMENU.mnr"))
(sl:del-fil (strcat sl-path0 "\\" "SLMENU_light.mnr"))
)
;;菜单显示程序----(一级)------
(defun slmenuk (/ i menuk k1 k2 k3 k4 k5 k6 k7 k8 k9 k10 k11 s1)
(setq
    k1 (slmsg "下拉MENU" "┰MENU" "downMENU")
    k2 (slmsg "图标菜单" "瓜夹垫虫" "IconMenu")
    k3 (slmsg "展开" "甶秨" "open")
    k4 (slmsg "开" "秨" "open")
    k5 (slmsg "关" "闽" "close")
    k6 (slmsg "SL-绘制" "SL-酶籹" "SL-draw")
    k7 (slmsg "SL-钢筋" "SL-葵惮" "SL-steelbar")
    k8 (slmsg "SL-查询-缩放" "SL-琩高-罽" "SL-query-zoom")
    k9 (slmsg "SL-编辑" "SL-絪胯" "SL-edit")
    k10 (slmsg "SL-常用" "SL-盽ノ" "SL-Common")
    k11 (slmsg "SL-文件" "SL-ゅン" "SL-file")
)
(setq menuk (readkey (strcat sl-path0 "\\" "main.ini") k2))
(sl:Toolbar-Show "SLMENU" k11)
(if (or (= menuk nil) (= menuk k4))
    (progn
      (rwritekey (strcat sl-path0 "\\" "main.ini") k2 k4)
      (sl:Toolbar-Show "SLMENU" k6)
      (sl:Toolbar-Show "SLMENU" k7)
      (sl:Toolbar-Show "SLMENU" k8)
      (sl:Toolbar-Show "SLMENU" k9)
      (sl:Toolbar-Show "SLMENU" k10)
    )
    (progn
      (rwritekey (strcat sl-path0 "\\" "main.ini") k2 k5)
      (sl:Toolbar-Hide "SLMENU" k6)
      (sl:Toolbar-Hide "SLMENU" k7)
      (sl:Toolbar-Hide "SLMENU" k8)
      (sl:Toolbar-Hide "SLMENU" k9)
      (sl:Toolbar-Hide "SLMENU" k10)
    )
)
(setq s1 (readkey (strcat sl-path0 "\\" "main.ini") k1))
(if (or (= s1 nil) (= s1 k3))
    (progn
      (setq s1 k3)
      (rwritekey (strcat sl-path0 "\\" "main.ini") k1 k3)
    )
)
(if (>= (setq i (vla-get-count (vla-get-menubar *Acad*))) 16) (setq i 16))
(if (= s1 k3) ;展开
    (progn
      (menucmd (strcat "p" (itoa (1+ i)) "=+SLMENU.POP1"))
      (menucmd (strcat "p" (itoa (+ i 2)) "=+SLMENU.POP2"))
      (menucmd (strcat "p" (itoa (+ i 3)) "=+SLMENU.POP3"))
      (menucmd (strcat "p" (itoa (+ i 4)) "=+SLMENU.POP4"))
      (menucmd (strcat "p" (itoa (+ i 5)) "=+SLMENU.POP5"))
      (menucmd (strcat "p" (itoa (+ i 6)) "=+SLMENU.POP6"))
      (menucmd (strcat "p" (itoa (+ i 7)) "=+SLMENU.POP7"))
      (menucmd (strcat "p" (itoa (+ i 8)) "=+SLMENU.POP8"))
    )
    (menucmd (strcat "p" (itoa (1+ i)) "=+SLMENU.POP1"))
)
)
;;下拉菜单开关--k: t 展开 nil 合并----(一级)----
(defun showxlmenu (k / k1 k2 k3)
(setq
    k1 (slmsg "下拉MENU" "┰MENU" "downMENU")
    k2 (slmsg "展开" "甶秨" "open")
    k3 (slmsg "合并" "" "close")
)
(if (= k t)
    (rwritekey (strcat sl-path0 "\\" "main.ini") k1 k2)
    (rwritekey (strcat sl-path0 "\\" "main.ini") k1 k3)
)
(delmenu)
(menu00)
)
;;图标菜单开关-----(一级)------
;;kt 开 nil 关
(defun opmenu (k / k1 k2 k3)
(setq
    k1 (slmsg "图标菜单" "瓜夹垫虫" "IconMenu")
    k2 (slmsg "开" "秨" "open")
    k3 (slmsg "关" "闽" "close")
)
(if (= k t)
    (rwritekey (strcat sl-path0 "\\" "main.ini") k1 k2)
    (rwritekey (strcat sl-path0 "\\" "main.ini") k1 k3)
)
(delmenu)
(menu00)
)
;;专业设置--k: t 建筑 nil 机械----(一级)----
(defun showzymenu (k / k1 k2 k3)
(setq
    k1 (slmsg "专业" "盡穨" "major")
    k2 (slmsg "建筑" "縱" "Architecture")
    k3 (slmsg "机械" "诀瘪" "Mechanical")
)
(if (= k t)
    (rwritekey (strcat sl-path0 "\\" "main.ini") k1 k2)
    (rwritekey (strcat sl-path0 "\\" "main.ini") k1 k3)
)
(delmenu)
(menu00)
)
;;加载菜单------
(defun menu00 (/ s s1 k k1 k2 k3)
(if (not (menugroup "SLMENU"))
    (progn
      (setq
      k1 (slmsg "下拉MENU" "┰MENU" "downMENU")
      k2 (slmsg "专业" "盡穨" "major")
      k3 (slmsg "图标菜单" "瓜夹垫虫" "IconMenu")
      )
      (if (= (readkey (strcat sl-path0 "\\" "main.ini") k1) nil)
      (rwritekey (strcat sl-path0 "\\" "main.ini") k1 (slmsg "展开" "甶秨" "open"))
      )
      (if (= (readkey (strcat sl-path0 "\\" "main.ini") k2) nil)
      (rwritekey (strcat sl-path0 "\\" "main.ini") k2 (slmsg "建筑" "縱" "Architecture"))
      )
      (if (= (readkey (strcat sl-path0 "\\" "main.ini") k3) nil)
      (rwritekey (strcat sl-path0 "\\" "main.ini") k3 (slmsg "开" "秨" "open"))
      )
      (setq k (slmsg "版本" "セ" "version"))
      (cond
      ((getcname "tpscale")
          (setq s (slmsg "天正" "ぱタ" "TianzhengDesign"))
      )
      ((getcname "sascl")
          (setq s (slmsg "浩辰" "疎ò" "TaochenDesign"))
      )
      ((= $Lgver 1) ;简体
          (setq s "简体中文")
      )
      ((= $Lgver 2) ;繁体版
          (setq s "羉砰いゅ")
      )
      ((= $Lgver 3) ;英文
          (setq s "Englishversion")
      )
      )
      (setq s1 (readkey (strcat sl-path0 "\\" "main.ini") k))
      (if (or (/= s1 s) (= nil s1))
      (rwritekey (strcat sl-path0 "\\" "main.ini") k s)
      )
      (delmenu) ;需要删除
      (cond
      ((= $Lgver 1); (/= (getcname "sascl") nil)) ;;CAD是简体中文版包括浩辰中望
          (load (strcat sl-path0 "\\" "Support" "\\" "slmenu-bz.VLX"))
      )
      ((= $Lgver 2) ;繁体版
          (load (strcat sl-path0 "\\" "Support" "\\" "slmenu-ft.VLX"))
      )
      ((= $Lgver 3) ;英文版
          (load (strcat sl-path0 "\\" "Support" "\\" "slmenu-en.VLX"))
      )
      )
      (Menu-load (strcat sl-path0 "\\" "SLMENU.mns"))
      (slmenuk) ;菜单显示, 此处确保显示正确
      ;(command "MENULOAD" (strcat sl-path0 "\\" "SLMENU.mns"))
    )
    (progn (Menu-Unload "SLMENU") (menu00))
)
);(setq sl-path0 "d:\\三领设计")
(setq date1 (getvar "MILLISECS"))
(menu00)
(prompt (strcat (slmsg "耗时" "" "Time consuming") (rtos (/ (- (getvar "MILLISECS") date1) 1000.000) 2 3) (slmsg "秒" "" "seconds")))


zhangkui9070 发表于 2024-3-10 15:20:27

感谢分享,受益颇多

gble119 发表于 2024-7-16 22:45:05

多谢教程 试下如何

gzcsun 发表于 2024-7-17 10:03:05

快0.1秒的,只怕是COMMAND方式写法没有优化。{:1_1:}
页: [1]
查看完整版本: 菜单系统的加载速度问题