TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: alanjt 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:
("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:
(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?
-
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).
-
Not sure I understand, but try --
(Applyfilter "P-SEWER`,*" thelist)
PS: Don't use LIST as a variable name.
-
What the? I didn't see Tim's response before I posted and didn't get the "someone posted before you" warning.
??
Weird.
-
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!
-
lolz!
-
BEAUTIFUL!!
thank you guys so much!
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. :)
-
Alan I assume you got the answer but I'll state it anyway.
(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.
(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)
)
-
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.
(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.
-
this one is more simple
(defun ApplyFilter (wcfilter Lst / result err)
(if (= wcfilter "*")
Lst
(vl-remove-if-not
(function (lambda (e) (wcmatch (car e) wcfilter)))
Lst
)
)
)
-
To me this one is more flexible:
(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.
(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:
(_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.
(_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.
-
very nice mike, i didn't even think about case considerations.