乐筑天下

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

[编程交流] Lisp: Put all XREFs on layer "

[复制链接]

11

主题

24

帖子

13

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
55
发表于 2022-7-6 06:57:16 | 显示全部楼层 |阅读模式
I need a lisp routine to put all xrefs in a drawing onto the layer "G-XREF". Where;
If the layer does not exist it would be created first?
 
?
:unsure:
回复

使用道具 举报

pBe

32

主题

2722

帖子

2666

银币

后起之秀

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

铜币
211
发表于 2022-7-6 07:03:01 | 显示全部楼层
  1. (defun c:XRL (/ objs ent i)(setq objs (ssget "_X" '((0 . "INSERT")[color=blue](8 . "~G-XREF")[/color])))(repeat (setq i (sslength objs))       (setq ent (entget (ssname objs (setq i (1- i)))))            (if [color=blue](and[/color] (= 4 (logand 4 (cdr (assoc 70 (tblsearch "BLOCK" (cdr (assoc 2 ent)))))))      [color=blue](= (cdr (assoc 70 (entget (tblobjname "LAYER" (cdr (assoc 8 ent)))))) 0))[/color]     (entmod (subst (cons 8 "G-XREF")(assoc 8 ent) ent)))))
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-6 07:06:24 | 显示全部楼层
 
You may need also to add some more codes for adding the layer name to the layer Name list pBe.
回复

使用道具 举报

pBe

32

主题

2722

帖子

2666

银币

后起之秀

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

铜币
211
发表于 2022-7-6 07:09:12 | 显示全部楼层
 
No tharwat, entmod does that for you.
if the layer does not exist it will create the layer on the fly
 
What should be added is a filter excluding INSERTS/XREF already on layer G-XREF
 
  1. (setq objs (ssget "_X" '((0 . "INSERT")[color=blue](8 . "~G-XREF")[/color])))
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-6 07:10:51 | 显示全部楼层
You're right pBe .
 
I am sorry for the confusion .
回复

使用道具 举报

pBe

32

主题

2722

帖子

2666

银币

后起之秀

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

铜币
211
发表于 2022-7-6 07:14:24 | 显示全部楼层
 
No worries Tharwat. and again no need to apologize my friend.
 
Cheers
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 07:17:18 | 显示全部楼层
 
 
Nice one pBe; just be sure to watch for XREF's on locked layers :wink:
回复

使用道具 举报

pBe

32

主题

2722

帖子

2666

银币

后起之秀

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

铜币
211
发表于 2022-7-6 07:21:43 | 显示全部楼层
 
Thanks Renderman.
Your are right
 
Post updated
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 07:23:49 | 显示全部楼层
Building on your code, and just for fun:
 
  1. (defun c:XRL2 ( / ss l) (if (setq ss (ssget "_x" (list '(0 . "INSERT")                                (cons 8 (strcat "~" (setq l "G-XREF"))))))   ((lambda (i / e n)      (while (setq e (entget (ssname ss (setq i (1+ i)))))        (if (and (= 4 (logand 4 (cdr (assoc 70 (tblsearch "block" (cdr (assoc 2 e)))))))                 (= 0 (cdr (assoc 70 (entget (tblobjname "layer" (cdr (setq n (assoc 8 e)))))))))          (entmod (subst (cons 8 l) n e)))))     -1)   (prompt "\n** Nothing selected ** ")) (princ))
 
  1. (defun c:XRL3 ( / dxf ss l) (defun dxf (n eData)   (if (and (= 'INT (type n)) (listp eData))     (cdr (assoc n eData))     (prompt "\n** "DXF" error: Invalid argument ** ")))  (if (setq ss (ssget "_x" (list '(0 . "INSERT")                                (cons 8 (strcat "~" (setq l "G-XREF"))))))   ((lambda (i / e)      (while (setq e (entget (ssname ss (setq i (1+ i)))))        (if          (and            (= 4 (logand 4 (dxf 70 (tblsearch "block" (dxf 2 e)))))            (= 0 (dxf 70 (entget (tblobjname "layer" (dxf 8 e))))))           (entmod (subst (cons 8 l) (assoc 8 e) e)))))     -1)   (prompt "\n** Nothing selected ** ")) (princ))
回复

使用道具 举报

pBe

32

主题

2722

帖子

2666

银币

后起之秀

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

铜币
211
发表于 2022-7-6 07:28:47 | 显示全部楼层
Great stuff Renderman.
 
Question for you.
Can  you use both "_X" and  ":L" method of selection for ssget together in one syntax? perhaps on newer version?
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-10 10:09 , Processed in 1.431935 second(s), 72 queries .

© 2020-2025 乐筑天下

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