乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 65|回复: 7

[编程交流] Export layers list (only a sel

[复制链接]

57

主题

243

帖子

190

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
285
发表于 2022-7-5 18:29:02 | 显示全部楼层 |阅读模式
I have this routine (unknown to the author). Thank you for your help with the following change: Export the list of layers but only on a selection.
 
 
  1. (defun c:LL2T ( / oecho clrlst dwgnm fn fh lyr lyrlst)(defun chkbit (bit_val num)(not (zerop (logand bit_val num))))(setqoecho (getvar "cmdecho")clrlst (list(cons 1 "RED")(cons 2 "YELLOW")(cons 3 "GREEN")(cons 4 "CYAN")(cons 5 "BLUE")(cons 6 "MAGENTA")(cons 7 "WHITE"))dwgnm (getvar "dwgname"))(setvar "cmdecho" 0)(setq fn (getfiled " File name: " (strcat dwgnm ".LS") "LS" (+ 1 2)))(while (setq lyr (tblnext "layer" (not lyr)))(setq lyrlst (cons (cdr (assoc 2 lyr)) lyrlst)))(setq lyrlst (acad_strlsort lyrlst))(princ "\nWriting layer data to file...")(setq fh (open fn "w"))(princ (strcat dwgnm ".DWG\n") fh)(foreach x lyrlst(setqlyr (tblsearch "layer" x)lyrname (cdr (assoc 2 lyr))lyrclr (cdr (assoc 62 lyr))lyrlt (cdr (assoc 6 lyr))frzn? (chkbit 1 (cdr (assoc 70 lyr)))lokd? (chkbit 4 (cdr (assoc 70 lyr))))(if (minusp lyrclr)(setqon? "OFF"lyrclr (abs lyrclr))(setq on? "ON"))(if (assoc lyrclr clrlst)(setq lyrclr (cdr (assoc lyrclr clrlst))))(if frzn?(setq frzn? "FROZEN")(setq frzn? "THAWED"))(if lokd?(setq lokd? "LOCKED")(setq lokd? "UNLOCKED"))(princ lyrname fh);;(princ "," fh);;(princ lyrclr fh);;(princ "," fh);;(princ lyrlt fh);;(princ "," fh);;(princ on? fh);;(princ "," fh);;(princ frzn? fh);;(princ "," fh);;(princ lokd? fh)(princ "\n" fh))(princ "done.")(close fh)(setvar "cmdecho" oecho)(princ))
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 18:44:57 | 显示全部楼层
Here is a similar program with a few more options - also, note that you can select layers from the Layer Manager and copy them directly.
回复

使用道具 举报

57

主题

243

帖子

190

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
285
发表于 2022-7-5 18:47:48 | 显示全部楼层
Lee, fantastic tool, as expected. Thank you for your statement. Already I kept. However, for this, I just want to extract the names of the layers contained in a selection, not the entire design.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 19:02:58 | 显示全部楼层
Maybe something like this?
  1. (defun c:layernames ( / f l s x )   (if (and (setq s (ssget))            (setq f (getfiled "Create File" "" "txt" 1))       )       (if (setq f (open f "w"))           (progn               (repeat (setq i (sslength s))                   (or (member (setq x (cdr (assoc 8 (entget (ssname s (setq i (1- i))))))) l)                       (and (write-line x f)                            (setq l (cons x l))                       )                   )               )               (close f)           )           (princ "\nUnable to open file for writing.")       )   )   (princ))
[untested]
回复

使用道具 举报

57

主题

243

帖子

190

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
285
发表于 2022-7-5 19:03:56 | 显示全部楼层
Lee, that's exactly. Better, just even making out the list sorted alphabetically. Thank you!
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 19:12:37 | 显示全部楼层
 
You're welcome! - For an alphabetically sorted output, try the following:
  1. (defun c:layernames ( / f l s x )   (if (and (setq s (ssget))            (setq f (getfiled "Create File" "" "txt" 1))       )       (if (setq f (open f "w"))           (progn               (repeat (setq i (sslength s))                   (or (member (setq x (cdr (assoc 8 (entget (ssname s (setq i (1- i))))))) l)                       (setq l (cons x l))                   )               )               (foreach x (acad_strlsort l) (write-line x f))               (close f)           )           (princ "\nUnable to open file for writing.")       )   )   (princ))
回复

使用道具 举报

57

主题

243

帖子

190

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
285
发表于 2022-7-5 19:28:29 | 显示全部楼层
Lee, you're the best. But also generous. Thank you!
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 19:33:03 | 显示全部楼层
........
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-12 19:42 , Processed in 0.682256 second(s), 68 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表