Author Topic: list manipulation and extraction issue, need help  (Read 2141 times)

0 Members and 1 Guest are viewing this topic.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
list manipulation and extraction issue, need help
« on: September 19, 2008, 01:03:16 PM »
i'm having a little trouble extracting specific layers from a list of layers with information...

if i have a list of layers in this format:

Quote
("P-PAVMT,11,CONTINUOUS" "P-PAVMT-T,11,CONTINUOUS" "P-SEWER,92,PROP SEWER"
"P-SEWER-T,92,CONTINUOUS" "P-BLDG,3,CONTINUOUS" "P-BLDG-T,10,CONTINUOUS"
"P-BLDG-H,9,CONTINUOUS" "P-STORM,172,PROP STORM" "P-STORM-T,172,CONTINUOUS"
"P-MON,6,CONTINUOUS" "P-MON-T,6,CONTINUOUS" "P-CONC,10,CONTINUOUS"
"P-CONC-T,10,CONTINUOUS" "P-CONC-H,9,CONTINUOUS" "P-WALL,2,CONTINUOUS"
"P-WALL-T,10,CONTINUOUS" "P-FENCE,6,PROP FENCE" "P-FENCE-T,6,CONTINUOUS"
"P-WATER,132,PROP WATER MAIN" "P-WATER-T,132,CONTINUOUS" "P-ELEC,242,PROP
OVERHEAD UTILITIES" "P-ELEC-T,242,CONTINUOUS" "P-TELE,242,PROP OT"
"P-TELE-T,242,CONTINUOUS" "P-BNDRY,7,CONTINUOUS" "P-BNDRY-T,3,CONTINUOUS"
"P-TOPO,252,HIDDEN2" "P-TOPO-H,242,HIDDEN2" "P-ELEC_B,242,PROP BE"
"P-ELEC_B-T,242,CONTINUOUS" "P-RW,6,PHANTOM2" "P-RW-T,6,CONTINUOUS"
"P-STRIP,9,CONTINUOUS" "P-STRIP-T,9,CONTINUOUS" "P-MISC,10,CONTINUOUS"
"P-MISC-T,10,CONTINUOUS" "P-POOL,172,CONTINUOUS" "P-POOL-T,172,CONTINUOUS"
"P-DECK,11,CONTINUOUS" "P-DECK-T,11,CONTINUOUS" "P-CANOPY,2,HIDDEN4"
"P-CANOPY-T,10,CONTINUOUS" "P-SIGN,10,CONTINUOUS" "P-SIGN-T,10,CONTINUOUS"
"P-TREES,8,HIDDEN2" "P-RIPRAP,10,CONTINUOUS" "P-RIPRAP-T,10,CONTINUOUS"
"P-FO,242,PROP FIBER OPTIC" "P-FO-T,242,CONTINUOUS" "P-GAS,32,PROP GAS MAIN"
"P-GAP-T,32,CONTINUOUS" "P-LOT,7,CONTINUOUS" "P-CL,2,CENTER2"
"P-ROADNAME,4,CONTINUOUS")

and i'm trying to extract out only the matching layers using a filtering subroutine:

