鬼魔 发表于 2007-5-16 21:34:00

[求助]快速改图层

本帖最后由 作者 于 2007-5-16 21:41:37 编辑 <br /><br /> <p>哪位朋友抽空帮忙编下,以前用过类似的,现在找不着</p><p>必须先选择物体,按主键盘上数字1-0,就把物体归入对应图层里,归入时,颜色随层,其他不变</p><p>数字1-0分别定义10个图层名字,例如,1 图层名字为 外线 2图层名字为 中线 等等,</p><p>如无图层,则建立图层再归入,颜色默认为白,其他随层</p>

sailorcwx 发表于 2007-5-17 17:25:00

本帖最后由 作者 于 2007-5-17 17:26:45 编辑

(defun C:CL(/ YH_LAYER YH_LAYERLIST YH_LAYERN YH_S)
(setq YH_layerlist (list "layer0" "layer1" "layer2" "layer3" "layer4" "layer5" "layer6" "layer7" "layer8" "layer9")) ;图层列表
(setq YH_S (ssget))
(if YH_S
    (progn
    (princ (strcat "0-" (nth 0 YH_layerlist) " 1-" (nth 1 YH_layerlist) " 2-" (nth 2 YH_layerlist) " 3-" (nth 3 YH_layerlist) " 4-" (nth 4 YH_layerlist) "\n" " 5-" (nth 5 YH_layerlist) " 6-" (nth 6 YH_layerlist) " 7-" (nth 7 YH_layerlist) " 8-" (nth 8 YH_layerlist) " 9-" (nth 9 YH_layerlist)))
    (initget "0 1 2 3 4 5 6 7 8 9")
    (setq YH_layern (getkword "\n输入图层序号:"))
    (if YH_layern
      (progn
(setq YH_layer (nth (atoi YH_layern) YH_layerlist))
(if (null (tblsearch "LAYER" YH_layer))
   (entmake (list
       '(0 . "LAYER")
       '(100 . "AcDbSymbolTableRecord")
       '(100 . "AcDbLayerTableRecord")
       (cons 2 YH_layer)          ;图层名称
       '(70 . 0)         ;图层状态
       (cons 62 7)               ;图层颜色
       (cons 6 "bylayer")          ;图层线型
       )
   )
   )
(command "CHPROP" YH_S "" "la" YH_layer "c" "bylayer" "")
)
      )
    )
    )
(princ)
)

鬼魔 发表于 2007-5-17 21:00:00

<p>QQQ for <font color="#000000"><strong>sailorcwx </strong>,</font>程序做的不错</p><p>是否能做到不用输命令,先选择而后改</p>

sailorcwx 发表于 2007-5-18 14:31:00

