本帖最后由 菜卷鱼 于 2023-5-17 14:38 编辑
没有做测试,但是写了注释,假如程序有问题你自己学着改
- (defun c:tt ()
- (setq lst '(("jmd,dldw" "居民地及设施")
- ("DGX,GCD,DMTZ" "地貌")
- ("DLSS" "交通")
- ("GXYZ" "管线")
- ("KZD" "测量控制点")
- ("SXSS" "水系及附属设施")
- ("TK" "图廓整饰")
- ("ZBTZ" "植被与土质")
- ("ZJ" "注记")
- )
- )
- (foreach a lst
- (if (setq ss (ssget "x" (list (cons 8 (car a)))))
- (progn
- (command "change" ss "" "p" "la" (cadr a) "c" "bylayer" "")
- (setq ns (ssget "p" '((0 . "insert")))) ;;;从上一次选择的选择集里选出块
- (setq i -1)
- (repeat (sslength ns) ;;;每个块处理一遍
- (setq blk (ssname ns (setq i (1+ i))))
- (setq lst2 (blklst blk)) ;;;;块转成列表
- (foreach obj lst2 ;;;;每个块内的成员处理一遍
- (setq info (entget obj))
- (setq newlayer (cons 67 (cadr a))) ;;;新的图层
- (setq newcolor (cons 62 0)) ;;;;新的颜色
- (entmod (subst newlayer (assoc 67 info) info)) ;;;新图层替换旧图层
- ;;(entmod (subst newcolor (assoc 62 info) info)) ;;;Bylayer颜色的时候 62索引项是没有的,假如要换别的颜色就用得上
- (entmod (vl-remove (assoc 62 info) info)) ;;;颜色改成bylayer
- )
- )
- )
- )
- (princ)
- )
|