明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 7773|回复: 26

[基础] [求助]图层快速变换

  [复制链接]
发表于 2010-10-6 00:10 | 显示全部楼层 |阅读模式

    自己想实现 将选择的对象变换到指定的图层,如果没有选择对象则将这个命令包含的图层设为当前。

    例如 我选择一条直线,输入命令C1,将其转换到预先设置好的“1”图层中;如果没有选择任何对象,而输入命令“C1”,那就将“1”图层设为当前。这个就是天河CAD的图层变换工具的功能。

    自己想把这个命令写出来,但是谁为当前图层不知道该如何来做?不知道该怎么来识别没有选择对象的情况。

    很傻很天真的求助中...

(defun C:C0 () (ssget) (command "change" "P" "la" "0" ""))
(defun C:C1 () (ssget) (command "change" "P" "la" "1" ""))
(defun C:C2 () (ssget) (command "change" "P" "la" "2" ""))
(defun C:C3 () (ssget) (command "change" "P" "la" "3" ""))
(defun C:C4 () (ssget) (command "change" "P" "la" "4" ""))
(defun C:C5 () (ssget) (command "change" "P" "la" "5" ""))
(defun C:C6 () (ssget) (command "change" "P" "la" "6" ""))

发表于 2019-5-16 19:33 | 显示全部楼层
自己用的一个程序,分享大家,更改至0层

  1. (defun c:00 (/ ss i ent)
  2.   (setq ss (ssget))
  3.   (entToLayer ss "0")
  4.   (princ)
  5. )


  6. (defun entToLayer (ss name / ent i)
  7.   (if (/= ss nil)
  8.     (repeat (setq i (sslength ss))
  9.       (setq i (- i 1))
  10.       (setq ent (entget (ssname ss i)))
  11.       (setq ent
  12.              (uTbMod ent
  13.                      (list (cons 8 name) (cons 6 "BYLAYER") (cons 62 256))
  14.              )
  15.       )
  16.       (entmod ent)
  17.     )
  18.     (setvar 'CLAYER name)
  19.   )

  20. )
  21. (defun uTbMod (tb nLst)
  22.   (mapcar (function
  23.             (lambda (x) (setq tb (SUBST x (assoc (car x) tb) tb)))
  24.           )
  25.           nLst
  26.   )
  27.   tb
  28. )
发表于 2019-6-28 11:15 | 显示全部楼层
本帖最后由 chenccna 于 2019-7-2 20:11 编辑
yutianweidi 发表于 2010-12-5 18:34
前提是需要将CAD绘图区域的模板设置好,就是图层要设置好,给出两个命令!
1.以下自动加载默认图层
(defu ...

不能选中后替换图层啊?
更改如下:可以选中后直接替换图层
(defun layerch(mylsp / LAYCH)
    (setvar "PICKFIRST" 1)
    (setvar "cmdecho" 0)
(if (setq LAYCH (ssget)) ;如果已选择图形则将选择的图形转换到指定的层
  (command "change" laych "" "p" "lt" "bylayer" "c" "bylayer" "la" mylsp "")
(command "_layer" "m" mylsp  "");否则将指定的层转换为当前层
)
(prin1)
)

发表于 2019-2-24 15:15 | 显示全部楼层
yutianweidi 发表于 2010-12-5 18:34
前提是需要将CAD绘图区域的模板设置好,就是图层要设置好,给出两个命令!
1.以下自动加载默认图层
(defu ...

为什么这个在CAD2018版本就不能用了?
 楼主| 发表于 2010-10-6 00:15 | 显示全部楼层

    写错了

    自己想把这个命令写出来,但是谁为(设为)当前图层不知道该如何来做?不知道该怎么来识别没有选择对象的情况。

    很傻很天真的求助中...

发表于 2010-10-7 17:19 | 显示全部楼层

(defun C:C0 (/ s1) (setq s1 (ssget)) (if (= s1 nil) (command "-layer" "s" "0" "") (command "change" s1 "" "P" "la" "0" "")))

 

其它的知道怎麼改了吧!!

发表于 2010-10-7 19:07 | 显示全部楼层

楼上程序不能实现预选择

给个参考程序

http://bbs.mjtd.com/forum.php?mod=viewthread&tid=79588&replyID=&skin=0

发表于 2010-10-8 08:07 | 显示全部楼层

如樓上所言,修改如下:

(defun C:C0 (/ s1)
(setq s1 (cadr(ssgetfirst)))
(if (= s1 nil) (command "-layer" "s" "0" "")
(command "change" s1 "" "P" "la" "0" "")
)
(princ)
)

 

 

发表于 2010-12-1 21:08 | 显示全部楼层
楼上程序可用
但是可不可以改下使他能实现如下功能:
预选某实体,输入C1命令后实体自动归到1层,如果没有1层则自动创建1层并且1层颜色为XXX号,线形为xxx。(XXX可以自己设置)

发表于 2010-12-5 18:16 | 显示全部楼层
我也是 很傻很天真的求助中...
发表于 2010-12-5 18:34 | 显示全部楼层
本帖最后由 yutianweidi 于 2010-12-5 18:37 编辑

前提是需要将CAD绘图区域的模板设置好,就是图层要设置好,给出两个命令!
1.以下自动加载默认图层
(defun c:EEA()
      (command "layer" "n" "0"  "l" "continuous" "0" "c" "7" "0" "")
      (command "layer" "n" "BASE"  "l" "phantom2" "BASE" "c" "1" "BASE" "")
      (command "layer" "n" "BEND"  "l" "continuous" "BEND" "c" "2" "BEND" "")
      (command "layer" "n" "CENTER"  "l" "center2" "CENTER" "c" "1" "CENTER" "")
      (command "layer" "n" "DIM"  "l" "continuous" "DIM" "c" "4" "DIM" "")
      (command "layer" "n" "FORM"  "l" "continuous" "FORM" "c" "180" "FORM" "")
      (command "layer" "n" "HATCH"  "l" "continuous" "HATCH" "c" "1" "HATCH" "")
      (command "layer" "n" "HIDDEN"  "l" "DASHED" "HIDDEN" "c" "2" "HIDDEN" "")
      (command "layer" "n" "LASER"  "l" "continuous" "LASER" "c" "1" "LASER" "")
      (command "layer" "n" "MARK"  "l" "continuous" "MARK" "c" "3" "MARK" "")
      (command "layer" "n" "NCT"  "l" "continuous" "NCT" "c" "6" "NCT" "")
      (command "layer" "n" "PREP"  "l" "continuous" "PREP" "c" "5" "PREP" "")
      (command "layer" "n" "PREPHID"  "l" "DASHED" "PREPHID" "c" "5" "PREPHID" "")
      (command "layer" "n" "ZCJG"  "l" "continuous" "ZCJG" "c" "3" "ZCJG" "")
)

1.以下用于图层转换

;本程序定义一些图层转换命令,本程序执行时,先选择图形再输入命令则将选择的图形转换到指定的层
;             不选择图形直接输入命令则将指定的层转换为当前层.
(DEFUN LAYERCH(MYLSP / LAYCH)
(if (setq LAYCH (ssget "i"))          ;如果已选择图形则将选择的图形转换到指定的层
   (command "_.change" LAYCH "" "_p" "_LT" "BYLAYER" "_C" "BYLAYER" "_la" mylsp "")
   (command "_layer" "m" mylsp  "")    ;否则将指定的层转换为当前层
)
   (princ)
)
(DEFUN C:DI() (LAYERCH "DIM"))          ;用简化命令DI定义DIM图层的转换命令
(DEFUN C:LS() (LAYERCH "LASER"))
(DEFUN C:ZC() (LAYERCH "ZCJG"))
(DEFUN C:PP() (LAYERCH "PREP"))
(DEFUN C:Q() (LAYERCH "0"))
(DEFUN C:NC() (LAYERCH "NCT"))
(DEFUN C:MA() (LAYERCH "MARK"))
(DEFUN C:FM() (LAYERCH "FORM"))
(DEFUN C:BE() (LAYERCH "BEND"))
(DEFUN C:BA() (LAYERCH "BASE"))
(DEFUN C:HI() (LAYERCH "HIDDEN"))
;如果要定义其它图层的简化命令,按以上格式即可.

发表于 2010-12-5 19:09 | 显示全部楼层
设为当前层可直接修改系统变量——clayer
发表于 2010-12-6 22:23 | 显示全部楼层
8楼的,也没打到楼主的要求去,期待中
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-10 00:20 , Processed in 0.145289 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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