Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to make selection set

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
danglar
1829 Views, 8 Replies

How to make selection set

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?

8 REPLIES 8
Message 2 of 9
dbhunia
in reply to: danglar

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

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 3 of 9
danglar
in reply to: dbhunia

Thank you!

All works perfect like a charm

I almost found the solution by myself
but I just make a little mistakeSmiley Happy
Message 4 of 9
danglar
in reply to: danglar

Final solution published here:

https://lispbox.wordpress.com/

 

 

 

Message 5 of 9
cadffm
in reply to: danglar

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)
)
- Sebastian -
Message 6 of 9
ВeekeeCZ
in reply to: danglar

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.

Message 7 of 9
danglar
in reply to: ВeekeeCZ

Thanks   and @CADffm

As you see I'm trying to learn autolisp coding by my own mistakes

and your help pushing me forward (sorry for my bad English) but I thing you understand me

Message 8 of 9
ВeekeeCZ
in reply to: danglar

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. 

Message 9 of 9
danglar
in reply to: ВeekeeCZ

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

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost