Author Topic: duplicated hatch area delete way  (Read 2530 times)

0 Members and 1 Guest are viewing this topic.

dussla

  • Bull Frog
  • Posts: 297
duplicated hatch area delete way
« on: April 04, 2018, 10:40:10 AM »
sorry freinds ~ i need  help again   
sorry many ask ~ forgive me

there is  very  big hatch area
attached  image is very simple example

there is overlapping hatch (=duplicate hatch)

i would like to  delete all  duplicate area

no overkill  ~~
both delete way
can you understand my attached image ~



dussla

  • Bull Frog
  • Posts: 297
Re: duplicated hatch area delete way
« Reply #1 on: April 04, 2018, 10:41:23 AM »
sorry freinds ~ i need  help again   
sorry many ask ~ forgive me

there is  very  big hatch area
attached  image is very simple example

there is overlapping hatch (=duplicate hatch)

i would like to  delete all  duplicate area

no overkill  ~~
both delete way
can you understand my attached image ~


dwg file

ribarm

  • Gator
  • Posts: 3297
  • Marko Ribar, architect
Re: duplicated hatch area delete way
« Reply #2 on: April 04, 2018, 11:36:42 AM »
What if green hatch only partially cover underneath hatches, delete them anyway - both green and one under?
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3297
  • Marko Ribar, architect
