pBe 发表于 2022-7-6 10:19:00

try this (for now)
 

(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)))));

Tharwat 发表于 2022-7-6 10:21:15

This might be in need of change ..
 

(* pi (/ 270. 180.0))

pBe 发表于 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 callneverthelssTharwaT

Tharwat 发表于 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 发表于 2022-7-6 10:30:39

 
We shall see......
 
I'm guessing as well

alanjt 发表于 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?
 

(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"                     (ssget "_X" (list (cons 8 layer) (cons 410 (getvar 'ctab)))) ;TERRIBLE METHOD!!!                     ""                     "_non"                     (polar pt (* 1.5 pi) (setq q (+ q 50.)))                     ""            )       )   )   ) ) (princ))

Lee Mac 发表于 2022-7-6 10:35:45

I'd probably write it like this:
 

(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))

alanjt 发表于 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.

Lee Mac 发表于 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

alanjt 发表于 2022-7-6 10:48:02

Yeah, I was standing in front of the urinal and realized what you must have done.
Thanks.
页: 1 [2]
查看完整版本: copy layer and sort, sometime