+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Full Member
    Discipline
    Civil
    Aftertouch's Discipline Details
    Discipline
    Civil
    Details
    Engineer
    Using
    AutoCAD 2017
    Join Date
    Jul 2016
    Location
    Netherlands
    Posts
    61

    Default Build list without duplicates

    Registered forum members do not see this ad.

    Hello all,

    I got a lot of layers that contain numbers. Example below:
    Code:
    B-OI-KL-DATA_KPN_0000546663_VECT_17O000770-G
    B-OI-KL-DATA_KPN_0000546663_VECT_17O000771-G
    B-OI-KL-DATA_KPN_0000546663_VECT_17O000772-G
    B-OI-KL-DATA_LIANDER_0000574962_VECT_17O000770-G
    B-OI-KL-DATA_LIANDER_0000574962_VECT_17O000771-G
    B-OI-KL-DATA_REGGEFIBER_0000579733_VECT_17O000772-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:
    Code:
    		(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:
    Code:
    meldingnr = 17O000770, 17O000771, 17O000772 (can get much longer)
    (princ meldingnr)
    Last edited by Aftertouch; 11th Jan 2017 at 03:20 pm.

  2. #2
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    5,733

    Default

    One way with member function;

    Code:
    (member 170000771 '(170000771 170000772 170000773))

  3. #3
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    751

    Default

    Or vl-position, or just collect everything and use something from LM's unique & duplicate list functions.

  4. #4
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    8,663

    Default

    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.
    A man who never made mistakes never made anything

  5. #5
    Full Member
    Discipline
    Civil
    Aftertouch's Discipline Details
    Discipline
    Civil
    Details
    Engineer
    Using
    AutoCAD 2017
    Join Date
    Jul 2016
    Location
    Netherlands
    Posts
    61

    Default

    I am a bit closer already, i made this:
    Code:
    	(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) 8) 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:
    Code:
    !meldingnrlist = ("17O000770" "17O000771" "17O000772")
    !meldingsoortlst = ("O")
    Now i want the add this as a TEXT in the drawing...

    I tried:
    Code:
    (setq nummer (vl-princ-to-string meldingnrlist))
    (setq soort (vl-princ-to-string meldingsoortlist))
    But then it returns:
    Code:
    (17O000770 17O000771 17O000772)
    (Oriƫntatieverzoek)
    How can i let it look like:
    17O000770, 17O000771, 17O000772 (remove the "(" and ")" and add comma's???)

  6. #6
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    751

    Default

    Hint:
    Code:
    _$ (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":

    Code:
    (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)
    Last edited by Grrr; 12th Jan 2017 at 05:36 pm.

  7. #7
    Full Member
    Discipline
    Civil
    Aftertouch's Discipline Details
    Discipline
    Civil
    Details
    Engineer
    Using
    AutoCAD 2017
    Join Date
    Jul 2016
    Location
    Netherlands
    Posts
    61

    Default

    Thanks all,

    I got it working the way i want.
    The final code: (fragments)

    Code:
    	(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) 8) 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.) :-)

  8. #8
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    751

    Default

    Registered forum members do not see this ad.

    You don't need this:
    Code:
    (setq meldingnrlist (vl-princ-to-string meldingnrlist)) ; make string of the result.
    Because this is already a string:
    Code:
    (setq meldingnrlist (vl-string-right-trim ", " (apply 'strcat (mapcar '(lambda (x) (strcat x ", ")) meldingnrlist)))) ; add comma's an remove last comma

Similar Threads

  1. New Autodesk Memento Oct 2015 Build (Windows version, build 1.5.0.30)
    By Between the Lines in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 4th Nov 2015, 07:30 am
  2. removing duplicates in a list
    By Lt Dan's legs in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 21st Sep 2010, 07:24 pm
  3. Plotting Duplicates, but don't want it to!
    By SplashMan in forum AutoCAD Drawing Management & Output
    Replies: 0
    Last Post: 9th Nov 2009, 04:16 pm
  4. Please help. Erasing duplicates.
    By Jacko93 in forum AutoCAD General
    Replies: 5
    Last Post: 15th May 2009, 02:27 pm
  5. Delete Duplicates
    By CAD-e-Corner in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 7th Dec 2007, 07:41 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts