Author Topic: Passing a list to SSGET Logical Operators  (Read 1422 times)

0 Members and 1 Guest are viewing this topic.

Coltm16

  • Guest
Passing a list to SSGET Logical Operators
« on: February 03, 2017, 11:14:07 AM »
Is it possible to pass a list to an SSGET function with conditional operators, or something similar to accomplish the same thing? I've tried everything I can think of but it is not working. Example:

Code - Auto/Visual Lisp: [Select]
  1. (setq mylist (list (cons 8 "Layer1") (cons 8 "Layer2")))
  2. (setq ss (ssget (list (cons -4 "<OR")  mylist (cons -4 "OR>"))))
  3. (command "_stretch" ss "")

Thanks for any help.


« Last Edit: February 03, 2017, 11:20:30 AM by Coltm16 »

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Passing a list to SSGET Logical Operators
« Reply #1 on: February 03, 2017, 11:24:11 AM »
Code - Auto/Visual Lisp: [Select]
  1. (ssget '((8 . "Layer1,Layer2")))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Coltm16

  • Guest
Re: Passing a list to SSGET Logical Operators
« Reply #2 on: February 03, 2017, 12:03:54 PM »
Thanks, Have not tested it yet, but can it be:

Code - Auto/Visual Lisp: [Select]
  1. (setq mylistoflayers (list "Layer1"" Layer2")
  2. (ssget '((8 . mylistoflayers)))

or Do i need to use

Code - Auto/Visual Lisp: [Select]
  1. (ssget (list (cons 8 mylistoflayers)))

edit: or should I use strcat with each element of the list of layers?

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Passing a list to SSGET Logical Operators
« Reply #3 on: February 03, 2017, 12:10:57 PM »
If you have a list of layer names, you could do something like this:
Code - Auto/Visual Lisp: [Select]
  1.   (list
  2.     (cons 8
  3.      (apply 'strcat (mapcar '(lambda (layname) (strcat layname ",")) (list "Layer1" " Layer2")))
  4.     )
  5.   )
  6. )
Also be aware you can use wild cards too:
Code - Auto/Visual Lisp: [Select]
  1. (ssget '((8 . "Layer*")))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Coltm16

  • Guest
Re: Passing a list to SSGET Logical Operators
« Reply #4 on: February 03, 2017, 12:33:53 PM »
Thanks! I am so close. However, my layerslist is coming out like ("layer1," "layer2,"....) Instead of one long string ("layer1,layer2,layer3....). Thank you for your help!

Code - Auto/Visual Lisp: [Select]
  1. (defun c:stretchfilter (/ ss i l x ent layerlist)
  2.  
  3. (Princ "\nSelect object(s) to include their layers in a stretch command.")
  4. (if (setq ss (ssget ":L"))
  5.         (progn
  6.                 (repeat (setq i (sslength ss))
  7.                         (if (not (member (setq l (cdr (assoc 8 (entget (ssname ss (setq i (1- i))))))) x))
  8.                                 (setq x (cons l x))
  9.                                 );endif
  10.                 );endrepeat
  11.                 (setq layerlist (mapcar '(lambda (layname) (strcat layname ",")) x ))
  12.                 (princ (strcat "\nOnly these layers will be included in the selection window: " layerlist))
  13.                 (princ "\nSelect objects to stretch by crossing-window or crossing-polygon...")
  14.                 (setq ss (ssget (list (cons -4 "<OR")  (cons 8 layerlist) (cons -4 "OR>"))))
  15.                 (command "_Stretch" ss "")
  16.         ));endif and progn
  17. );end func

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Passing a list to SSGET Logical Operators
« Reply #5 on: February 03, 2017, 12:37:10 PM »
Code - Auto/Visual Lisp: [Select]
  1. (apply 'strcat layerlist)

Coltm16

  • Guest
Re: Passing a list to SSGET Logical Operators
« Reply #6 on: February 03, 2017, 12:44:12 PM »
Awesome, Thank You!