Author Topic: Overkill in Block  (Read 2183 times)

0 Members and 1 Guest are viewing this topic.

miquan

  • Guest
Overkill in Block
« on: May 22, 2014, 10:07:36 PM »
Dear all,

I try to overkill duplicated lines in all blocks in drawing.

I used this Lee's lisp, but now it's not working for this block, please help me to fix.

Autolisp code:
Code: [Select]
;;http://www.cadtutor.net/forum/showthread.php?48469-Overkill-all-including-blocks&s=d39932f12a90fe5c87c3c8528193bf09
;; Line Kill  -  Lee Mac
;; Removes duplicate or zero-length lines from the drawing and
;; also from within blocks and nested blocks.

(defun c:LKILL ( / dup lck lst p1 p2 tol zln )
   
    (setq tol 1e-8  ;; Tolerance
          zln 0
          dup 0
    )
    (vlax-for lay (vla-get-layers (LM:acdoc))
        (if (= :vlax-true (vla-get-lock lay))
            (progn
                (setq lck (cons lay lck))
                (vla-put-lock lay :vlax-false)
            )
        )
    )
    (vlax-for blk (vla-get-blocks (LM:acdoc))
        (if (= :vlax-false (vla-get-isxref blk))
            (vlax-for obj blk
                (cond
                    (   (/= "AcDbLine" (vla-get-objectname obj)))
                    (   (equal 0.0
                            (distance
                                (setq p1 (vlax-get obj 'startpoint))
                                (setq p2 (vlax-get obj 'endpoint))
                            )
                            tol
                        )
                        (setq zln (1+ zln))
                        (vla-delete obj)
                    )
                    (   (vl-some
                            (function
                                (lambda ( x )
                                    (and (equal (car x) p1 tol) (equal (cadr x) p2 tol))
                                )
                            )
                            lst
                        )
                        (setq dup (1+ dup))
                        (vla-delete obj)
                    )
                    (   (setq lst (cons (list p1 p2) lst)))
                )
            )
        )
        (setq lst nil)
    )
    (foreach layer lck
        (vla-put-lock layer :vlax-true)
    )
    (vla-regen (LM:acdoc) acallviewports)
    (if (< 0 zln)
        (princ (strcat "\n" (itoa zln) " zero-length line" (if (= 1 zln) " removed." "s removed.")))
        (princ (strcat "\nNo zero-length lines found."))
    )
    (if (< 0 dup)
        (princ (strcat "\n" (itoa dup) " duplicate line" (if (= 1 dup) " removed." "s removed.")))
        (princ (strcat "\nNo duplicate lines found."))
    )
    (princ)
)

;; Active Document  -  Lee Mac
;; Returns the VLA Active Document Object

(defun LM:acdoc nil
    (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
    (LM:acdoc)
)
(vl-load-com)
(princ)


My block (see attached file)

Thanks,
Miquan

hanhphuc

  • Newt
  • Posts: 64
Re: Overkill in Block
« Reply #1 on: May 23, 2014, 02:16:20 AM »
ni hao.. the lines not duplicate, but just 2 short lines overlapped on a longer line.
Alternatively, U can use Express Tools command: OVERKILL, there is an option to remove overlap objects. thx
( apply 'equal "hp" "happy" "hạnh phúc" "ハッピー" "幸福" "행복" ) ; error: too many arguments

miquan

  • Guest
Re: Overkill in Block
« Reply #2 on: May 23, 2014, 02:19:12 AM »
Dear,

Overkill is not working for block.

Thanks,
Miquan

ChrisCarlson

  • Guest
Re: Overkill in Block
« Reply #3 on: May 23, 2014, 11:27:43 AM »
There's a grand total of 3 lines...why not just delete the one line which overlaps?

miquan

  • Guest
Re: Overkill in Block
« Reply #4 on: May 23, 2014, 10:18:56 PM »
Hi
If there are some blocks,you can do it manually.
But I have about 500 blocks with different name.
Miquan





snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Overkill in Block
« Reply #5 on: May 24, 2014, 11:43:35 AM »
As Lee points out, his program deletes duplicate lines, end points must be exactly the same.  The drawing you supplied has three lines all with different endpoints, although one line is on top of another it is not a duplicate. 

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Overkill in Block
« Reply #6 on: May 26, 2014, 01:31:47 PM »
This is only quickly put together but should perform as required:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:linekill ( / cnt doc lst )
  2.           cnt 0
  3.     )
  4.  
  5.     ;; Retrieve all lines & line endpoints
  6.     (vlax-for blk (vla-get-blocks doc)
  7.         (if (= :vlax-false (vla-get-isxref blk))
  8.             (vlax-for obj blk
  9.                 (if (= "AcDbLine" (vla-get-objectname obj))
  10.                     (setq lst (cons (list obj (vlax-get obj 'startpoint) (vlax-get obj 'endpoint)) lst))
  11.                 )
  12.             )
  13.         )
  14.     )
  15.    
  16.     ;; Bigger lines cannot be inside smaller lines
  17.     (setq lst
  18.         (vl-sort lst
  19.            '(lambda ( a b )
  20.                 (<  (distance (cadr a) (caddr a))
  21.                     (distance (cadr b) (caddr b))
  22.                 )
  23.             )
  24.         )
  25.     )
  26.  
  27.     ;; Delete overlapping lines
  28.     (foreach x lst
  29.         (if
  30.             (and
  31.                 (vl-some
  32.                    '(lambda ( y ) (apply 'inline (append (cdr x) (cdr y))))
  33.                     (setq lst (cdr lst))
  34.                 )
  35.                 (vlax-write-enabled-p (car x))
  36.                 (setq cnt (1+ cnt))
  37.             )
  38.             (vla-delete (car x))
  39.         )
  40.     )
  41.  
  42.     ;; Regenerate drawing
  43.     (vla-regen doc acallviewports)
  44.     (if (< 0 cnt)
  45.         (princ (strcat "\n" (itoa cnt) " overlapping line" (if (= 1 cnt) "" "s") " deleted."))
  46.         (princ "\nNo overlapping lines found.")
  47.     )
  48.     (princ)
  49. )
  50.  
  51. (defun inline ( a b c d )
  52.     (equal
  53.         (+ (distance a c) (distance a b) (distance b d))
  54.         (distance c d)
  55.         1e-8
  56.     )
  57. )

miquan

  • Guest
Re: Overkill in Block
« Reply #7 on: May 26, 2014, 07:26:15 PM »
Dear Lee,

Thanks so much for your kindly help.

Miquan

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Overkill in Block
« Reply #8 on: May 27, 2014, 01:09:53 PM »
You're welcome Miquan  :-)