Jump to content

Solution: lwpolyline node optimization algorithm.


ssdd

Recommended Posts

Why are they wrong in 1st place ? Fix that 1st 

 

For me a new line trim, then fillet rad=0, erase line in some cases use that line as part of new pline. A few seconds to fix. Could macro/lisp the common steps.

 

Break and fillet maybe.

Edited by BIGAL
Link to comment
Share on other sites

I don't think this is possible without runniing some sort of slim polyline or pldiet lisp on the lines first. There are multiple vertices between between the proposed "fillets", and any lisp would have to work via some sort of distance, which could remove vertices that shouldn't be removed.

Link to comment
Share on other sites

There is another way very complicated explode erase all unwanted remake plines yes now two, fillet the two with nearest ends. Lee has find ends make pline.

 

A lot of effort for Fix the problem in 1st place.

 

It was so fast to fix manually. Yeah I know but I have hundreds.

Link to comment
Share on other sites

Just curious how did OP come up with these weird shapes polylines?

 

tested if PLDIET.lsp fuzz factor - 90%

depends on angle fuzz factor too

 

minimal tested

(defun c:test ( / foo v s l ls nl vp vl)
  ;c:vtrim - trim sharp vertices
  ;hanhphuc 20.11.19
  
  (mapcar 'set
          '(foo v)
          '(((l)
             (if
              (cddr l)
              (cons (list (car l) (cadr l) (caddr l)) (foo (cdr l)))
             )
            )
            ((x) (polar '(0.0 0.0) (apply 'angle x) 1.0))
           )
  )
  
  (prompt "\nPlease select LWPolyline.. ")
  
  (if (setq s (ssget 
                     '((0 . "LWPOLYLINE")
                       (-4 . ">")
                       (90 . 3)
                       (-4 . "<NOT")
                       (-4 . "<>")
                       (42 . 0.0)
                       (-4 . "NOT>")
                      )
              )
      )
    
    (foreach en (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) ;(acet-ss-to-list s)
      (and (setq l  (mapcar 'cdr (vl-remove-if ''((x) (/= 10 (car x))) (entget en)))
                 ls (foo l)
                 nl (cons
                      (caar ls)
                      (append (vl-remove nil
                                         (mapcar ''((x)
                                                    (if
                                                     (not (equal (angle (car x) (cadr x)) (apply 'angle (cdr x)) (* pi 0.25))) ; angle fuzz factor
                                                     (cadr x)
                                                    )
                                                   )
                                                 ls
                                         )
                              )
                              (list (caddr (last ls)))
                      )
                    )
           )
           (setq vp ((lambda (l fuzz)
                       (vl-remove-if
                         ''((x) (> (abs (distance '(0. 0.) (car x))) fuzz))
                         (mapcar ''((x) (cons (mapcar '+ (v (list (car x) (cadr x))) (v (cdr x))) x)) (foo l))
                       )
                     )
                      nl
                      1.0
                    )
           )
           (setq vl (mapcar ''((x) (mapcar ''((x) (vlax-curve-getDistAtPoint en x)) (cdr x))) vp))
           (foreach p l
             (if (vl-some ''((v) (< (car v) (vlax-curve-getDistAtPoint en p) (caddr v))) vl)
               (setq l (vl-remove p l))
             )
             l
           )
           (entmakex (vl-list* '(0 . "LWPOLYLINE")
                               '(100 . "AcDbEntity")
                               '(100 . "AcDbPolyline")
                               '(70 . 0)
                               '(62 . 1)
                               (cons 90 (length l))
                               (mapcar ''((x) (cons 10 x)) l)
                     )
           )
      )
    )
    (princ "\nOops..")
  )
  (princ)
)

 

@Marco Ribar has many polyline routines perhaps has solution 

 

 

vt1.gif

Edited by hanhphuc
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...