Author Topic: Wcmatch: another silly question  (Read 3602 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Wcmatch: another silly question
« on: April 11, 2019, 03:43:21 AM »
I use very often this simple but very useful function:
Code: [Select]
(defun _WcmatchAll (text patterns) ; M. Puckett
  (vl-every
    (function (lambda (p) (wcmatch (strcase text) (strcase p))))
    patterns
  )
)
Purpose: discard anonymous blocks *X*, *U*, *D* and names starting with "X_"
Code: [Select]
(_WcmatchAll "*U254"   '("[~*]*" "~X_*")) => nil
(_WcmatchAll "*D45t"   '("[~*]*" "~X_*")) => nil
(_WcmatchAll "*X4gh"   '("[~*]*" "~X_*")) => nil
(_WcmatchAll "X_123"   '("[~*]*" "~X_*")) => nil
New Purpose: discard anonymous blocks *X*, *D* and names starting with "X_" but NOT *U* anonymous blocks
Code: [Select]
(_WcmatchAll "*U254"   '("[~*]D*"    "[~*]X*"    "~X_*")) => nil ?
(_WcmatchAll "*U254"   '("[~*]~D*"   "[~*]~X*"   "~X_*")) => nil ?
(_WcmatchAll "*U254"   '("[~*][~D]*" "[~*][~X]*" "~X_*")) => nil ?
???

kpblc

  • Bull Frog
  • Posts: 396
Re: Wcmatch: another silly question
« Reply #1 on: April 11, 2019, 03:53:46 AM »
Code - Auto/Visual Lisp: [Select]
  1. (_wcmatchall "*U254" '("~`*~D*" "~`*~X*" "~X_*"))
??
Sorry for my English.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Wcmatch: another silly question
« Reply #2 on: April 11, 2019, 04:54:15 AM »
Code - Auto/Visual Lisp: [Select]
  1. (_wcmatchall "*U254" '("~`*~D*" "~`*~X*" "~X_*"))
??
Code: [Select]
(_wcmatchall "*U254" '("~`*~D*" "~`*~X*" "~X_*")) => T   OK
(_wcmatchall "X_123" '("~`*~D*" "~`*~X*" "~X_*")) => nil OK
(_wcmatchall "*D45t" '("~`*~D*" "~`*~X*" "~X_*")) => T   must be nil
(_wcmatchall "*X4gh" '("~`*~D*" "~`*~X*" "~X_*")) => T   must be nil

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Wcmatch: another silly question
« Reply #3 on: April 11, 2019, 09:40:58 AM »
Try this:
Code - Auto/Visual Lisp: [Select]
  1. (_wcmatchall "*U254" '("~`*[DX]*" "~X_*"))
  2. (_wcmatchall "X_123" '("~`*[DX]*" "~X_*"))
  3. (_wcmatchall "*D45t" '("~`*[DX]*" "~X_*"))
  4. (_wcmatchall "*X4gh" '("~`*[DX]*" "~X_*"))
« Last Edit: April 11, 2019, 10:11:47 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Wcmatch: another silly question
« Reply #4 on: April 11, 2019, 10:19:13 AM »
Thanks!  :-) It wasn't that simple, grazie mille.  :yes:
Code: [Select]
New Purpose: discard anonymous blocks *X*, *D* and names starting with "X_" but NOT *U* anonymous blocks
                    (all other names are ok)
(_wcmatchall "Abcde" '("~`*[DX]*" "~X_*")) => T   OK
(_wcmatchall "*U254" '("~`*[DX]*" "~X_*")) => T   OK
(_wcmatchall "X_123" '("~`*[DX]*" "~X_*")) => nil OK
(_wcmatchall "*D45t" '("~`*[DX]*" "~X_*")) => nil OK
(_wcmatchall "*X4gh" '("~`*[DX]*" "~X_*")) => nil OK

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Wcmatch: another silly question
« Reply #5 on: April 11, 2019, 10:23:11 AM »
Thanks!  :-) It wasn't that simple, grazie mille.  :yes:
Code: [Select]
New Purpose: discard anonymous blocks *X*, *D* and names starting with "X_" but NOT *U* anonymous blocks
                    (all other names are ok)
(_wcmatchall "Abcde" '("~`*[DX]*" "~X_*")) => T   OK
(_wcmatchall "*U254" '("~`*[DX]*" "~X_*")) => T   OK
(_wcmatchall "X_123" '("~`*[DX]*" "~X_*")) => nil OK
(_wcmatchall "*D45t" '("~`*[DX]*" "~X_*")) => nil OK
(_wcmatchall "*X4gh" '("~`*[DX]*" "~X_*")) => nil OK
Glad to help :) .. this should work too if you want to use something a bit more legible.
Code - Auto/Visual Lisp: [Select]
  1. (_wcmatchall "Abcde" '("~`*D*" "~`*X*" "~X_*"))
  2. (_wcmatchall "*U254" '("~`*D*" "~`*X*" "~X_*"))
  3. (_wcmatchall "X_123" '("~`*D*" "~`*X*" "~X_*"))
  4. (_wcmatchall "*D45t" '("~`*D*" "~`*X*" "~X_*"))
  5. (_wcmatchall "*X4gh" '("~`*D*" "~`*X*" "~X_*"))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC


Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Wcmatch: another silly question
« Reply #7 on: April 11, 2019, 01:15:45 PM »
Alternatively:
Code - Auto/Visual Lisp: [Select]
  1. (not (wcmatch <blockname> "`*[DX]*,X_*"))

No custom function required.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Wcmatch: another silly question
« Reply #8 on: April 11, 2019, 02:39:26 PM »
Alternatively:
Code - Auto/Visual Lisp: [Select]
  1. (not (wcmatch <blockname> "`*[DX]*,X_*"))

No custom function required.
Grazie  :-)