Author Topic: Find duplicate block on polyline vertices  (Read 1904 times)

0 Members and 1 Guest are viewing this topic.

PM

  • Guest
Find duplicate block on polyline vertices
« on: November 07, 2022, 11:39:51 AM »
Hi i use this code to find duplicate block on polyline vertices. If there no duplicate block in drawing i want to give me an princ  "<< No duplicate block found >>". I add this text but every time i run the code i see it. Something is not correct. Can any one help?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:blockdup ( / ent idx ins lst rtn sel )
  2.    (if (setq sel (ssget "_X" '((0 . "INSERT"))))
  3.        (progn
  4.            (setq rtn (ssadd))
  5.            (repeat (setq idx (sslength sel))
  6.                (setq ent (ssname sel (setq idx (1- idx)))
  7.                      ins (cdr (assoc 10 (entget ent)))
  8.                )
  9.                (if (vl-some '(lambda ( x ) (equal ins x 1e-4)) lst)
  10.                    (ssadd ent rtn)
  11.                    (setq lst (cons ins lst))
  12.                )
  13.            )
  14.                    (princ (strcat "\n" (itoa (sslength rtn)) " found."))
  15.            (sssetfirst nil rtn)
  16.                    (princ "\n<< No duplicate block found >>")) <-- I have problem here
  17.        )
  18.    )
  19.    (princ)
  20. )
  21.  
  22.  

Thanks

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Find duplicate block on polyline vertices
« Reply #1 on: November 07, 2022, 12:38:15 PM »
You need to add some simple IF logic to your prompts. Do you know what sslength returns?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

PM

  • Guest
Re: Find duplicate block on polyline vertices
« Reply #2 on: November 07, 2022, 12:57:59 PM »
Hi  ronjonp. sslength returns the number of duplicated block
« Last Edit: November 07, 2022, 01:05:16 PM by PM »

PM

  • Guest
Re: Find duplicate block on polyline vertices
« Reply #3 on: November 07, 2022, 01:15:33 PM »
I fix it thanks ronjonp

Code - Auto/Visual Lisp: [Select]
  1. (defun c:blockdup ( / ent idx ins lst rtn sel )
  2.    (if (setq sel (ssget "_X" '((0 . "INSERT"))))
  3.        (progn
  4.            (setq rtn (ssadd))
  5.            (repeat (setq idx (sslength sel))
  6.                (setq ent (ssname sel (setq idx (1- idx)))
  7.                      ins (cdr (assoc 10 (entget ent)))
  8.                )
  9.                (if (vl-some '(lambda ( x ) (equal ins x 1e-4)) lst)
  10.                    (ssadd ent rtn)
  11.                    (setq lst (cons ins lst))
  12.                )
  13.            )
  14.                    (princ (strcat "\n" (itoa (sslength rtn)) " found."))
  15.            (sssetfirst nil rtn)
  16.  
  17.         (if (= (sslength rtn) 0)
  18.                  (princ "\n<< No duplicate block found >>")
  19.         )
  20.        )
  21.    )
  22.    (princ)
  23. )
  24.  
  25.  
  26.  

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Find duplicate block on polyline vertices
« Reply #4 on: November 07, 2022, 03:39:34 PM »
I fix it thanks ronjonp

Code - Auto/Visual Lisp: [Select]
  1. (defun c:blockdup ( / ent idx ins lst rtn sel )
  2.    (if (setq sel (ssget "_X" '((0 . "INSERT"))))
  3.        (progn
  4.            (setq rtn (ssadd))
  5.            (repeat (setq idx (sslength sel))
  6.                (setq ent (ssname sel (setq idx (1- idx)))
  7.                      ins (cdr (assoc 10 (entget ent)))
  8.                )
  9.                (if (vl-some '(lambda ( x ) (equal ins x 1e-4)) lst)
  10.                    (ssadd ent rtn)
  11.                    (setq lst (cons ins lst))
  12.                )
  13.            )
  14.                    (princ (strcat "\n" (itoa (sslength rtn)) " found."))
  15.            (sssetfirst nil rtn)
  16.  
  17.         (if (= (sslength rtn) 0)
  18.                  (princ "\n<< No duplicate block found >>")
  19.         )
  20.        )
  21.    )
  22.    (princ)
  23. )
  24.  
Close:
Code - Auto/Visual Lisp: [Select]
  1. (if (= (sslength rtn) 0)
  2.   (princ "\n<< No duplicate block found >>")
  3.   (princ (strcat "\n" (itoa (sslength rtn)) " found."))
  4. )
Which could also be nested like so:
Code - Auto/Visual Lisp: [Select]
  1. (princ (strcat "\n"
  2.                (if (= (sslength rtn) 0)
  3.                  "No duplicate block "
  4.                  (itoa (sslength rtn))
  5.                )
  6.                " found."
  7.        )
  8. )
« Last Edit: November 07, 2022, 03:48:03 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

PM

  • Guest
Re: Find duplicate block on polyline vertices
« Reply #5 on: November 08, 2022, 01:35:58 AM »
Thank you  ronjonp