找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1086|回复: 2

[每日一码] 创建层从其他存在的层复制属性

[复制链接]

已领礼包: 19个

财富等级: 恭喜发财

发表于 2016-12-13 14:53:09 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
命令 test 拾取实体拷贝图层
命令 test1, 对话框选择复制的图层

(defun ListBox (title msg keylab flag / tmp file dcl_id choice)
  ;; ListBox (gile)
  ;; Dialog box to choose one or more in a list
  ;;
  ;; Arguments
  ;; title : the dialog title (string)
  ;; msg ; message (string), "" or nil for none
  ;; keylab : an dotted pairs list of type ((key1 . label1) (key2 . label2) ...)
  ;; flag : 0 = popup list
  ;;        1 = single choice list box
  ;;        2 = multipe choices list box
  ;;
  ;; Return value : the choosen key (flag = 0 or 1) or the list of choosen keys (flag = 2)
  ;;
  ;; Using example
  ;; (listbox "Layout" "Choose a layout" (mapcar 'cons (layoutlist) (layoutlist)) 1)

  ;; create and open a temporay file
  (setq        tmp  (vl-filename-mktemp "tmp.dcl")
        file (open tmp "w")
  )
  ;; write the file according to arguments
  (write-line
    (strcat "ListBox:dialog{label=\"" title "\";")
    file
  )
  (if (and msg (/= msg ""))
    (write-line (strcat ":text{label=\"" msg "\";}") file)
  )
  (write-line
    (cond
      ((= 0 flag) "spacer;:popup_list{key=\"lst\";")
      ((= 1 flag)
       "spacer;:list_box{key=\"lst\";allow_accept = true;"
      )
      (T "spacer;:list_box{key=\"lst\";multiple_select=true;")
    )
    file
  )
  (write-line "}spacer;ok_cancel;}" file)
  (close file)

  ;; load the file and show the dialog
  (setq dcl_id (load_dialog tmp))
  (if (not (new_dialog "ListBox" dcl_id))
    (exit)
  )
  (start_list "lst")
  (mapcar 'add_list (mapcar 'cdr keylab))
  (end_list)
  (action_tile
    "accept"
    "(or (= (get_tile \"lst\") \"\")
                    (if (= 2 flag) (progn
                    (foreach n (str2lst (get_tile \"lst\") \" \")
                    (setq choice (cons (nth (atoi n) (mapcar 'car keylab)) choice)))
                    (setq choice (reverse choice)))
                    (setq choice (nth (atoi (get_tile \"lst\")) (mapcar 'car keylab)))))
                    (done_dialog)"
  )
  (start_dialog)
  (unload_dialog dcl_id)
  (vl-file-delete tmp)
  choice
)
(defun make-copy-layer (New_Layer_Name Owner_Layer_Name / tmp)
;;;[url]http://www.caduser.ru/forum/index.php?PAGE_NAME=message&FID=2&TID=47868&PAGEN_1=2[/url]
;;;Functionh to create a copy of the layer
;;; New_Layer_Name - the name of the new layer
;;; Owner_Layer_Name - name of the copied layer
;;; Returns ename copy created layer or nil
;;; (Make-copy-layer "My new layer" "0")

  (if (and (setq tmp (tblobjname "LAYER" Owner_Layer_Name))
           (setq tmp (entget tmp))
           (snvalid New_Layer_Name 0)
           (not (tblsearch "LAYER" New_Layer_Name))
      )
    (entmakex (subst (cons 2 New_Layer_Name) (assoc 2 tmp) tmp))
  )
)
;;;Written By Michael Puckett. 
;;;(setq all_layers (tablelist "LAYER"))
(defun tablelist (s / d r)
  (while (setq d (tblnext s (null d)))
    (setq r (cons (cdr (assoc 2 d)) r))
  ) ;_ while
) ;_ defun
(defun c:test (/ e1 _l _n _nl)
  (if
    (setq e1
           (entsel
             "\nPlease select a primitive copy of the layer you want to get <exit>: "
           )
    )
     (progn
       (print (setq _l (cdr (assoc 8 (entget (car e1))))))
       (setq _nl (getstring t "\nNew layer name: "))
       (if (make-copy-layer _nl _l)
         (setvar "clayer" _nl)
       )
     )
  )
)                                        ;defun
(defun C:test1 (/ _nl _l)
  (vl-load-com)
  (and
    (setq _l
           (listbox "Layer"
                    "Select exist layer"
                    ((lambda (l) (mapcar 'cons l l))
                      (vl-remove-if-not 'snvalid (tablelist "LAYER"))
                    )
                    1
           )
    )
    (setq _nl (getstring t "\nNew layer name: "))
    (snvalid _nl 0)
    (if        (make-copy-layer _nl _l)
      (setvar "clayer" _nl)
    )
  )
  (princ)
)
(princ "\n type Test or Test1 in command line")
(princ)

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 1304个

财富等级: 财源广进

发表于 2016-12-13 15:46:44 | 显示全部楼层
啥也不说了,感谢楼主分享哇!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 1094个

财富等级: 财源广进

发表于 2021-11-13 06:26:00 | 显示全部楼层
感谢分享创建层从其他存在的层复制属性
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2025-9-26 02:13 , Processed in 0.170102 second(s), 33 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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