【超级显示/隐藏工】多年前的好贴,别再错过了
原贴网址http://bbs.mjtd.com/thread-24923-5-1.html;;优化交互界面,by1028695446--2019.4.9
;;By LUCAS(龙龙仔)(原著)
;;这是无痕的思路(不会用就找他)
;;超级隐藏/显示工具
(prompt "\n超级隐藏/显示工具-------------龙龙仔.2004.1")
(alert
(strcat
"\n\n-----------超级隐藏/显示工具(测试版V0)-龙龙仔.2004.1----------"
"\n\n-----------------交互界面优化-102869554-----------------------"
"\n\n显示所有(E) 隐藏所有(D)"
"\n\n显示已标记组(V) 隐藏已标记组(C)/"
"\n\n显示上个标记组(S)显示下个标记组(F)/"
"\n\n锁定显示(空格)===显示上一个/下一个的时候不会被隐藏"
"\n\n显示解锁(R)=====显示上一个/下一个的时候会被隐藏"
"\n\n显示记录列表(B) 退出(X)/"
"\n\n增加隐藏标记组(A)删除隐藏标记组(Q)/"
"\n\n清空记录(Z):"
"\n\n主程序(XSHOW_LAI <词典名称>)---------------------------------"
"\n\n这样用户可以自定义快捷键,并创建多个词典,用于存储标记组-------"
"\n\n如:(defun C:xy( )(XSHOW_LAI " "\"LUNG\""")),本程序默认设置---"
"\n\n超级命令,对所有词典管用-----C:XSHOWALL-----------------------"
"\n\n超级命令,对所有词典管用-----C:XHIDEALL-----------------------"
)
)
;;超级隐藏/显示工具
;;By LUCAS(龙龙仔)
;;写好就没有用过.......
(defun C:xy()(XSHOW_LAI "LUNG"))
(defun C:xsa()(C:XSHOWALL));;显示全部
(defun C:yca()(C:XHIDEALL));;隐藏全部
(vl-load-com)
(defun C:XSHOWALL (/ SSOBJ ENT)
(if
(and
(ssget "X" (list (cons 60 1) (cons 410 (getvar "CTAB"))))
(setq SSOBJ (ssget "X" (list (cons 410 (getvar "CTAB")))))
)
(progn
(setq SSOBJ (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
(vlax-for ENT SSOBJ
(vla-put-visible ENT :vlax-true)
)
(prompt "\n显示所有物件!")
)
(prompt "\n无隐藏物件!")
)
(princ)
)
(defun C:XHIDEALL (/ SSOBJ ENT)
(if (setq SSOBJ (ssget "X" (list (cons 410 (getvar "CTAB")))))
(progn
(setq SSOBJ (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
(vlax-for ENT SSOBJ (vla-put-visible ENT :vlax-false))
(prompt "\n隐藏所有物件!")
)
)
(princ)
) ;;(CHECK "LUNG");;获取词典列表索引
(defun CHECK (DICT / DICT_KEY ENT LL N)
(setq DICT_KEY (vlax-ldata-list DICT) N 0)
(repeat (length DICT_KEY)
(setq LL (cons (car (nth N DICT_KEY)) LL))
(setq N (1+ N))
)
LL
) ;;(DICT_OFF "LUNG" "1");;隐藏
(defun DICT_OFF (DICT KEY / SS ENT)
(setq SS (cdr (assoc KEY (vlax-ldata-list DICT))))
(foreach ENT SS
(if (and (setq ENT (handent ENT)) (entget ENT))
(vla-put-visible (vlax-ename->vla-object ENT) :vlax-false)
)
)
(princ)
) ;;(DICT_ON "LUNG" "1");;显示
(defun DICT_ON (DICT KEY / SS ENT)
(setq SS (cdr (assoc KEY (vlax-ldata-list DICT))))
(foreach ENT SS
(if (and (setq ENT (handent ENT)) (entget ENT))
(vla-put-visible (vlax-ename->vla-object ENT) :vlax-true)
)
)
(princ)
) ;;(MAKE_DICT "LUNG" "1" (SSGET));;存储图元句柄(5 . *)
(defun MAKE_DICT (DICT KEY SS / ENAME_LIST N)
(setq N 0)
(repeat (sslength SS)
(setq ENAME_LIST
(cons (cdr (assoc 5 (entget (ssname SS N))))
ENAME_LIST
)
)
(setq N (1+ N))
)
(vlax-ldata-put DICT KEY ENAME_LIST)
) ;;主程序
;;(XSHOW_LAI "LUNG")
(defun XSHOW_LAI (DICT / KEY N LEN LIS LIS1 LOOP MSG MODE S1 TMPKEY)
(if (not (setq N (vlax-ldata-get (strcat DICT "_N") "N")));;如有N没有被存储...N为当前记录索引值
(progn
(setq N 0);;设定默认值,,暂时设定为0,原先为1
(vlax-ldata-put (strcat DICT "_N") "N" 1);;给n创建词典,用于记录
)
)
(if (not (setq LIS (vlax-ldata-get (strcat DICT "_LIS") "LIS")));;如有LIS没有被存储...用于锁定标记
(progn
(setq LIS '());;设定默认值
(vlax-ldata-put (strcat DICT "_LIS") "LIS" LIS)
)
)
(setq MSG
"\n[显示所有(E)/隐藏所有(D)/显示记录(V)/隐藏记录(C)/显示上个(S)/显示下个(F)/显示锁定(空格)/显示解锁(R)/记录列表(B)/退出(X)/增加隐藏(A)/删除标记(Q)/清空记录(Z)]:"
)
(prompt MSG)
(setq LOOP t)
(while LOOP
(setq MODE (grread t 4 0));(grread t 4 2)
(cond
((or
(member MODE '((2 13) (2 88) (2 120) ));;; CTRL-M或回车;;; X键;;; x键;;; 鼠标右键,右键设置为回车时
(= (car MODE) 11);;; 鼠标右键,右键设置为回车时
(= (car MODE) 25);;; 鼠标右键,右键设置为屏幕菜单时
)
(setq LOOP NIL)
)
((member MODE '((2 65) (2 97))) ;A
(if (CHECK DICT);;如果已经有记录索引
(setq KEY (rtos (1+ (last (setq KEY_LIST
(vl-sort (mapcar 'atof (CHECK DICT)) '<);;列表从小到大排列
)
)
)
)
);指定最新的标记索引
(setq KEY "1")
)
(setq LEN (length (vlax-ldata-list DICT)))
;;(vlax-ldata-put "LUNG" "KEY_LIST" KEY_LIST)
;;(setq KEY (rtos (1+ (apply 'max (mapcar 'atof (CHECK "LUNG"))))))
(prompt (strcat "\n" DICT "增选隐藏物件:"))
(if (setq S1 (ssget))
(MAKE_DICT DICT KEY S1);;添加标记内容
)
(prompt MSG)
)
((member MODE '((2 69) (2 101))) ;E;;;;这个正确*********************************************
(C:XSHOWALL)
(prompt MSG)
)
((member MODE '((2 100) (2 68))) ;D;;;;这个正确*********************************************
(C:XHIDEALL)
(prompt MSG)
)
((member MODE '((2 67) (2 99))) ;C;;隐藏被记录图元
(setq CHECK_LIST (CHECK DICT))
(mapcar '(lambda (X)
(DICT_OFF DICT X);;关闭被记录的图元
)
CHECK_LIST
)
(prompt (strcat"\n" DICT "中标记物件已被--全部隐藏!"))
(prompt MSG)
)
((member MODE '((2 86) (2 118))) ;V
(setq CHECK_LIST (CHECK DICT))
(mapcar '(lambda (X)
(DICT_ON DICT X)
)
CHECK_LIST
)
(prompt (strcat"\n" DICT "中标记物件已被--全部显示!"))
(prompt MSG)
)
((member MODE '((2 83) (2 115))) ;S
(if (not (setq N (vlax-ldata-get (strcat DICT "_N") "N")));;取出N值
(progn
(setq N 1);;设定默认值,,暂时设定为0,原先为1************************************
(vlax-ldata-put (strcat DICT "_N") "N" 1);;存储N
)
)
(if (setq LIS1 (CHECK DICT))
(progn
(setq LEN (length LIS1))
(if (= N (1- LEN));;N为最后一值(最大值),那就重0开始,循环往复
(setq N 0);;;为什么要设为0,默认值1干嘛用的***********************************
(setq N (1+ N))
)
(DICT_ON DICT (nth N LIS1));;显示下一个
(if (= N 0)
(setq TMPKEY (nth (1- LEN) LIS1));;设置索引最大值
(setq TMPKEY (nth (1- N) LIS1))
);;记录之前所在位置
(if (not (member TMPKEY LIS))
(DICT_OFF DICT TMPKEY)
)
(vlax-ldata-put (strcat DICT "_N") "N" N);;存储当前索引值
(prompt (strcat "\n" DICT "显示第"
(vl-prin1-to-string(nth N LIS1))
"笔物件,锁定串列="
(vl-prin1-to-string LIS)
)
)
)
)
(prompt MSG)
)
((member MODE '((2 102) (2 70))) ;F
(if (not (setq N (vlax-ldata-get (strcat DICT "_N") "N")))
(progn
(setq N 1);;设定默认值,,暂时设定为0,原先为1********************************
(vlax-ldata-put (strcat DICT "_N") "N" N);;;修正了
)
)
(if (setq LIS1 (CHECK DICT))
(progn
(setq LEN (length LIS1))
(if (= N 0)
(setq N (1- LEN))
(setq N (1- N))
)
(DICT_ON DICT (nth N LIS1))
(if (= N (1- LEN))
(setq TMPKEY (nth 0 LIS1))
(setq TMPKEY (nth (1+ N) LIS1))
)
(if (not (member TMPKEY LIS))
(DICT_OFF DICT TMPKEY)
)
(vlax-ldata-put (strcat DICT "_N") "N" N)
(prompt (strcat "\n" DICT "显示第"
(vl-prin1-to-string(nth N LIS1))
"笔物件,锁定串列="
(vl-prin1-to-string LIS)
)
)
)
)
(prompt MSG)
)
((member MODE '((2 32))) ;"";;将当前显示的索引标记,添加的锁定栏
(if (setq LIS1 (CHECK DICT))
(progn
(if
(not (setq LIS (vlax-ldata-get (strcat DICT "_LIS") "LIS")))
(progn
(setq LIS '())
(vlax-ldata-put (strcat DICT "_LIS") "LIS" LIS)
)
)
(if (not (member (nth N LIS1) LIS))
(setq LIS (append LIS (list (nth N LIS1))))
)
(vlax-ldata-put (strcat DICT "_LIS") "LIS" LIS)
(prompt (strcat "\n" DICT "显示锁定串列"
(vl-prin1-to-string LIS)
",目前显示第"
(vl-prin1-to-string(nth N LIS1))
"笔物件"
)
)
)
)
(prompt MSG)
)
((member MODE '((2 114) (2 82))) ;R;;将当前显示的索引标记,从锁定栏解锁
(if (setq LIS1 (CHECK DICT))
(progn
(if
(not (setq LIS (vlax-ldata-get (strcat DICT "_LIS") "LIS"))
)
(progn
(setq LIS '())
(vlax-ldata-put (strcat DICT "_LIS") "LIS" LIS)
)
)
(if (member (nth N LIS1) LIS)
(setq LIS (vl-remove (nth N LIS1) LIS))
)
(vlax-ldata-put (strcat DICT "_LIS") "LIS" LIS)
(prompt (strcat "\n" DICT "显示锁定串列"
(vl-prin1-to-string LIS)
",目前显示第"
(vl-prin1-to-string(nth N LIS1))
"笔物件"
)
)
)
)
(prompt MSG)
)
((member MODE '((2 122) (2 90))) ;Z
;|
(setq
KEY_LIST1 (mapcar 'rtos
(vl-sort (mapcar 'atof (CHECK "LUNG")) '<)
)
)|;
;|
(setq CHECK_LIST (CHECK "LUNG"))
(mapcar '(lambda (X)
(vlax-ldata-delete "LUNG" X)
)
CHECK_LIST
)|;
(initget "Y ")
(if (getkword (strcat"\n" DICT "真的要清除所有标记物件!<N>:"))
(progn
(dictremove (namedobjdict) DICT)
(dictremove (namedobjdict) (strcat DICT "_N"))
(dictremove (namedobjdict) (strcat DICT "_LIS"))
(prompt (strcat"\n" DICT "已清除所有标记物件!"))
)
(prompt (strcat"\n" DICT "标记物件已保留!"))
)
(prompt MSG)
)
((member MODE '((2 113) (2 81))) ;Q
(if (setq LIS1 (CHECK DICT))
(progn
(DICT_ON DICT (nth N LIS1))
(vlax-ldata-delete DICT (nth N LIS1))
(prompt (strcat "\n" DICT "已删除"
(vl-prin1-to-string (nth N LIS1))
"标记,目前标记"
(vl-prin1-to-string (CHECK DICT))
)
)
(setq N 1);;设定默认值,,暂时设定为0,原先为1
)
)
(prompt MSG)
)
((member MODE '((2 66) (2 98))) ;B
(prompt
(strcat "\n" DICT "目前标记" (if DICT (vl-prin1-to-string (CHECK DICT))))
)
(prompt MSG)
)
)
)
(princ)
)
本帖最后由 panliang9 于 2019-4-10 08:14 编辑
原来的好象一直没用起来,现在似乎能行了。仔细研究一下,谢谢楼主!
我以前也发贴讨论过这个问题,http://bbs.mjtd.com/thread-176377-1-1.html
希望得到的结果就是一个下拉的显示状态管理器,可以存很多个这种显示隐藏的状态,可以很方便的调用。
CAD原生的是图层管理器,但很多时候很不方便,要求很严格的分层。
本帖最后由 cyfdean 于 2019-6-18 19:15 编辑
我看到海龙工具箱与源泉工具箱都有这功能,但是我只想要 超级显示/隐藏工具,所以今天找到这里来了。这个就是我想要的原码了:http://bbs.mjtd.com/forum.php?mod=viewthread&tid=113902&extra=&highlight=%D2%FE%B2%D8&page=1
cyfdean 发表于 2019-6-18 17:13
我看到海龙工具箱与源泉工具箱都有这功能,但是我只想要 超级显示/隐藏工具,所以今天找到这里来了。这个就 ...
http://bbs.mjtd.com/thread-179805-1-1.html
这里有很多的选择 感谢无私分享,最喜欢源码了 天正局部隐藏功能??
页:
[1]