Code: [Select]
  (defun ApplyFilter (wcfilter Lst / result err)
    (if (= wcfilter "*")
      Lst
      (progn
        (foreach bn Lst
          (cond
            ((vl-catch-all-error-p
               (setq matchFlag (vl-catch-all-apply 'wcmatch (list bn wcfilter)))
             )
             (setq err t)
            )
            (matchFlag
             (setq result (cons bn result))
            )
          )
        )
        (reverse result)
      )
    )
  )

why is it that if i (Applyfilter "P-SEWER,*" LIST) it will return ("P-SEWER,92,PROP SEWER" "P-SEWER-T,92,CONTINUOUS")? For some reason, it's ignoring the comma, which would omit a *-T, etc. layer.

any thoughts?
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

T.Willey

  • Needs a day job
  • Posts: 5251
Re: list manipulation and extraction issue, need help
« Reply #1 on: September 19, 2008, 01:17:23 PM »
Quote from: Acad Help files for wcmatch
Wild-card characters
 
Character
 Definition
 
# (pound)
 Matches any single numeric digit.
 
@ (at)
 Matches any single alphabetic character.
 
. (period)
 Matches any single nonalphanumeric character.
 
* (asterisk)
 Matches any character sequence, including an empty one, and it can be used anywhere in the search pattern: at the beginning, middle, or end.
 
? (question mark)
 Matches any single character.
 
~ (tilde)
 If it is the first character in the pattern, it matches anything except the pattern.
 
[...]
 Matches any one of the characters enclosed.
 
[~...]
 Matches any single character not enclosed.
 
– (hyphen)
 Used inside brackets to specify a range for a single character.
 
, (comma)
 Separates two patterns.

 
` (reverse quote)
 Escapes special characters (reads next character literally).
 
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: list manipulation and extraction issue, need help
« Reply #2 on: September 19, 2008, 01:20:04 PM »
Not sure I understand, but try --

(Applyfilter "P-SEWER`,*" thelist)

PS: Don't use LIST as a variable name.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: list manipulation and extraction issue, need help
« Reply #3 on: September 19, 2008, 01:21:16 PM »
What the? I didn't see Tim's response before I posted and didn't get the "someone posted before you" warning.

??

Weird.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

T.Willey

  • Needs a day job
  • Posts: 5251
Re: list manipulation and extraction issue, need help
« Reply #4 on: September 19, 2008, 01:23:50 PM »
What the? I didn't see Tim's response before I posted and didn't get the "someone posted before you" warning.

??

Weird.
And I beat you by ~3 minutes.  I ninja!
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: list manipulation and extraction issue, need help
« Reply #5 on: September 19, 2008, 01:25:56 PM »
lolz!
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: list manipulation and extraction issue, need help
« Reply #6 on: September 19, 2008, 01:37:38 PM »
BEAUTIFUL!!
thank you guys so much!

Quote
PS: Don't use LIST as a variable name.
i didn't/don't, i just typed LIST to represent the list. thanks for the tip though. :)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: list manipulation and extraction issue, need help
« Reply #7 on: September 19, 2008, 07:34:02 PM »
Alan I assume you got the answer  but I'll state it anyway.
Code: [Select]
(Applyfilter "P-SEWER*" TheList) ; get anything that starts with "P-SEWER"
(Applyfilter "~*-T" TheList) ; get anything that does not end with "-T"

Revised code to work with this revised list.
Code: [Select]
  (defun ApplyFilter (wcfilter Lst / result err)
    (if (= wcfilter "*")
      Lst
      (progn
        (foreach bn Lst
          (cond
            ((vl-catch-all-error-p
               (setq matchFlag (vl-catch-all-apply 'wcmatch (list (car bn) wcfilter)))
             )
             (setq err t)
            )
            (matchFlag
             (setq result (cons bn result))
            )
          )
        )
        (reverse result)
      )
    )
  )

(defun c:test (/ thelist)
  (setq thelist
         '(("P-PAVMT" 11 "CONTINUOUS")
           ("P-PAVMT-T" 11 "CONTINUOUS")
           ("P-SEWER" 92 "PROP SEWER")
           ("P-SEWER-T" 92 "CONTINUOUS")
           ("P-BLDG" 3 "CONTINUOUS")
           ("P-BLDG-T" 10 "CONTINUOUS")
           ("P-BLDG-H" 9 "CONTINUOUS")
           ("P-STORM" 172 "PROP STORM")
           ("P-STORM-T" 172 "CONTINUOUS")
           ("P-MON" 6 "CONTINUOUS")
           ("P-MON-T" 6 "CONTINUOUS")
           ("P-CONC" 10 "CONTINUOUS")
           ("P-CONC-T" 10 "CONTINUOUS")
           ("P-CONC-H" 9 "CONTINUOUS")
           ("P-WALL" 2 "CONTINUOUS")
           ("P-WALL-T" 10 "CONTINUOUS")
           ("P-FENCE" 6 "PROP FENCE")
           ("P-FENCE-T" 6 "CONTINUOUS")
           ("P-WATER" 132 "PROP WATER MAIN")
           ("P-WATER-T" 132 "CONTINUOUS")
           ("P-ELEC" 242 "PROP OVERHEAD UTILITIES")
           ("P-ELEC-T" 242 "CONTINUOUS")
           ("P-TELE" 242 "PROP OT")
           ("P-TELE-T" 242 "CONTINUOUS")
           ("P-BNDRY" 7 "CONTINUOUS")
           ("P-BNDRY-T" 3 "CONTINUOUS")
           ("P-TOPO" 252 "HIDDEN2")
           ("P-TOPO-H" 242 "HIDDEN2")
           ("P-ELEC_B" 242 "PROP BE")
           ("P-ELEC_B-T" 242 "CONTINUOUS")
           ("P-RW" 6 "PHANTOM2")
           ("P-RW-T" 6 "CONTINUOUS")
           ("P-STRIP" 9 "CONTINUOUS")
           ("P-STRIP-T" 9 "CONTINUOUS")
           ("P-MISC" 10 "CONTINUOUS")
           ("P-MISC-T" 10 "CONTINUOUS")
           ("P-POOL" 172 "CONTINUOUS")
           ("P-POOL-T" 172 "CONTINUOUS")
           ("P-DECK" 11 "CONTINUOUS")
           ("P-DECK-T" 11 "CONTINUOUS")
           ("P-CANOPY" 2 "HIDDEN4")
           ("P-CANOPY-T" 10 "CONTINUOUS")
           ("P-SIGN" 10 "CONTINUOUS")
           ("P-SIGN-T" 10 "CONTINUOUS")
           ("P-TREES" 8 "HIDDEN2")
           ("P-RIPRAP" 10 "CONTINUOUS")
           ("P-RIPRAP-T" 10 "CONTINUOUS")
           ("P-FO" 242 "PROP FIBER OPTIC")
           ("P-FO-T" 242 "CONTINUOUS")
           ("P-GAS" 32 "PROP GAS MAIN")
           ("P-GAP-T" 32 "CONTINUOUS")
           ("P-LOT" 7 "CONTINUOUS")
           ("P-CL" 2 "CENTER2")
           ("P-ROADNAME" 4 "CONTINUOUS")
          )
  )

  (setq ret (Applyfilter "~*-T" TheList))
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: list manipulation and extraction issue, need help
« Reply #8 on: September 19, 2008, 09:36:49 PM »
very cool, thanks alan. yeah, i got everything working (for now). it also gave me the idea to run a check after to remove all that that do not match the required format.
Code: [Select]
(setq layer_list (ApplyFilter "*`,*`,*" layer_list))i know my questions aren't over, i'm still working on the dcl portion (other post).

thanks guys.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: list manipulation and extraction issue, need help
« Reply #9 on: September 20, 2008, 05:54:04 AM »
this one is more simple
Code: [Select]
(defun ApplyFilter (wcfilter Lst / result err)
  (if (= wcfilter "*")
    Lst
    (vl-remove-if-not
      (function (lambda (e) (wcmatch (car e) wcfilter)))
      Lst
    )
  )
)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: list manipulation and extraction issue, need help
« Reply #10 on: September 20, 2008, 11:13:59 AM »
To me this one is more flexible:

Code: [Select]
(defun _WCMatchList ( lst pattern ignorecase )
    (   (lambda ( foo pattern ) (vl-remove-if-not 'foo lst))
        (if ignorecase
            (lambda (x) (wcmatch (strcase x) pattern))
            (lambda (x) (wcmatch x pattern))
        )   
        (if ignorecase (strcase pattern) pattern)
    )   
)

Given there's no guarantee all the strings are the same case it affords the caller the ability to ignore or honor the case.

Sample data with mixed case strings.

Code: [Select]
(setq lst
   '(
        "P-BLDG,3,CONTINUOUS"
        "P-BLDG-H,9,CONTINUOUS"
        "P-BLDG-T,10,CONTINUOUS"
        "P-BNDRY,7,CONTINUOUS"
        "P-BNDRY-T,3,CONTINUOUS"
        "P-CANOPY,2,HIDDEN4"
        "P-CANOPY-T,10,CONTINUOUS"
        "P-CL,2,CENTER2"
        "P-CONC,10,CONTINUOUS"
        "P-CONC-H,9,CONTINUOUS"
        "P-CONC-T,10,CONTINUOUS"
        "P-DECK,11,CONTINUOUS"
        "P-DECK-T,11,CONTINUOUS"
        "P-ELEC,242,PROPOVERHEAD UTILITIES"
        "P-ELEC-T,242,CONTINUOUS"
        "P-ELEC_B,242,PROP BE"
        "P-ELEC_B-T,242,CONTINUOUS"
        "P-FENCE,6,PROP FENCE"
        "P-FENCE-T,6,CONTINUOUS"
        "P-FO,242,PROP FIBER OPTIC"
        "P-FO-T,242,CONTINUOUS"
        "P-GAP-T,32,CONTINUOUS"
        "P-GAS,32,PROP GAS MAIN"
        "P-LOT,7,CONTINUOUS"
        "P-MISC,10,CONTINUOUS"
        "P-MISC-T,10,CONTINUOUS"
        "P-MON,6,CONTINUOUS"
        "P-MON-T,6,CONTINUOUS"
        "p-pavmt,11,continuous"
        "p-pavmt-t,11,continuous"
        "p-pool,172,continuous"
        "p-pool-t,172,continuous"
        "p-riprap,10,continuous"
        "p-riprap-t,10,continuous"
        "p-roadname,4,continuous"
        "p-rw,6,phantom2"
        "p-rw-t,6,continuous"
        "p-sewer,92,prop sewer"
        "p-sewer-t,92,continuous"
        "p-sign,10,continuous"
        "p-sign-t,10,continuous"
        "p-storm,172,prop storm"
        "p-storm-t,172,continuous"
        "p-strip,9,continuous"
        "p-strip-t,9,continuous"
        "p-tele,242,prop ot"
        "p-tele-t,242,continuous"
        "p-topo,252,hidden2"
        "p-topo-h,242,hidden2"
        "p-trees,8,hidden2"
        "p-wall,2,continuous"
        "p-wall-t,10,continuous"
        "p-water,132,prop water main"
        "p-water-t,132,continuous"
    )
)

Honor the case:

Code: [Select]
(_WCMatchList lst "P-*`,*`,CONTINUOUS" nil)

"P-BLDG,3,CONTINUOUS"
"P-BLDG-H,9,CONTINUOUS"
"P-BLDG-T,10,CONTINUOUS"
"P-BNDRY,7,CONTINUOUS"
"P-BNDRY-T,3,CONTINUOUS"
"P-CANOPY-T,10,CONTINUOUS"
"P-CONC,10,CONTINUOUS"
"P-CONC-H,9,CONTINUOUS"
"P-CONC-T,10,CONTINUOUS"
"P-DECK,11,CONTINUOUS"
"P-DECK-T,11,CONTINUOUS"
"P-ELEC-T,242,CONTINUOUS"
"P-ELEC_B-T,242,CONTINUOUS"
"P-FENCE-T,6,CONTINUOUS"
"P-FO-T,242,CONTINUOUS"
"P-GAP-T,32,CONTINUOUS"
"P-LOT,7,CONTINUOUS"
"P-MISC,10,CONTINUOUS"
"P-MISC-T,10,CONTINUOUS"
"P-MON,6,CONTINUOUS"
"P-MON-T,6,CONTINUOUS"

(_WCMatchList lst "p-*`,*`,continuous" nil)

"p-pavmt,11,continuous"
"p-pavmt-t,11,continuous"
"p-pool,172,continuous"
"p-pool-t,172,continuous"
"p-riprap,10,continuous"
"p-riprap-t,10,continuous"
"p-roadname,4,continuous"
"p-rw-t,6,continuous"
"p-sewer-t,92,continuous"
"p-sign,10,continuous"
"p-sign-t,10,continuous"
"p-storm-t,172,continuous"
"p-strip,9,continuous"
"p-strip-t,9,continuous"
"p-tele-t,242,continuous"
"p-wall,2,continuous"
"p-wall-t,10,continuous"
"p-water-t,132,continuous"

Ignore the case.

Code: [Select]
(_WCMatchList lst "p-*`,*`,continuous" t)

"P-BLDG,3,CONTINUOUS"
"P-BLDG-H,9,CONTINUOUS"
"P-BLDG-T,10,CONTINUOUS"
"P-BNDRY,7,CONTINUOUS"
"P-BNDRY-T,3,CONTINUOUS"
"P-CANOPY-T,10,CONTINUOUS"
"P-CONC,10,CONTINUOUS"
"P-CONC-H,9,CONTINUOUS"
"P-CONC-T,10,CONTINUOUS"
"P-DECK,11,CONTINUOUS"
"P-DECK-T,11,CONTINUOUS"
"P-ELEC-T,242,CONTINUOUS"
"P-ELEC_B-T,242,CONTINUOUS"
"P-FENCE-T,6,CONTINUOUS"
"P-FO-T,242,CONTINUOUS"
"P-GAP-T,32,CONTINUOUS"
"P-LOT,7,CONTINUOUS"
"P-MISC,10,CONTINUOUS"
"P-MISC-T,10,CONTINUOUS"
"P-MON,6,CONTINUOUS"
"P-MON-T,6,CONTINUOUS"
"p-pavmt,11,continuous"
"p-pavmt-t,11,continuous"
"p-pool,172,continuous"
"p-pool-t,172,continuous"
"p-riprap,10,continuous"
"p-riprap-t,10,continuous"
"p-roadname,4,continuous"
"p-rw-t,6,continuous"
"p-sewer-t,92,continuous"
"p-sign,10,continuous"
"p-sign-t,10,continuous"
"p-storm-t,172,continuous"
"p-strip,9,continuous"
"p-strip-t,9,continuous"
"p-tele-t,242,continuous"
"p-wall,2,continuous"
"p-wall-t,10,continuous"
"p-water-t,132,continuous"

Mileages vary, this is mine.

Cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: list manipulation and extraction issue, need help
« Reply #11 on: September 20, 2008, 08:47:59 PM »
very nice mike, i didn't even think about case considerations.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox