Aftertouch Posted January 11, 2017 Share Posted January 11, 2017 (edited) Hello all, I got a lot of layers that contain numbers. Example below: B-OI-KL-DATA_KPN_0000546663_VECT_[color="red"]17O000770[/color]-G B-OI-KL-DATA_KPN_0000546663_VECT_[color="red"]17O000771[/color]-G B-OI-KL-DATA_KPN_0000546663_VECT_[color="red"]17O000772[/color]-G B-OI-KL-DATA_LIANDER_0000574962_VECT_[color="red"]17O000770[/color]-G B-OI-KL-DATA_LIANDER_0000574962_VECT_[color="red"]17O000771[/color]-G B-OI-KL-DATA_REGGEFIBER_0000579733_VECT_[color="red"]17O000772[/color]-G The numbers can be completely random, not pre-set. the total list can be up to 100 layers long. I can filter the number using: (vlax-for obj (vla-get-layers doc) (setq lay (vla-get-name obj)) (setq meldingnr "none") (setq meldingsoort "none") (if (wcmatch (strcase lay) "B-OI-*") (progn (cond ((= meldingnr "none") (setq meldingnr (strcat (substr lay (-(strlen lay) 10) 9 ))) ; get number from layer. ) ) <do more stuff with all layers> ) ) This evaluates all layers and does something with it. How can i make a check, that if it gets a number that is not 'meldingnr' it adds it to the 'meldingnr' I am looking for a result that looks like: meldingnr = 17O000770, 17O000771, 17O000772 (can get much longer) (princ meldingnr) Edited January 11, 2017 by Aftertouch Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 11, 2017 Share Posted January 11, 2017 One way with member function; (member 170000771 '(170000771 170000772 170000773)) Quote Link to comment Share on other sites More sharing options...
Grrr Posted January 11, 2017 Share Posted January 11, 2017 Or vl-position, or just collect everything and use something from LM's unique & duplicate list functions. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 12, 2017 Share Posted January 12, 2017 Not sure if this is what you want but there was a post here about missing number 1 3 4 5 "2" is missing. Sorry no idea what its heading was. Quote Link to comment Share on other sites More sharing options...
Aftertouch Posted January 12, 2017 Author Share Posted January 12, 2017 I am a bit closer already, i made this: (setq meldingnrlist '()) (setq meldingsoortlist '()) (setvar "CMDECHO" 0) (vlax-for obj (vla-get-layers doc) (setq lay (vla-get-name obj)) (if (wcmatch (strcase lay) "B-OI-*") (progn (setq meldingnr (strcat (substr lay (-(strlen lay) 10) 9 ))) (if(=(member meldingnr meldingnrlist) nil) (progn (setq meldingnrlist (cons meldingnr meldingnrlist)) ) ) (setq meldingsoort (strcat (substr lay (-(strlen lay) 1 ))) (if(= meldingsoort "O") (progn (setq meldingsoort "Oriëntatieverzoek") ) (progn (setq meldingsoort "Graafmelding") ) ) (if(=(member meldingsoort meldingsoortlist) nil) (progn (setq meldingsoortlist (cons meldingsoort meldingsoortlist)) ) ) now i managed to get this: !meldingnrlist = ("17O000770" "17O000771" "17O000772") !meldingsoortlst = ("O") Now i want the add this as a TEXT in the drawing... I tried: (setq nummer (vl-princ-to-string meldingnrlist)) (setq soort (vl-princ-to-string meldingsoortlist)) But then it returns: (17O000770 17O000771 17O000772) (Oriëntatieverzoek) How can i let it look like: 17O000770, 17O000771, 17O000772 (remove the "(" and ")" and add comma's???) Quote Link to comment Share on other sites More sharing options...
Grrr Posted January 12, 2017 Share Posted January 12, 2017 (edited) Hint: _$ (mapcar '(lambda (x) (strcat x ",")) '("17O000770" "17O000771" "17O000772")) ("17O000770," "17O000771," "17O000772,") _$ (apply 'strcat (mapcar '(lambda (x) (strcat x ",")) '("17O000770" "17O000771" "17O000772"))) "17O000770,17O000771,17O000772," _$ (vl-string-right-trim "," (apply 'strcat (mapcar '(lambda (x) (strcat x ",")) '("17O000770" "17O000771" "17O000772")))) "17O000770,17O000771,17O000772" _$ BTW, Heres an example how to obtain that "meldingnrlist": (defun GetMeldingnrlist ( / LM:str->lst LayerDef Layers meldingnrlist ) ;; String to List - Lee Mac ;; Separates a string using a given delimiter ;; str - [str] String to process ;; del - [str] Delimiter by which to separate the string ;; Returns: [lst] List of strings (defun LM:str->lst ( str del / pos ) (if (setq pos (vl-string-search del str)) (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del)) (list str) ) ) (while (setq LayerDef (tblnext "LAYER" (not LayerDef))) (setq Layers (cons (cdr (assoc 2 LayerDef)) Layers)) ) (if (setq Layers (vl-remove-if-not '(lambda (x) (wcmatch x "B`-OI`-KL`-DATA_*_*_*_*`-G")) Layers)) (setq meldingnrlist (vl-string-right-trim "," (apply 'strcat (mapcar '(lambda (x) (strcat (vl-string-right-trim "-G" (last (LM:str->lst x "_"))) ",")) Layers ) ) ) ) ) ) (GetMeldingnrlist) Edited January 12, 2017 by Grrr Quote Link to comment Share on other sites More sharing options...
Aftertouch Posted January 13, 2017 Author Share Posted January 13, 2017 Thanks all, I got it working the way i want. The final code: (fragments) (setq meldingnrlist '()) ;Empty list (setq meldingsoortlist '()) ; empty list (if (wcmatch (strcase lay) "B-OI-*") ; check for layer name starting with... (progn (setq meldingnr (strcat (substr lay (-(strlen lay) 10) 9 ))) ; get the meldingnr. (if(=(member meldingnr meldingnrlist) nil); if the number is not in the list.. (progn (setq meldingnrlist (cons meldingnr meldingnrlist)); add it to the list... (setq meldingsoort (strcat (substr lay (-(strlen lay) 1 ))) ; add other info of that layer to other list. (if(= meldingsoort "O") ; change some names (progn (setq meldingsoort "Oriëntatieverzoek") ) (progn (setq meldingsoort "Graafmelding") ) ) (setq meldingsoortlist (cons meldingsoort meldingsoortlist)) ) ) (setq meldingnrlist (vl-string-right-trim ", " (apply 'strcat (mapcar '(lambda (x) (strcat x ", ")) meldingnrlist)))) ; add comma's an remove last comma (setq meldingnrlist (vl-princ-to-string meldingnrlist)) ; make string of the result. (Result is one string with all elements of the lisp, seperated with a comma.) :-) Quote Link to comment Share on other sites More sharing options...
Grrr Posted January 13, 2017 Share Posted January 13, 2017 You don't need this: (setq meldingnrlist (vl-princ-to-string meldingnrlist)) ; make string of the result. Because this is already a string: (setq meldingnrlist (vl-string-right-trim ", " (apply 'strcat (mapcar '(lambda (x) (strcat x ", ")) meldingnrlist)))) ; add comma's an remove last comma Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.