Author Topic: Selection by layer with crossing window  (Read 3352 times)

0 Members and 1 Guest are viewing this topic.

Zykl0

  • Guest
Selection by layer with crossing window
« on: October 07, 2014, 08:15:37 PM »
Hi,

I'm looking for a lisp that select every object in the drawing on the same layer ?
I have found quite a few but none of them allow me to select more than one object at time :-(

IS there an easy way to convert this script into a crossing windows selection of multiple layer?



(defun c:ss3 (/ ss Sel)

(if
 (and
  (setq Sel (entsel "\n Select object on layer desired: "))
  (setq ss (ssget "x" (list (cons 8 (cdr (assoc 8 (entget (car Sel))))) (cons 410 (getvar "ctab")))))
 )
 (sssetfirst nil ss)
)
(princ)
)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Selection by layer with crossing window
« Reply #1 on: October 07, 2014, 08:40:20 PM »
At first glance your request seems contradictory.

How do you want to nominate the layers to apply to the selection filter ?

Do you want to select objects and extract their layers to use,
or ??

For reference, this selects objects on the 2 nominated layers  using a user defined crossing

Code - Auto/Visual Lisp: [Select]
  1. (setq sel ( ssget  '( (8 . "ST-DIM,ANNO35"))))
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Zykl0

  • Guest
Re: Selection by layer with crossing window
« Reply #2 on: October 07, 2014, 08:48:12 PM »
Sorry for being unclear,

I want to select multiple entity with the cross window selection box, let say i select things on layer 1, 2 and 3
once i use the script i want all the entity on the drawing that are on layer 1,2 and 3 to be in my current selection no mater if they are block, polyline, line or whatever.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Selection by layer with crossing window
« Reply #3 on: October 07, 2014, 10:12:10 PM »
Have a play :

Code - Auto/Visual Lisp: [Select]
  1. ;; Codehimbelonga kdub@theSwamp 2014/10/08
  2.  
  3. (defun c:doit (/ sel ss selectioncount)
  4.   (if (and (setq sel (ssget))
  5.            (setq layerstring
  6.                   (listitems->string (selection-layers sel) ",")
  7.            )
  8.       )
  9.     (setq ss             (ssget "x" (list (cons 8 layerstring)))
  10.           selectioncount (sslength ss)
  11.     )
  12.     ;;else
  13.     (setq selectioncount 0)
  14.   )
  15.   (prompt (strcat "Selection count :" (itoa selectioncount) " ->> "))
  16.   (princ)
  17.   ss
  18. )
  19.  
  20.  


Library stuff

Code - Auto/Visual Lisp: [Select]
  1. ;; Codehimbelonga kdub@theSwamp 2014/10/08
  2. (defun selection-layers (ss / layerlist index)
  3.   (setq layerlist '()
  4.         index 0
  5.   )
  6.   (while (< index (sslength ss))
  7.     (setq layerlist (cons (cdr (assoc 8 (entget (ssname ss index)))) layerlist)
  8.           index     (1+ index)
  9.     )
  10.   )
  11.   (acad_strlsort (delete-duplicates layerlist))
  12. )
  13.  
  14. (defun delete-duplicates (lst / tmp)
  15.   (while lst
  16.     (setq tmp (cons (car lst) tmp)
  17.           lst (vl-remove-if
  18.                 '(lambda (x) (equal x (car tmp) 0.000001))
  19.                 lst
  20.               )
  21.     )
  22.   )
  23.   (reverse tmp)
  24. )
  25.  
  26. (defun listitems->string (listitems delimiter)
  27.   (if (cdr listitems)
  28.     (strcat (car listitems) delimiter (listitems->string (cdr listitems) delimiter))
  29.     (car listitems)
  30.   )
  31. )
  32.  


« Last Edit: October 07, 2014, 10:15:59 PM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Selection by layer with crossing window
« Reply #4 on: October 08, 2014, 01:32:16 AM »
Afterthought:
You should add a prompt for selecting the initial objects ( to determine the layers for the filter) .. just so the user knows what is happening.

Also add comments as required ...

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Selection by layer with crossing window
« Reply #5 on: October 08, 2014, 07:41:03 AM »
Here's another way to write it:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:layersel ( / i l n s )
  2.     (if (setq s (ssget))
  3.         (progn
  4.             (repeat (setq i (sslength s))
  5.                 (or (member (setq n (cdr (assoc 8 (entget (ssname s (setq i (1- i))))))) l)
  6.                     (setq l (vl-list* "," n l))
  7.                 )
  8.             )
  9.             (sssetfirst nil (ssget "_X" (list (cons 8 (apply 'strcat (cdr l))))))
  10.         )
  11.     )
  12.     (princ)
  13. )

Zykl0

  • Guest
Re: Selection by layer with crossing window
« Reply #6 on: October 08, 2014, 07:52:00 AM »
Thank you guys,

This is exactly what i needed!

Have a great day.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Selection by layer with crossing window
« Reply #7 on: October 08, 2014, 08:03:04 AM »
You're most welcome Zykl0  :-)

GDF

  • Water Moccasin
  • Posts: 2081
Re: Selection by layer with crossing window
« Reply #8 on: October 08, 2014, 09:43:55 AM »
Lee, that is pretty sweet. I can use this.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Selection by layer with crossing window
« Reply #9 on: October 08, 2014, 09:48:27 AM »
Lee, that is pretty sweet. I can use this.

Cheers Gary - I'm glad you find it useful  :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Selection by layer with crossing window
« Reply #10 on: October 09, 2014, 06:09:10 AM »
Thank you guys,

This is exactly what i needed!

Have a great day.

Pleased you are pleased ;)


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.