本帖最后由 kucha007 于 2022-12-4 14:00 编辑
改了一下,支持多选或者先选(但得先勾选“先选择后执行”)
PS:代码有误,还在想如何合并选择集= =
- (setvar "PICKFIRST" 1);勾选先选择后执行
- (defun c:TT (/ Old_Cmd Doc ss Cols co Dxf Lst sss)
- (vl-load-com)
- (if (not (setq ss (ssget "i")))
- (setq ss (ssget))
- )
- (setq Old_Cmd (getvar "cmdecho"))
- (setq Doc (vla-get-ActiveDocument (vlax-get-acad-object)))
- (vla-startundomark Doc) ;记录编组
- (setvar "cmdecho" 0)
- (if ss
- (progn
- (repeat (setq i (sslength ss))
- (setq e (ssname ss (setq i (1- i))))
- (setq Cols (cons
- (cond
- ((cdr (assoc 62 (entget e))))
- ((abs (cdr (assoc 62 (tblsearch "LAYER" (cdr (assoc 8 (entget e))))))))
- )
- Cols
- )
- )
- )
- (foreach co Cols
- (while (setq Dxf (tblnext "LAYER" (null Dxf)))
- (if (= co (abs (cdr (assoc 62 Dxf))))
- (setq Lst (cons "," (cons (cdr (assoc 2 Dxf)) Lst)))
- )
- );获取颜色的图层
- (setq sss
- (ssget "_X"
- (if Lst
- (list
- (cons -4 "<OR")
- (cons -4 "<AND")
- (cons 62 co)
- (if (= 1 (getvar 'cvport))
- (cons 410 (getvar 'ctab)) '(410 . "Model")
- )
- (cons -4 "AND>")
- (cons -4 "<AND")
- (cons 62 256)
- (cons 8 (apply 'strcat (cdr Lst)))
- (if (= 1 (getvar 'cvport))
- (cons 410 (getvar 'ctab)) '(410 . "Model")
- )
- (cons -4 "AND>")
- (cons -4 "OR>")
- )
- (list (cons 62 co))
- )
- )
- )
- (if (> (sslength sss) 0)(sssetfirst nil sss))
- )
- )
- )
- (setvar "cmdecho" Old_Cmd)
- (vla-endundomark Doc) ;结束编组
- (princ)
- )
|