Re: duplicated hatch area delete way
« Reply #3 on: April 04, 2018, 12:23:46 PM »
Here you go...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:deleteoverlappedhatches ( / adoc ss n i ha bl k dx p pl hl )
  2.  
  3.  
  4.   (vla-endundomark adoc)
  5.   (setq ss (ssget "_:L" '((0 . "HATCH") (2 . "SOLID"))))
  6.   (if ss
  7.     (progn
  8.       (initget 7)
  9.       (setq n (getint "\nNumber of iterations - checks from outside to inner area : "))
  10.       (repeat (setq i (sslength ss))
  11.         (setq ha (ssname ss (setq i (1- i))))
  12.         (vl-cmdf "_.-HATCHEDIT" ha "_B" "_P" "_N")
  13.         (setq bl (cons (list (entlast) ha) bl))
  14.       )
  15.       (repeat n
  16.         (foreach b bl
  17.           (if (not (vlax-erased-p (car b)))
  18.             (progn
  19.               (setq k -1)
  20.               (setq dx (/ (vlax-curve-getdistatparam (car b) (vlax-curve-getendparam (car b))) 100.))
  21.               (repeat 100
  22.                 (setq p (vlax-curve-getpointatdist (car b) (* dx (setq k (1+ k)))))
  23.                 (setq pl (cons p pl))
  24.               )
  25.               (if (vl-some '(lambda ( x ) (= (sslength (ssget "_C" x x)) 2)) pl)
  26.                 (setq hl (cons b hl))
  27.               )
  28.               (setq pl nil)
  29.             )
  30.           )
  31.         )
  32.         (foreach e (apply 'append hl)
  33.           (entdel e)
  34.         )
  35.         (setq hl nil)
  36.       )
  37.       (foreach b bl
  38.         (entdel (cadr b))
  39.       )
  40.       (foreach b (mapcar 'car bl)
  41.         (if (not (vlax-erased-p b))
  42.           (entdel b)
  43.         )
  44.       )
  45.     )
  46.   )
  47.   (vla-regen adoc acactiveviewport)
  48.   (vla-endundomark adoc)
  49.   (princ)
  50. )
  51.  

HTH., M.R.
« Last Edit: April 05, 2018, 04:37:36 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ronjonp

  • Needs a day job
  • Posts: 7531
Re: duplicated hatch area delete way
« Reply #4 on: April 04, 2018, 05:50:46 PM »
Here's another way ( based off of example drawing )
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ _apl f e s)
  2.   ;; RJP - 04-04-2018
  3.   ;; Deletes overlapping hatches with common centroids
  4.   (defun _apl (l) (mapcar '(lambda (x) (/ x (length l))) (apply 'mapcar (cons '+ l))))
  5.   ;; Fuzz value '20000' below set from drawing example .. may need to adjust for different scenarios
  6.   (setq f 20000.)
  7.   (cond ((setq s (ssget ":L" '((0 . "hatch"))))
  8.          (setq s
  9.                 (mapcar
  10.                   '(lambda (x)
  11.                      (list x
  12.                            (_apl (mapcar 'cdr
  13.                                          (vl-remove-if
  14.                                            '(lambda (d) (or (equal '(0.0 0.0 0.0) (cdr d)) (/= 10 (car d))))
  15.                                            (entget x)
  16.                                          )
  17.                                  )
  18.                            )
  19.                      )
  20.                    )
  21.                   (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
  22.                 )
  23.          )
  24.          (while (setq e (car s))
  25.            (setq s (cdr s))
  26.            (if (setq tmp (vl-remove-if-not '(lambda (x) (equal (cadr e) (cadr x) f)) s))
  27.              (progn (mapcar 'entdel (mapcar 'car tmp))
  28.                     (entdel (car e))
  29.                     (mapcar '(lambda (x) (grdraw (cadr e) (cadr x) 3) (setq s (vl-remove x s))) tmp)
  30.              )
  31.            )
  32.          )
  33.         )
  34.   )
  35.   (princ)
  36. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

dussla

  • Bull Frog
  • Posts: 297
Re: duplicated hatch area delete way
« Reply #5 on: April 04, 2018, 07:10:10 PM »
Here's another way ( based off of example drawing )
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ _apl f e s)
  2.   ;; RJP - 04-04-2018
  3.   ;; Deletes overlapping hatches with common centroids
  4.   (defun _apl (l) (mapcar '(lambda (x) (/ x (length l))) (apply 'mapcar (cons '+ l))))
  5.   ;; Fuzz value '20000' below set from drawing example .. may need to adjust for different scenarios
  6.   (setq f 20000.)
  7.   (cond ((setq s (ssget ":L" '((0 . "hatch"))))
  8.          (setq s
  9.                 (mapcar
  10.                   '(lambda (x)
  11.                      (list x
  12.                            (_apl (mapcar 'cdr
  13.                                          (vl-remove-if
  14.                                            '(lambda (d) (or (equal '(0.0 0.0 0.0) (cdr d)) (/= 10 (car d))))
  15.                                            (entget x)
  16.                                          )
  17.                                  )
  18.                            )
  19.                      )
  20.                    )
  21.                   (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
  22.                 )
  23.          )
  24.          (while (setq e (car s))
  25.            (setq s (cdr s))
  26.            (if (setq tmp (vl-remove-if-not '(lambda (x) (equal (cadr e) (cadr x) f)) s))
  27.              (progn (mapcar 'entdel (mapcar 'car tmp))
  28.                     (entdel (car e))
  29.                     (mapcar '(lambda (x) (grdraw (cadr e) (cadr x) 3) (setq s (vl-remove x s))) tmp)
  30.              )
  31.            )
  32.          )
  33.         )
  34.   )
  35.   (princ)
  36. )


good
i test this file
but that is not work ~~

dussla

  • Bull Frog
  • Posts: 297
Re: duplicated hatch area delete way
« Reply #6 on: April 04, 2018, 07:11:36 PM »
Here's another way ( based off of example drawing )
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ _apl f e s)
  2.   ;; RJP - 04-04-2018
  3.   ;; Deletes overlapping hatches with common centroids
  4.   (defun _apl (l) (mapcar '(lambda (x) (/ x (length l))) (apply 'mapcar (cons '+ l))))
  5.   ;; Fuzz value '20000' below set from drawing example .. may need to adjust for different scenarios
  6.   (setq f 20000.)
  7.   (cond ((setq s (ssget ":L" '((0 . "hatch"))))
  8.          (setq s
  9.                 (mapcar
  10.                   '(lambda (x)
  11.                      (list x
  12.                            (_apl (mapcar 'cdr
  13.                                          (vl-remove-if
  14.                                            '(lambda (d) (or (equal '(0.0 0.0 0.0) (cdr d)) (/= 10 (car d))))
  15.                                            (entget x)
  16.                                          )
  17.                                  )
  18.                            )
  19.                      )
  20.                    )
  21.                   (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
  22.                 )
  23.          )
  24.          (while (setq e (car s))
  25.            (setq s (cdr s))
  26.            (if (setq tmp (vl-remove-if-not '(lambda (x) (equal (cadr e) (cadr x) f)) s))
  27.              (progn (mapcar 'entdel (mapcar 'car tmp))
  28.                     (entdel (car e))
  29.                     (mapcar '(lambda (x) (grdraw (cadr e) (cadr x) 3) (setq s (vl-remove x s))) tmp)
  30.              )
  31.            )
  32.          )
  33.         )
  34.   )
  35.   (princ)
  36. )


good
i test this file
but that is not work ~~

dwg file

ronjonp

  • Needs a day job
  • Posts: 7531
Re: duplicated hatch area delete way
« Reply #7 on: April 04, 2018, 08:22:29 PM »
Here's another way ( based off of example drawing )
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ _apl f e s)
  2.   ;; RJP - 04-04-2018
  3.   ;; Deletes overlapping hatches with common centroids
  4.   (defun _apl (l) (mapcar '(lambda (x) (/ x (length l))) (apply 'mapcar (cons '+ l))))
  5.   ;; Fuzz value '20000' below set from drawing example .. may need to adjust for different scenarios
  6.   (setq f 20000.)
  7.   (cond   ((setq s (ssget ":L" '((0 . "hatch"))))
  8.     (setq s
  9.       (mapcar
  10.         '(lambda (x)
  11.            (list x
  12.             (_apl (mapcar 'cdr
  13.                 (vl-remove-if
  14.                   '(lambda (d) (or (equal '(0.0 0.0 0.0) (cdr d)) (/= 10 (car d))))
  15.                   (entget x)
  16.                 )
  17.              )
  18.             )
  19.            )
  20.          )
  21.         (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
  22.       )
  23.     )
  24.     (while   (setq e (car s))
  25.       (setq s (cdr s))
  26.       (if (setq tmp (vl-remove-if-not '(lambda (x) (equal (cadr e) (cadr x) f)) s))
  27.         (progn (mapcar 'entdel (mapcar 'car tmp))
  28.           (entdel (car e))
  29.           (mapcar '(lambda (x) (grdraw (cadr e) (cadr x) 3) (setq s (vl-remove x s))) tmp)
  30.         )
  31.       )
  32.     )
  33.    )
  34.   )
  35.   (princ)
  36. )


good
i test this file
but that is not work ~~

dwg file
You should have posted your actual drawing ... Sorry not enough time right now to figure this one out. Maybe ribarms code will do.
« Last Edit: April 05, 2018, 09:04:24 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

dussla

  • Bull Frog
  • Posts: 297
Re: duplicated hatch area delete way
« Reply #8 on: April 04, 2018, 10:47:21 PM »
Really sorry  my poor explain about my work
I receved this plan often
Red  is road
Gray is  earth

Earth hatch   exsit all region
For my work    i need   earth hatch -  road hatch
Then i can get  pure earth region  ~~~


ribarm

  • Gator
  • Posts: 3297
  • Marko Ribar, architect
Re: duplicated hatch area delete way
« Reply #9 on: April 05, 2018, 09:51:48 AM »
Ron's method is good, but the DWG is very demandable... So this is something between Ron's code and my version... It could get you some results as I've checked for fuzziness and hard coded it into lisp... Of course, only on your DWG...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:deleteoverlappedhatches ( / _apl adoc ss i ha el s enx bl hl )
  2.  
  3.  
  4.   (defun _apl ( l ) (mapcar '(lambda ( x ) (/ x (length l))) (apply 'mapcar (cons '+ l))))
  5.  
  6.   (vla-endundomark adoc)
  7.   (setq ss (ssget "_:L" '((0 . "HATCH") (2 . "SOLID"))))
  8.   (if ss
  9.     (progn
  10.       (repeat (setq i (sslength ss))
  11.         (setq ha (ssname ss (setq i (1- i))))
  12.         (setq el (entlast) s (ssadd))
  13.         (vl-cmdf "_.-HATCHEDIT" ha "_B" "_P" "_N")
  14.         (while (setq el (entnext el))
  15.           (ssadd el s)
  16.         )
  17.         (vl-cmdf "_.PEDIT" "_M" s "" "_J" "_J" "_E" 10000.0)
  18.         (while (< 0 (getvar 'cmdactive)) (vl-cmdf ""))
  19.         (if (= 0 (logand 1 (cdr (assoc 70 (setq enx (entget (entlast)))))))
  20.           (entmod (setq enx (subst (cons 70 (1+ (cdr (assoc 70 enx)))) (assoc 70 enx) enx)))
  21.         )
  22.         (setq bl (cons (list (_apl (mapcar 'cdr (vl-remove-if '(lambda ( x ) (/= (car x) 10)) enx))) (entlast) ha) bl))
  23.       )
  24.       (foreach b bl
  25.         (if (vl-some '(lambda ( x ) (and (equal (vlax-curve-getarea (cadr b)) (vlax-curve-getarea (cadr x)) 1e+9) (< (distance (car b) (car x)) 3.6e+4))) (vl-remove b bl)) ;;; change 1e+9 and 3.6e+4 to suit DWG
  26.           (setq hl (cons b hl))
  27.         )
  28.       )
  29.       (foreach e (mapcar 'caddr hl)
  30.         (entdel e)
  31.       )
  32.       (foreach b bl
  33.         (entdel (cadr b))
  34.       )
  35.     )
  36.   )
  37.   (vla-regen adoc acactiveviewport)
  38.   (vla-endundomark adoc)
  39.   (princ)
  40. )
  41.  

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

:)

M.R. on Youtube

dussla

  • Bull Frog
  • Posts: 297
Re: duplicated hatch area delete way
« Reply #10 on: April 05, 2018, 10:12:13 AM »
Ron's method is good, but the DWG is very demandable... So this is something between Ron's code and my version... It could get you some results as I've checked for fuzziness and hard coded it into lisp... Of course, only on your DWG...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:deleteoverlappedhatches ( / _apl adoc ss i ha el s enx bl hl )
  2.  
  3.  
  4.   (defun _apl ( l ) (mapcar '(lambda ( x ) (/ x (length l))) (apply 'mapcar (cons '+ l))))
  5.  
  6.   (vla-endundomark adoc)
  7.   (setq ss (ssget "_:L" '((0 . "HATCH") (2 . "SOLID"))))
  8.   (if ss
  9.     (progn
  10.       (repeat (setq i (sslength ss))
  11.         (setq ha (ssname ss (setq i (1- i))))
  12.         (setq el (entlast) s (ssadd))
  13.         (vl-cmdf "_.-HATCHEDIT" ha "_B" "_P" "_N")
  14.         (while (setq el (entnext el))
  15.           (ssadd el s)
  16.         )
  17.         (vl-cmdf "_.PEDIT" "_M" s "" "_J" "_J" "_E" 10000.0)
  18.         (while (< 0 (getvar 'cmdactive)) (vl-cmdf ""))
  19.         (if (= 0 (logand 1 (cdr (assoc 70 (setq enx (entget (entlast)))))))
  20.           (entmod (setq enx (subst (cons 70 (1+ (cdr (assoc 70 enx)))) (assoc 70 enx) enx)))
  21.         )
  22.         (setq bl (cons (list (_apl (mapcar 'cdr (vl-remove-if '(lambda ( x ) (/= (car x) 10)) enx))) (entlast) ha) bl))
  23.       )
  24.       (foreach b bl
  25.         (if (vl-some '(lambda ( x ) (and (equal (vlax-curve-getarea (cadr b)) (vlax-curve-getarea (cadr x)) 1e+9) (< (distance (car b) (car x)) 3.6e+4))) (vl-remove b bl)) ;;; change 1e+9 and 3.6e+4 to suit DWG
  26.           (setq hl (cons b hl))
  27.         )
  28.       )
  29.       (foreach e (mapcar 'caddr hl)
  30.         (entdel e)
  31.       )
  32.       (foreach b bl
  33.         (entdel (cadr b))
  34.       )
  35.     )
  36.   )
  37.   (vla-regen adoc acactiveviewport)
  38.   (vla-endundomark adoc)
  39.   (princ)
  40. )
  41.  

M.R.

wow wow
i tested this code
90% is sucess~~
perpect  , really really thank you for your effor
again thank you ~~

ronjonp

  • Needs a day job
  • Posts: 7531
Re: duplicated hatch area delete way
« Reply #11 on: April 05, 2018, 10:57:40 AM »
Had a little bit of time .. here's another way to do it ( not 100% )  That drawing is a mess!

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ b c e f ll s ur)
  2.   ;; RJP - 04-05-2018
  3.   ;; Deletes overlapping hatches with somewhat common bounding boxes
  4.   (setq f 500)
  5.   (cond ((setq s (ssget ":L" '((0 . "hatch"))))
  6.          (setq s (mapcar '(lambda (x)
  7.                             (vla-getboundingbox (vlax-ename->vla-object x) 'll 'ur)
  8.                             (cons x (mapcar 'vlax-safearray->list (list ll ur)))
  9.                           )
  10.                          (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
  11.                  )
  12.          )
  13.          (while (setq e (car s))
  14.            (setq s (cdr s))
  15.            (setq b (cdr e))
  16.            (if (setq c
  17.                       (vl-remove-if-not
  18.                         '(lambda (x) (and (equal (car b) (car (cdr x)) f) (equal (cadr b) (cadr (cdr x)) f)))
  19.                         s
  20.                       )
  21.                )
  22.              (progn (mapcar 'entdel (mapcar 'car c))
  23.                     (entdel (car e))
  24.                     (mapcar '(lambda (x) (setq s (vl-remove x s))) c)
  25.              )
  26.            )
  27.          )
  28.         )
  29.   )
  30.   (princ)
  31. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

dussla

  • Bull Frog
  • Posts: 297
Re: duplicated hatch area delete way
« Reply #12 on: April 05, 2018, 11:40:32 AM »
my client give  mess plan always
Sometimes it goes crazy.
really thank you for your effor
I think
Maybe you are a genius sometimes :smitten: