CAD_Noob 发表于 2022-7-5 15:42:46

图层名称+图层颜色

又是我。我想知道根据颜色过滤所有对象并将其添加到层名称中有多难。
 
例子:
 
我有3行与XXX具有相同的图层名称,但不在bylayer上。一条是红色,另一条是蓝色,最后是绿色。
 
我希望它变成XXX-红色,XXX-蓝色,XXX-绿色。
 
有可能吗?它能在任何物体上工作吗?直线、圆、块、椭圆、矩形等。。。
 
如果没有手动选择,将非常有用。

Grrr 发表于 2022-7-5 15:47:38

像这样的
 


(defun C:test ( / del ct *error* SS LyrStates i enx col lyr nlyr tmp )
(setq del "_") ; Delimeter
(setq ct
   '(
   (1 . "Red") (2 . "Yellow") (3 . "Green") (4 . "Cyan")
   (5 . "Blue") (6 . "Magenta") (7 . "Whilte")
   )
)

(defun *error* ( m )
   (and ThawUnlockLyrs LyrStates (ThawUnlockLyrs LyrStates))
   (and m (princ m)) (princ)
); defun *error*

(if (setq SS (ssget "X"))
   (progn
   (and ThawUnlockLyrs (setq LyrStates (ThawUnlockLyrs nil)))
   (repeat (setq i (sslength SS))
       (and
         (setq col (assoc 62 (setq enx (entget (ssname SS (setq i (1- i)))))))
         (vl-every '(lambda (x) (not (assoc x enx))) '(420 430))
         (setq lyr (assoc 8 enx))
         (setq nlyr (strcat (cdr lyr) del (cond ( (cdr (assoc (setq tmp (cdr col)) ct)) ) ( (itoa tmp) ) )))
         (progn
         (entmod (subst '(62 . 256) col (subst (cons 8 nlyr) lyr enx)))
         (entmod (append (entget (tblobjname "LAYER" nlyr)) (list col)))
         )
       )
   )
   )
)
(*error* nil) (princ)
)
(vl-load-com) (princ)

; (setq LyrStates (ThawUnlockLyrs nil))
; (and LyrStates (ThawUnlockLyrs LyrStates))
(defun ThawUnlockLyrs ( aL / d L st enx )
(cond
   (aL
   (foreach x aL
       (if (setq enx (entget (tblobjname "LAYER" (car x))))
         (entmod (subst (cons 70 (cadr x)) (assoc 70 enx) enx))
       ); if
   ); foreach
   )
   (T
   (while (setq d (tblnext "LAYER" (not d)))
       (setq L (cons (apply 'append (mapcar '(lambda (x) (if (member (car x) '(2 70)) (list (cdr x)))) d)) L))
       (setq st
         (
         (lambda (x)
         (if (= 1 (logand 1 x)) (setq x (1+ x))) ; Frozen
         (if (= 4 (logand 4 x)) (setq x (+ 4 x))) ; Locked
         x
         )
         (cadar L)
       )
       ); setq st
       (setq enx (entget (tblobjname "LAYER" (caar L))))
       (entmod (subst (cons 70 st) (assoc 70 enx) enx))
   ); while
   L
   ); T
); cond
); defun ThawUnlockLyrs

halam 发表于 2022-7-5 15:53:27

你好Noob先生
 
 
这个过滤工具将花费你5美元(没有****!)但这绝对值得投资!
在Autodesk AutoCAD app store中搜索表单SelectSame。

CAD_Noob 发表于 2022-7-5 15:58:26

 
谢谢你。。工作完美。
是否可以对其进行一些修改,以在运行代码之前解锁层,并在一次时再次锁定?

CAD_Noob 发表于 2022-7-5 16:00:59

 
你的插件看起来很有前途,但目前恐怕不适合我的需要。

Grrr 发表于 2022-7-5 16:04:57

 
我修改了代码作为回复#2。
 
问题:
 
然而,使用普通路径,我组装的子功能(ThawUnlockLyrs)有点问题——不知道为什么。
例如,最初存储旧状态和解冻+解锁所有层效果良好:
(setq LyrStates (ThawUnlockLyrs nil))
 
但当我尝试使用输出列表恢复状态时:
(and LyrStates (ThawUnlockLyrs LyrStates))
在“Layers properties manager”中,一切看起来都很好,但是我之前冻结的图层上的图形对象消失了,就像它们的图层仍然冻结或关闭一样。
但是,在“图层属性管理器”中,一切似乎都很好。
在未保存的dwg上测试了这一点,然后我决定保存并重新打开它-所有对象都正常,现在可以看到了。
 
这就是为什么我保留了一个类似这样的替代VLA子功能,它工作得很好。

CAD_Noob 发表于 2022-7-5 16:07:31

非常感谢。明天可以吗?因为我现在家里没有autocad。
我非常感谢你的努力!

Roy_043 发表于 2022-7-5 16:14:27

@Grrr:你试过重新生成dwg吗?

rlx 发表于 2022-7-5 16:17:44

 
 
有时会出现类似的问题,在自动替换标题栏后,我尝试手动修改的每个属性都会不可见,只有重新打开图形才有帮助。这并不是一直都在发生,所以优先级很低。

Grrr 发表于 2022-7-5 16:19:50

 
是的,罗伊,我做了-也许这是AutoCAD中的一个错误。
页: [1] 2
查看完整版本: 图层名称+图层颜色