Author Topic: Wcmatch or Selset filter  (Read 1592 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Wcmatch or Selset filter
« on: October 25, 2022, 11:52:32 AM »
I have this ssget filter:
(setq SstABC (ssget "_X" '((8 . "$ABC_REVS,$ABC_TEXT*,$ABC_ATTRIB,$ABC_THIN,$ABC_NORM,$ABC_MIDI,$ABC_WIDE,$ABC_DIM,$ABC_HATCH") (67 . 0))))

Is there a more elegant method of building a Wcmatch or Selset filter?
Code: [Select]
Example:
(setq In_Lst '("REVS" "TEXT*" "ATTRIB" "THIN" "NORM" "MIDI" "WIDE" "DIM" "HATCH"))
(defun BuildWcmatchStr (In_Lst PfxStr / OutStr)
  (setq OutStr "")
  (foreach ForElm In_Lst
    (setq OutStr (strcat OutStr PfxStr ForElm ","))
  )
  (substr OutStr 1 (1- (strlen OutStr)))
)
(setq FltStr (BuildWcmatchStr In_Lst "$ABC_"))
(setq SstABC (ssget "_X" (list (cons 8 FltStr) '(67 . 0))))

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Wcmatch or Selset filter
« Reply #1 on: October 25, 2022, 01:22:53 PM »
Perhaps?
Code - Auto/Visual Lisp: [Select]
  1. (setq sstabc (ssget "_X" '((8 . "$ABC_*") (67 . 0))))
or
Code - Auto/Visual Lisp: [Select]
  1. (apply 'strcat (mapcar '(lambda (x) (strcat "$ABC_" x ",")) in_lst))
« Last Edit: October 25, 2022, 01:26:30 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Wcmatch or Selset filter
« Reply #2 on: October 26, 2022, 03:07:42 AM »
Perhaps?
Code - Auto/Visual Lisp: [Select]
  1. (setq sstabc (ssget "_X" '((8 . "$ABC_*") (67 . 0))))
or
Code - Auto/Visual Lisp: [Select]
  1. (apply 'strcat (mapcar '(lambda (x) (strcat "$ABC_" x ",")) in_lst))
Thanks Ron for the answer  :-), I thought there was some other form of writing the filter string with brackets ([...]) or whatever...

>> (setq sstabc (ssget "_X" '((8 . "$ABC_*") (67 . 0)))) is not a sufficient filter for my need

I found two other similar possibilities:
Code: [Select]
; Martti Halminen
(defun join-with-delim-F (strings delimiter / temp)
  (foreach s strings
    (setq temp (cons s (cons delimiter temp)))
  )
  (apply (function strcat)
    (cdr (reverse temp))
  )
)
; Lee Mac
(defun LM:lst->str ( lst del / str )
    (setq str (car lst))
    (foreach itm (cdr lst) (setq str (strcat str del itm)))
    str
)
Code: [Select]
(setq In_Lst '("REVS" "TEXT*" "ATTRIB" "THIN" "NORM" "MIDI" "WIDE" "DIM" "HATCH"))

(strcat "$ABC_" (LM:lst->str       In_Lst ",$ABC_")) => "$ABC_REVS,$ABC_TEXT*,$ABC_ATTRIB,$ABC_THIN,$ABC_NORM,$ABC_MIDI,$ABC_WIDE,$ABC_DIM,$ABC_HATCH"
(strcat "$ABC_" (join-with-delim-F In_Lst ",$ABC_")) => "$ABC_REVS,$ABC_TEXT*,$ABC_ATTRIB,$ABC_THIN,$ABC_NORM,$ABC_MIDI,$ABC_WIDE,$ABC_DIM,$ABC_HATCH"

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Wcmatch or Selset filter
« Reply #3 on: October 30, 2022, 12:56:26 PM »
How about:
Code - Auto/Visual Lisp: [Select]
  1. (ssget "_X" (append '((67 . 0) (-4 . "<OR")) (mapcar '(lambda ( x ) (cons 8 (strcat "$ABC_" x))) In_Lst) '((-4 . "OR>"))))

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Wcmatch or Selset filter
« Reply #4 on: October 31, 2022, 04:04:01 AM »
How about:
Code - Auto/Visual Lisp: [Select]
  1. (ssget "_X" (append '((67 . 0) (-4 . "<OR")) (mapcar '(lambda ( x ) (cons 8 (strcat "$ABC_" x))) In_Lst) '((-4 . "OR>"))))
Thanks Lee  :-), just out of curiosity do you think that a list with OR is better than a string in ssget?
Code: [Select]
(-4 . "<OR") (8 . "$ABC_REVS") (8 . "$ABC_TEXT*") (8 . "$ABC_ATTRIB") (8 . "$ABC_THIN") (8 . "$ABC_NORM") (8 . "$ABC_MIDI") (8 . "$ABC_WIDE") (8 . "$ABC_DIM") (8 . "$ABC_HATCH") (-4 . "OR>")

"$ABC_REVS,$ABC_TEXT*,$ABC_ATTRIB,$ABC_THIN,$ABC_NORM,$ABC_MIDI,$ABC_WIDE,$ABC_DIM,$ABC_HATCH"

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Wcmatch or Selset filter
« Reply #5 on: October 31, 2022, 09:38:06 AM »
I'm unsure if there is a character limit imposed on the length of a string which may be used in an ssget filter list, but if there is, such a limit is likely to be hit sooner than any limit imposed on the length of the filter list itself, and as such, I would suggest using a list.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Wcmatch or Selset filter
« Reply #6 on: October 31, 2022, 01:04:34 PM »
I'm unsure if there is a character limit imposed on the length of a string which may be used in an ssget filter list, but if there is, such a limit is likely to be hit sooner than any limit imposed on the length of the filter list itself, and as such, I would suggest using a list.
It's a great reflection, thanks again.   8-)