this routine can copy selected objects to pre defined layer in a same place
(defun c:ccl ( / oldsnap ss x obj) (setq oldsnap (getvar "osmode")) (setvar "osmode" 167) (princ "\n\nSelect Objects for BACKGROUND layer.") (setq ss (ssget)) (repeat (setq x (sslength ss)) (setq obj (ssname ss (setq x (- x 1)))) (setq converted (ssadd)) (command "copy" obj "" "0,0" "0,0") (command "chprop" "L" "" "layer" "0-BACKGROUND" "") (ssadd (entlast) converted) (command "select" converted "") (sssetfirst nil converted) ) (setvar "osmode" oldsnap) (princ) )
I need to select all copied objects in this layer but sssetfirst select only last object and I need ALL of it
Can somebody help me?
Solved! Go to Solution.
Solved by ВeekeeCZ. Go to Solution.
Solved by cadffm. Go to Solution.
Solved by dbhunia. Go to Solution.
hi
try this..........
(defun c:ccl ( / oldsnap ss x obj) (setq oldsnap (getvar "osmode")) (setvar "osmode" 167) (princ "\n\nSelect Objects for BACKGROUND layer.") (setq ss (ssget)) (setq converted (ssadd)) (repeat (setq x (sslength ss)) (setq obj (ssname ss (setq x (- x 1)))) ;(setq converted (ssadd)) (command "copy" obj "" "0,0" "0,0") (command "chprop" "L" "" "layer" "0-BACKGROUND" "") (ssadd (entlast) converted) ;(command "select" converted "") ;(sssetfirst nil converted) ) (command "select" converted "")
(sssetfirst nil converted) (setvar "osmode" oldsnap) (princ) )
perhaps i am wrong, but
;; ccl edited/commented
(defun c:ccl2 () ;;(setq oldsnap (getvar "osmode")) ; why dealing with osmode ??? No Pickpoints used in this Lisp..; Except copy source- and targetpoint ;;(setvar "osmode" 167) ; but i guess you want really 0,0 and not a snapped pickpoint (osmode 127) from there !? (princ "\n\nSelect Objects for BACKGROUND layer.") ;; (setq ss (ssget)) ; without IF, it's not needed ;; (setq converted (ssadd)) ; it's not needed ;; (repeat (setq x (sslength ss)) ; if you have a selectionset, why working each item by item? ;; (setq obj (ssname ss (setq x (- x 1)))) (command "_.copy" (ssget) "" "_non" "0,0" "_non" "0,0") (command "_.chprop" "_p" "" "_layer" "0-BACKGROUND" "") ;; (ssadd (entlast) converted) ; it's not needed ;; );_repeat ;; (command "select" converted "") ; it's not needed (sssetfirst nil (ssget "_p")) ;; (setvar "osmode" oldsnap) ; no change, no re-set needed (princ) )
;; ccl rewritten (defun c:ccl3 (/ ss) (setvar 'CMDECHO 0) (princ "\n\nSelect Objects for BACKGROUND layer.") (if (setq ss (ssget "_:L")) (progn (command "_.LAYER" "_new" "0-BACKGROUND" "_on" "0-BACKGROUND" "_thaw" "0-BACKGROUND" "" "_.copy" ss "" "_non" "0,0" "_non" "0,0" "_.chprop" "_p" "" "_layer" "0-BACKGROUND" "" ) (sssetfirst nil ss) ) (princ "\nNothing selected, canceled.") ) (princ) )
Hi @danglar, nice attempt!
But... the first rule of using build-in commands within the (command) function is run them as few times as possible - because they are reeeealy sloooow.
Try your routine and compare with @cadffm's one on a large number of entities. You'll see the difference.
And add (setvar 'cmdecho 1) to his routine to restore the echo.
Since you're learning, here is another very common approach.
- making a mark by saving last entity
- let a command create new entities as many as need... often we don't know how many.
- then catch all new entities from the mark to the end of the database.
(defun c:ccl3 (/ *error* ss ssnew enl) (defun *error* (errmsg) (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end")) (princ (strcat "\nError: " errmsg))) (setvar 'CMDECHO 1) ; since a sysvar was changed make sure to restore it back. (princ)) (princ "\n\nSelect Objects for BACKGROUND layer,") (if (setq ss (ssget "_:L")) (progn (setq enl (entlast)) ; save last entity - MARK (setvar 'CMDECHO 0) (command "_.LAYER" "_new" "0-BACKGROUND" "_on" "0-BACKGROUND" "_thaw" "0-BACKGROUND" "" "_.COPY" ss "" "_non" "0,0" "_non" "0,0") (setq ssnew (ssadd)) ; create an empty selection set (while (setq enl (entnext enl)) ; while there is some next entity from the MARK (ssadd enl ssnew)) ; add it to my selection set because it's a new (command "_.CHPROP" ssnew "" "_layer" "0-BACKGROUND" "") (setvar 'CMDECHO 1) (sssetfirst nil ssnew) ) (princ "\nNothing selected, canceled.") ) (princ) )
There is a difference in DRAWORDER between @cadffm's routine and mine (or your original attempt). While his changes a layer of the ORIGINAL entities, so they are in the BACK, my is changing all NEW ones being as a copy in the FRONT. I guess in this case may be even preferable to have all objects at 0-BACKROUND layer in the BACK, but usually we/I expect to change the new ones.
It's very interesting approach. Now we can to see the solution of issue from different point of view..
Thank you for your opinion to my posts