+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
  1. #1
    Junior Member
    Using
    AutoCAD 2000
    Join Date
    Dec 2011
    Posts
    10

    Default filtering out identical plines from a list

    Registered forum members do not see this ad.

    I'm trying to filter out plines that are duplicates of each other from a list. I've been trying to compare 1 point in the first pline against the list of points from the other plines. They will only share a point if they are identical for this use. I've been trying to work this out on my own but it has becaome a complete mess and I know there must be a simpler way. This code works but has no way of checking the last pline.
    comparepts is a list of lists of the points on the plines
    nubpaths is a list of the pline entity names
    Help if you can please.


    Code:
    (setq compctr1 0
            ctr 
    0
            numnubs (length 
    nubpaths)
            nlist (list)
      
    )
    
     
      (while (< compctr1 (- numnubs 1))
        (setq 
    compctr2 (+ compctr1 1))
        (while (and (< compctr2 
    numnubs) (not reject))
          (setq complngth (length 
    (nth compctr2 comparepts)))
          (setq compctr3 
    0)
            (while (and (< compctr3 
    complngth) (not (equal (car (nth compctr1 comparepts)) (nth compctr3 (nth 
    compctr2 comparepts)) 
    0.00009)))
              (setq 
    compctr3 (+ compctr3 1))
            ) ;_ end 
    of while
            (if (/= compctr3 
    complngth) 
    
                (setq 
    reject T)
              
    
            ) ;_ end of 
    if
        
        (setq compctr2 (+ compctr2 
    1))
      
        (if (= compctr2 numnubs)  
    
           (setq nlist (append nlist (list (nth 
    compctr1 nubpaths))))
        )
          
    
        ) ;_ end of while
        
    
        (setq compctr1 (+ compctr1 
    1)
              reject 
    nil
        )
      ) ;_ end of while

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,708

    Default

    You will find people are more willing to help if you responded to the time they have donated to you.
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  3. #3
    Junior Member
    Using
    AutoCAD 2000
    Join Date
    Dec 2011
    Posts
    10

    Default

    Quote Originally Posted by Lee Mac View Post
    You will find people are more willing to help if you responded to the time they have donated to you.

    Apologies Lee. I never actually saw your reply. I think I dug the answer up somewhere else on the internet. I wish I had. It would have been very helpful. I got so caught up in trying to learn and make my code work that I moved on and forgot to look back. I have been helped by you many times though from reading your posts to others questions. Thank you for taking the time to help those of us that are still learning.

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,708

    Default

    Here is some quickly written code for you to play with:

    Code:
    (defun c:test ( / ent inc itm1 lst sel tmp vrt )
    
        ;; Get selection of LWPolylines for testing
    
        (if (setq sel (ssget '((0 . "LWPOLYLINE"))))
            (progn
    
                ;; Collect a list of vertices for each LWPolyline
    
                (repeat (setq inc (sslength sel))                
                    (setq ent (ssname sel (setq inc (1- inc)))
                          vrt nil
                    )
                    (foreach pair (entget ent)
                        (if (= 10 (car pair))
                            (setq vrt (cons (cdr pair) vrt))
                        )
                    )
                    (setq lst (cons (list vrt ent) lst))
                )
    
                ;; Iterate over 'lst', check for dupes
    
                (while (setq itm1 (car lst))
                    (setq
                        tmp (cdr lst)
                        lst nil
                    )
                    (foreach itm2 tmp
    
                        ;; If vertex list is identical
                        
                        (if (equal (car itm1) (car itm2))
    
                            ;; Remove from set
                            
                            (ssdel (cadr itm2) sel)
    
                            ;; Otherwise retain for further testing
                            
                            (setq lst (cons itm2 lst))
                        )
                    )
                )
    
                ;; Highlight unique set
    
                (sssetfirst nil sel)
            )
        )
        (princ)
    )
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  5. #5
    Junior Member
    Using
    AutoCAD 2000
    Join Date
    Dec 2011
    Posts
    10

    Default

    Thanks Lee. The code looks good. I called the plines identical but the vertices may not be in the exact same order. They were created with bpoly. Will this still work if the vertices are in different order.

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,708

    Default

    Quote Originally Posted by jeremyearle5 View Post
    Thanks Lee. The code looks good. I called the plines identical but the vertices may not be in the exact same order. They were created with bpoly. Will this still work if the vertices are in different order.
    You're welcome.

    The above code is checking for identical LWPolylines - i.e. all vertices are the same and in the same order (though, bulge factor is not checked). For your case it may be sufficient to test whether every vertex of the test item appears in the vertex list of the second item.
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  7. #7
    Senior Member marko_ribar's Avatar
    Computer Details
    marko_ribar's Computer Details
    Operating System:
    Windows 7 Ultimate X64
    Computer:
    Intel quad core CPU 4x2.66GHz, 8GB RAM
    Motherboard:
    INTEL compatibile
    CPU:
    quad core 4x2.66GHz
    RAM:
    8GB
    Graphics:
    NVIDIA GeForce 6600 GT
    Primary Storage:
    250 GB
    Secondary Storage:
    500 GB
    Monitor:
    Samsung 17''
    Discipline
    Architectural
    marko_ribar's Discipline Details
    Occupation
    Architecture, project designer, project visualisation
    Discipline
    Architectural
    Details
    space design - modeling and animations
    Using
    AutoCAD 2012
    Join Date
    Feb 2010
    Location
    Belgrade, Serbia, Europe
    Posts
    327

    Default

    If you want to select identical entities (can be applied to any entity not only polyline), I've created this code, although entities aren't exactly identical, but they main properties are... They are clones made after commands like copy, mirror, array...

    Code:
    (defun c:selectidentical ( / ENTA N PROP1 PROP2 PROP3 PROP4 PROPLST REFENTA RPROP1 RPROP2 RPROP3 RPROP4 RPROPLST SS SSNEW ) (vl-load-com)
      (setq entA (vlax-ename->vla-object (car (entsel "\nPick reference entity"))))
      (setq prop1 (if (vlax-property-available-p entA 'Length) (vla-get-Length entA)))
      (setq prop2 (if (vlax-property-available-p entA 'Area) (vla-get-Area entA)))
      (setq prop3 (if (vlax-property-available-p entA 'Volume) (vla-get-Volume entA)))
      (setq prop4 (if (vlax-property-available-p entA 'PrincipalMoments) (vla-get-PrincipalMoments entA)))
      (if prop4 (setq prop4 (vlax-safearray->list (vlax-variant-value prop4))))
      (setq proplst (list prop1 prop2 prop3))
      (setq ssnew (ssadd))
      (setq ss (ssget "_X"))
      (repeat (setq n (sslength ss))
        (setq refentA (vlax-ename->vla-object (ssname ss (setq n (1- n)))))
        (setq rprop1 (if (vlax-property-available-p refentA 'Length) (vla-get-Length refentA)))
        (setq rprop2 (if (vlax-property-available-p refentA 'Area) (vla-get-Area refentA)))
        (setq rprop3 (if (vlax-property-available-p refentA 'Volume) (vla-get-Volume refentA)))
        (setq rprop4 (if (vlax-property-available-p refentA 'PrincipalMoments) (vla-get-PrincipalMoments refentA)))
        (if rprop4 (setq rprop4 (vlax-safearray->list (vlax-variant-value rprop4))))
        (setq rproplst (list rprop1 rprop2 rprop3))
        (if (and (equal proplst rproplst 1e-8) (equal prop4 rprop4 1e-3)) (ssadd (vlax-vla-object->ename refentA) ssnew))
      )
      (sssetfirst nil ssnew)
      (alert (strcat "\nTotal : " (itoa (sslength ssnew)) " identical entity(ies)"))
      (princ)
    )
    I've found this code very useful in process of working in ACAD...
    M.R.

    Marko Ribar, d.i.a. (graduated engineer of architecture)
    M.R. on YouTube

  8. #8
    Forum Deity BlackBox's Avatar
    Using
    Civil 3D 2011
    Join Date
    Nov 2009
    Posts
    3,932

    Default

    Hope they don't miss.
    "Potential has a shelf life." - Margaret Atwood

  9. #9
    Forum Deity Dadgad's Avatar
    Using
    AutoCAD 2012
    Join Date
    Nov 2011
    Location
    At the confluence of worthlessness & invaluability
    Posts
    3,131

    Default

    I would suggest the use of OVERKILL, to those who have it as a very good pre-emptive way to root out redundancy while still in your drawing, always nice to tidy up before saving.
    Last edited by Dadgad; 7th Apr 2012 at 04:04 am.
    Volume and repetition do not validate opinions forged in the absence of thought.

  10. #10
    Forum Deity BlackBox's Avatar
    Using
    Civil 3D 2011
    Join Date
    Nov 2009
    Posts
    3,932

    Default

    Registered forum members do not see this ad.

    Forgive my asking, but what does my post have to do with that suggestion? I was commenting on the potential for (vlax-ename->vla-object nil).
    "Potential has a shelf life." - Margaret Atwood

Similar Threads

  1. Select identical objects
    By ServaCleanCAD in forum AutoCAD General
    Replies: 1
    Last Post: 22nd Feb 2010, 11:03 am
  2. Why the two identical layout tabs in paperspace?
    By joffy in forum AutoCAD Beginners' Area
    Replies: 2
    Last Post: 19th Feb 2009, 02:53 am
  3. Identical symbol in Dimn text
    By toolroom in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 5th Mar 2008, 10:37 am
  4. Identical symbol in Dimn text
    By toolroom in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 5th Mar 2008, 10:33 am
  5. Layer filtering
    By Meatarian in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 10th Feb 2005, 02:22 am

Tags for this Thread

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