<p>这样子怎么样</p><p>(defun c:1 (/ YH_S)<br/>&nbsp; (if (null (tblsearch "LAYER" "layer1"))<br/>&nbsp;&nbsp;&nbsp; (entmake (list<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '(0 . "LAYER")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '(100 . "AcDbSymbolTableRecord")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '(100 . "AcDbLayerTableRecord")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '( 2 . "layer1")&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;图层名称<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '(70 . 0)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;图层状态<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '(62 . 7)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;图层颜色<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '(6 . "bylayer")&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;图层线型<br/>&nbsp;)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp; )<br/>&nbsp; (setq YH_S (cadr (ssgetfirst)))<br/>&nbsp; (if YH_S<br/>&nbsp;&nbsp;&nbsp; (command "CHPROP" YH_S "" "la" "layer1" "c" "bylayer" "")<br/>&nbsp;&nbsp;&nbsp; )<br/>&nbsp; )</p>

sailorcwx 发表于 2007-5-18 14:36:00

<p>批量生产</p><p>(defun YH_chlayer (YH_layer / YH_S)<br/>&nbsp; (if (null (tblsearch "LAYER" YH_layer))<br/>&nbsp;&nbsp;&nbsp; (entmake (list<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '(0 . "LAYER")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '(100 . "AcDbSymbolTableRecord")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '(100 . "AcDbLayerTableRecord")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (cons 2 YH_layer)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;图层名称<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '(70 . 0)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;图层状态<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '(62 . 7)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;图层颜色<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '(6 . "bylayer")&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;图层线型<br/>&nbsp;)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp; )<br/>&nbsp; (setq YH_S (cadr (ssgetfirst)))<br/>&nbsp; (if YH_S<br/>&nbsp;&nbsp;&nbsp; (command "CHPROP" YH_S "" "la" YH_layer "c" "bylayer" "")<br/>&nbsp;&nbsp;&nbsp; )<br/>&nbsp; (princ)<br/>&nbsp; )</p><p>(defun c:0 ()<br/>&nbsp; (YH_chlayer "layer0")<br/>&nbsp; )<br/>(defun c:1 ()<br/>&nbsp; (YH_chlayer "layer1")<br/>&nbsp; )<br/>(defun c:2 ()<br/>&nbsp; (YH_chlayer "layer2")<br/>&nbsp; )<br/>(defun c:3 ()<br/>&nbsp; (YH_chlayer "layer3")<br/>&nbsp; )<br/>(defun c:4 ()<br/>&nbsp; (YH_chlayer "layer4")<br/>&nbsp; )<br/>(defun c:5 ()<br/>&nbsp; (YH_chlayer "layer5")<br/>&nbsp; )<br/>(defun c:6 ()<br/>&nbsp; (YH_chlayer "layer6")<br/>&nbsp; )<br/>(defun c:7 ()<br/>&nbsp; (YH_chlayer "layer7")<br/>&nbsp; )<br/>(defun c:8 ()<br/>&nbsp; (YH_chlayer "layer8")<br/>&nbsp; )<br/>(defun c:9 ()<br/>&nbsp; (YH_chlayer "layer9")<br/>&nbsp; )</p>

鬼魔 发表于 2007-5-18 20:26:00

测试了下,非常完美,再次感谢<strong>sailorcwx</strong>帮忙

鬼魔 发表于 2007-6-3 13:54:00

本帖最后由 作者 于 2007-6-3 13:57:14 编辑 <br /><br /> <p>能否在帮我改下</p><p>原本程序是如有先选择对象时,把对象归如指定层,如没就建立图层再归入;能否改下如果没先选择对象时,则新建图层并至为当前层(第2种情况是有了图层,也能满足至为当前层)。如果是有先选择对象时,就归入指定层,而不必将指定层至为当前层,颜色随层,其他按原来的</p>

sailorcwx 发表于 2007-6-3 14:13:00

<p>(defun YH_chlayer (YH_layer / YH_S)<br/>&nbsp; (if (null (tblsearch "LAYER" YH_layer))<br/>&nbsp;&nbsp;&nbsp; (entmake (list<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '(0 . "LAYER")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '(100 . "AcDbSymbolTableRecord")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '(100 . "AcDbLayerTableRecord")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (cons 2 YH_layer)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;图层名称<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '(70 . 0)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;图层状态<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '(62 . 7)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;图层颜色<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '(6 . "bylayer")&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;图层线型<br/>&nbsp;)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>&nbsp;&nbsp;&nbsp; )<br/>&nbsp; (setq YH_S (cadr (ssgetfirst)))<br/>&nbsp; (if YH_S<br/>&nbsp;&nbsp;&nbsp; (command "CHPROP" YH_S "" "la" YH_layer "c" "bylayer" "")<br/>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#dd0000">(setvar "clayer" YH_layer)</font><br/>&nbsp;&nbsp;&nbsp; )<br/>&nbsp; (princ)<br/>&nbsp; )</p><p>(defun c:0 ()<br/>&nbsp; (YH_chlayer "layer0")<br/>&nbsp; )<br/>(defun c:1 ()<br/>&nbsp; (YH_chlayer "layer1")<br/>&nbsp; )<br/>(defun c:2 ()<br/>&nbsp; (YH_chlayer "layer2")<br/>&nbsp; )<br/>(defun c:3 ()<br/>&nbsp; (YH_chlayer "layer3")<br/>&nbsp; )<br/>(defun c:4 ()<br/>&nbsp; (YH_chlayer "layer4")<br/>&nbsp; )<br/>(defun c:5 ()<br/>&nbsp; (YH_chlayer "layer5")<br/>&nbsp; )<br/>(defun c:6 ()<br/>&nbsp; (YH_chlayer "layer6")<br/>&nbsp; )<br/>(defun c:7 ()<br/>&nbsp; (YH_chlayer "layer7")<br/>&nbsp; )<br/>(defun c:8 ()<br/>&nbsp; (YH_chlayer "layer8")<br/>&nbsp; )<br/>(defun c:9 ()<br/>&nbsp; (YH_chlayer "layer9")<br/>&nbsp; )</p>

Eric991 发表于 2008-8-13 15:17:00

<p>感谢<strong><font face="Verdana" color="#61b713">sailorcwx,这个lsp找了很久了,终于找到了,而且很好用,谢谢!</font></strong></p>

fqqc 发表于 2008-10-2 18:08:00

<p>能否再帮我改一下啦?</p><p>要求:改变后的图层其它属性也要跟着变,不只是颜色,像线型之类的都要变</p><p>谢谢!</p>
页: [1]
查看完整版本: [求助]快速改图层