找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 614|回复: 0

[每日一码] 图层孤立(Layer Isolate)

[复制链接]

已领礼包: 19个

财富等级: 恭喜发财

发表于 2021-1-19 09:24:51 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×

  1. ;; Layer (un)ISOLATE
  2. ;;
  3. ;; File: laiso.lsp
  4. ;;
  5. ;;  Pseudo Code:
  6. ;;
  7. ;;  ISOLATE TOOL
  8. ;;  ------------
  9. ;;  o Select an ent(s) to isolate (leave on)
  10. ;;  o Get layers from those ents
  11. ;;  ~ Clean up list of layers by removing dups
  12. ;;  o Get layers of dwg currently on
  13. ;;  o remove list of layers to be left on
  14. ;;  o set a global variable with layer list to be turned off
  15. ;;  o if current layer is to be turned off...
  16. ;;      o switch clayer to one of those in the isolate list
  17. ;;  o itterate thru the list and turn each one off
  18. ;;

  19. (defun Select-Ent-lst ( )
  20.   (
  21.    ;; Itterate thru a Selection Set and return a list of items
  22.    ;; used to allow end user to select some items they wish to keep
  23.    (lambda (ss / lst cntr)
  24.      (if (null cntr)
  25.        (setq cntr 0) )
  26.      (if (null lst)
  27.        (setq lst '()) )
  28.       (if (eq (type ss) 'PICKSET)
  29.         (repeat (sslength ss)
  30.            (setq lst (append lst (list (entget (ssname ss cntr)))))
  31.            (setq cntr (1+ cntr)))
  32.         '*ERROR* )
  33.      lst
  34.      )
  35.     (ssget)) )

  36. (defun Build-Layer-lst ( ent-lst )
  37.   (mapcar
  38.    ;; Build a list of layers to leave on
  39.    '(lambda (x) (cdr (assoc 8 x))) ent-lst) )

  40. (defun clean-lst ( my-lst / lst )
  41. ;; Clean up a list of items; remove duplicates
  42.      (foreach x my-lst
  43.        (if (not (member x lst))
  44.          (setq lst (cons x lst))))
  45.      (reverse lst)
  46. )

  47. (defun Drawing-Layers-lst ( / )
  48.   ;; create a list of layers in the drawing.
  49.   ;; minus the ones turned off or frozen.
  50.   (while (setq x (tblnext "LAYER" (not x)))
  51.          (if (not (or (= (cdr (assoc 70 x)) 1) (< (cdr (assoc 62 x)) 0)))
  52.            (setq mlst (append mlst (list (cdr (cadr x)))))
  53.            )
  54.          )
  55.   mlst
  56.   )

  57. (defun rip-n-flip (lm lc / l-m cntr)
  58.   (setq cntr (length lc) l-m (mapcar 'list lm))
  59.   (while (> cntr -1)
  60.     (setq l-m (subst nil (list (nth cntr lc)) l-m))
  61.     (setq cntr (1- cntr))
  62.     (apply 'append l-m)) )

  63. (defun Lay (mode lst / layer)
  64.   (foreach x lst
  65.            (setq layer (entget (tblobjname "LAYER" x)))
  66.            (cond
  67.                ((and (null mode) (not (minusp (cdr (assoc 62 layer)))))
  68.                   (setq layer (subst (cons 62 (1+ (~ (cdr (assoc 62 layer))))) (assoc 62 layer) layer)))
  69.               ((and mode  (minusp (cdr (assoc 62 layer))))
  70.                  (setq layer (subst (cons 62 (abs (cdr (assoc 62 layer)))) (assoc 62 layer) layer)))
  71.               )
  72.            (entmod layer)
  73.            )
  74.   (princ) )

  75. ;;;===================================================================;
  76. ;;; main procedures section                                           ;
  77. ;;;===================================================================;
  78. (defun c:laiso ( / ToIsolate-Layer-List)
  79.   ;; (c:laiso)
  80.   (setq ToIsolate-Layer-List
  81.         (clean-lst
  82.           (Build-Layer-lst
  83.             (Select-Ent-lst))) )
  84.   (setq
  85.     *Layoff-layer-list*
  86.     (rip-n-flip
  87.       (Drawing-Layers-lst)
  88.       ToIsolate-Layer-List))

  89.   (if (member (getvar 'CLAYER) *Layoff-layer-list*)
  90.     (progn
  91.       (princ "\nCurrent layer scheduled to be turned off, switching layer...")
  92.       (setvar 'clayer (car ToIsolate-Layer-List))) )
  93.   (lay nil *Layoff-layer-list*) )

  94. (defun c:laon ( )
  95.   ;; (c:laon)
  96.   (if *Layoff-layer-list*
  97.     (progn
  98.       (lay "on" *Layoff-layer-list*)
  99.       (setq *Layoff-layer-list* nil))
  100.     '*ERROR*:NoList)
  101.   (princ) )
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-15 08:29 , Processed in 0.328283 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表