Author Topic: Correct Self Intersecting Polylines  (Read 5567 times)

0 Members and 1 Guest are viewing this topic.

mailmaverick

  • Bull Frog
  • Posts: 493
Correct Self Intersecting Polylines
« on: October 05, 2018, 04:21:59 AM »
How to correct Self-Intersecting Polylines to not Self-Intersecting Polylines ?
I'm referring to LWPolyline (in two dimensions only).

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Correct Self Intersecting Polylines
« Reply #1 on: October 05, 2018, 09:07:38 AM »
Interesting task, but I don't want to share the code...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

renkor

  • Newt
  • Posts: 27
Re: Correct Self Intersecting Polylines
« Reply #2 on: October 24, 2018, 03:15:19 AM »
Hello,

wow it`s a good task. where can we find some lisp like yours?

Best regards.

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Correct Self Intersecting Polylines
« Reply #3 on: October 24, 2018, 08:00:20 AM »
Hello,

wow it`s a good task. where can we find some lisp like yours?

Best regards.

I don't know, I know that I wrote my version and it's in my library which will be available after I die...
:(
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

mailmaverick

  • Bull Frog
  • Posts: 493
Re: Correct Self Intersecting Polylines
« Reply #4 on: August 25, 2021, 12:55:03 AM »
Hi,

Can someone please share the Code to automatically correct Self-Intersecting 2-D LWPolylines please.
Thanks a lot.

Rod

  • Newt
  • Posts: 185
Re: Correct Self Intersecting Polylines
« Reply #5 on: August 25, 2021, 01:59:12 AM »
If you are using AutoCAD Civil or Map you can utilise the Mapclean command through lisp.
I would use the "break crossing objects" first then "dissolve psuedo nodes" on the results (that are not closed)
Sorry don't have any code for you.
"All models are wrong, some models are useful" - George Box

danAllen

  • Newt
  • Posts: 133
Re: Correct Self Intersecting Polylines
« Reply #6 on: August 25, 2021, 04:54:52 PM »
I usually only need this for drawing hatches in a closed boundary. I find it easiest to explode the offending pline, and use BPOLY to draw a new one. Also OVERKILL often will fix the extra vertices. Try also CAB's break all.
http://www.theswamp.org/index.php?topic=10370.msg132035#msg132035

nekonihonjin

  • Newt
  • Posts: 103
Re: Correct Self Intersecting Polylines
« Reply #7 on: August 27, 2021, 11:34:10 AM »
Hi,

Can someone please share the Code to automatically correct Self-Intersecting 2-D LWPolylines please.
Thanks a lot.

if it's a closed pline, just hatch the inside with "pick points", the right-click in the hatch and "generate boundary"
the just erase both the hatch and the old selfintersecting line.

dexus

  • Bull Frog
  • Posts: 207
Re: Correct Self Intersecting Polylines
« Reply #8 on: October 25, 2023, 08:54:05 AM »
I came across this problem as well and couldn't find anyone who posted code to fix the polylines.
So I made a version myself using boundaries. It's not the quickest, but does the job (including some known flaws).

Code - Auto/Visual Lisp: [Select]
  1. (defun c:fixSelfIntersecting (/ sel box app lst dis n ss x y enl rtn cmdecho nomutt clayer *error*)
  2.   ; --------------------------------------------------------- ;
  3.   ;  Fix Self Intersecting polylines - dexus                  ;
  4.   ; --------------------------------------------------------- ;
  5.   ;  Tries to split self intersecting polylines into          ;
  6.   ;  seperate closed polylines.                               ;
  7.   ;                                                           ;
  8.   ;  Known flaws:                                             ;
  9.   ;  - Doesnt work on open polylines, only closed             ;
  10.   ;  - Resets width of all polyline segment to 0              ;
  11.   ;  - Some very, very small regions may be skipped           ;
  12.   ;  - Repeatedly prints error of valid boundary not found.   ;
  13.   ; --------------------------------------------------------- ;
  14.  
  15.   (defun *error* (st)
  16.     (if (wcmatch (strcase st t) "*break,*cancel*,*exit*")
  17.       (redraw)
  18.       (princ "\nError! Something went wrong.")
  19.     )
  20.     (if cmdecho (setvar 'cmdecho cmdecho))
  21.     (if nomutt (setvar 'nomutt nomutt))
  22.     (if clayer (setvar 'clayer clayer))
  23.     (setvar 'modemacro "")
  24.     (princ)
  25.   )
  26.  
  27.   (if (setq ss (ssget '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1))))
  28.   )))
  29.     (repeat (setq n (sslength ss))
  30.       (if
  31.         (and
  32.           (setq e (ssname ss (setq n (1- n))))
  33.           (setq sel (ssadd e))
  34.           (setq box (LM:ssboundingbox sel))
  35.         )
  36.         (progn
  37.           (setq app (vlax-get-acad-object)
  38.                 dis (/ (apply 'distance box) 20.0)
  39.                 lst (mapcar '(lambda (a o) (mapcar o a (list dis dis))) box '(- +))
  40.                 dis (* dis 1.5)
  41.                 cmdecho (getvar 'cmdecho)
  42.                 nomutt (getvar 'nomutt)
  43.                 clayer (getvar 'clayer))
  44.  
  45.           (apply 'vlax-invoke
  46.             (vl-list* app 'zoomwindow
  47.               (mapcar '(lambda (a o) (mapcar o a (list dis dis 0.0))) box '(- +))
  48.             )
  49.           )
  50.           (setq enl (entlast)
  51.                 rtn (ssadd))
  52.           (while (setq tmp (entnext enl))
  53.             (setq enl tmp)
  54.           )
  55.  
  56.           (setq x (caar lst)
  57.                 y (cadar lst)
  58.                 dis (/ dis 4.0))
  59.  
  60.           (setvar 'cmdecho 0)
  61.           (setvar 'nomutt 1)
  62.           (setvar 'clayer (cdr (assoc 8 (entget e))))
  63.           (command "_.-boundary" "_a" "_b" "_n" sel "" "_i" "_y" "_o" "_p" "")
  64.           (while (<= x (caadr lst))
  65.             (while (<= y (cadadr lst))
  66.               (command "_non" (list x y))
  67.               (setq y (+ y dis))
  68.             )
  69.             (setq x (+ x dis)
  70.                   y (cadar lst))
  71.           )
  72.           (while (< 0 (getvar 'cmdactive)) (command ""))
  73.           (while (setq enl (entnext enl)) (ssadd enl rtn))
  74.           (entdel e)
  75.           (vla-zoomprevious app)
  76.           (setvar 'cmdecho cmdecho)
  77.           (setvar 'nomutt nomutt)
  78.           (setvar 'clayer clayer)
  79.           rtn ; This retuns the resulting polylines as a selection set in case you want to use this function inside of another function.
  80.         )
  81.       )
  82.     )
  83.   )
  84.   (princ)
  85. )
  86.  
  87. ;;----------------------------------------------------------------------;;
  88. ;; Selection Set Bounding Box  -  Lee Mac                               ;;
  89. ;; Returns a list of the lower-left and upper-right WCS coordinates of a;;
  90. ;; rectangular frame bounding all objects in a supplied selection set.  ;;
  91. ;; s - [sel] Selection set for which to return bounding box             ;;
  92. ;;----------------------------------------------------------------------;;
  93. (defun LM:ssboundingbox (s / a b i m n o)
  94.   (repeat (setq i (sslength s))
  95.     (if
  96.       (and
  97.         (setq o (vlax-ename->vla-object (ssname s (setq i (1- i)))))
  98.         (vlax-method-applicable-p o 'getboundingbox)
  99.         (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list o 'a 'b))))
  100.       )
  101.       (setq m (cons (vlax-safearray->list a) m)
  102.             n (cons (vlax-safearray->list b) n))
  103.     )
  104.   )
  105.   (if (and m n)
  106.     (mapcar '(lambda (a b) (apply 'mapcar (cons a b))) '(min max) (list m n))
  107.   )
  108. )
  109.  
« Last Edit: October 25, 2023, 09:04:14 AM by dexus »