乐筑天下

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

[编程交流] copy layer and sort, sometime

[复制链接]
pBe

32

主题

2722

帖子

2666

银币

后起之秀

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

铜币
211
发表于 2022-7-6 10:19:00 | 显示全部楼层
try this (for now)
 

[code](defun c:test (/ adoc ppt1 ssob dwqty lys)(vl-load-com)(setq adoc (vla-get-activedocument (vlax-get-acad-object)))(setq ssob (ssget) dwqty 0)(mapcar(function(lambda (j / k)(if (not (member (setq k (cdr (assoc 8 (entget j)))) lys))(setq lys (cons k lys)))))(vl-remove-if 'listp (mapcar 'cadr (ssnamex ssob))))(foreach ln lys(sssetfirst nil ssob)(setq sellay (ssget "_p" (list (cons 8 ln))))(vlax-for ob (vla-get-activeselectionset adoc)(vla-move (vla-copy ob) (vlax-3d-point (setq ppt1 '(0.0 0.0)))(vlax-3d-point (polar ppt1 0.785398 (setq dwqty (+ 50 dwqty)))));
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-6 10:21:15 | 显示全部楼层
This might be in need of change ..
 
  1. (* pi (/ 270. 180.0))
回复

使用道具 举报

pBe

32

主题

2722

帖子

2666

银币

后起之秀

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

铜币
211
发表于 2022-7-6 10:24:12 | 显示全部楼层
i guess you're right
but as much as possible I dont want to deviate from his orignal code thats why it sticks and I still dont fully undertand the prurpose of his routine.
 
but good call  neverthelss  TharwaT
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-6 10:28:34 | 显示全部楼层
That what I felt of in the beginning of the thread.
 
But now I guess that he wants to repeat the selected objects according to the quantity of Layers that are
existed within the selection set and not to be repeat two or three times if many objects are laying within the same Layer Name.
 
Hope that my guess is right although .
回复

使用道具 举报

pBe

32

主题

2722

帖子

2666

银币

后起之秀

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

铜币
211
发表于 2022-7-6 10:30:39 | 显示全部楼层
 
We shall see......  
 
I'm guessing as well
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-6 10:33:35 | 显示全部楼层
I think his problem is in his first ssget selection, he's selecting objects on multiple layers. The first time for each layer is fine, but if it's repeated, all hell breaks loose.
 
Is this what you are after?
 
  1. (defun c:TEst (/ q ss pt i layer lst) (if (and (setq q  -50.                ss (ssget "_:L")          )          (setq pt (getpoint "\nSpecify base point: "))     )   (repeat (setq i (sslength ss))     (if (not (member (setq layer (cdr (assoc 8 (entget (ssname ss (setq i (1- i))))))) lst))       (progn (setq lst (cons layer lst))              (command "_.copy"                       [color=red](ssget "_X" (list (cons 8 layer) (cons 410 (getvar 'ctab))))[/color] ;TERRIBLE METHOD!!!                       ""                       "_non"                       (polar pt (* 1.5 pi) (setq q (+ q 50.)))                       ""              )       )     )   ) ) (princ))
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 10:35:45 | 显示全部楼层
I'd probably write it like this:
 
  1. (defun c:test ( / _move d ss l lst ) (vl-load-com) (defun _move ( obj dist )   (vla-move (vla-copy obj) (vlax-3D-point '(0. 0. 0.)) (vlax-3D-point (list 0. dist 0.))) ) (if (ssget "_:L")   (progn     (vlax-for obj (setq d 0. ss (vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object))))       (_move obj         (cond           ( (cdr (assoc (setq l (vla-get-layer obj)) lst)) )           ( (setq lst (cons (cons l (setq d (- d 50.))) lst)) d )         )       )     )     (vla-delete ss)   ) ) (princ))
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-6 10:39:23 | 显示全部楼层
This is why one shouldn't code when they are coming down with the flu. Nice work Lee. I am curious, won't _move error the first time for each layer, since your cond will return nil, or is my sickness missing something.....I'm going home.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 10:42:02 | 显示全部楼层
 
Cheers dude
 
The cond will never return nil, since the second condition just constructs the list and returns the distance.
 
Hope you get better soon mate
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-6 10:48:02 | 显示全部楼层
Yeah, I was standing in front of the urinal and realized what you must have done.
Thanks.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-6 23:08 , Processed in 0.332693 second(s), 70 queries .

© 2020-2025 乐筑天下

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