Author Topic: [XDrX-PlugIn(142)] break closed polylines at corners  (Read 159 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Bull Frog
  • Posts: 493
[XDrX-PlugIn(142)] break closed polylines at corners
« on: April 12, 2024, 05:30:59 AM »
https://www.cadtutor.net/forum/topic/83317-please-help-to-break-closed-polylines-at-corners/



1.The API provides a ready-made method for calculating the angle between each segment of a polyline.
(xdrx-getpropertyvalue pline "allinnerangles")
(xdrx-getpropertyvalue pline "allouterangles")
(xdrx-getpropertyvalue pline "angles")


2.Get the vertices whose angle between segments is not 0 or PI, and then use xdrx-curve-getsplitcurves to break.

Code: [Select]
(defun c:xdtb_plbrkatcorner (/ angles pts ss x y)
  (if (setq ss (xdrx-ssget (xdrx-string-multilanguage "\n选择多段线<退出>:" "\nSelect Polylines<Exit>:") '
   ((0 . "*polyline"))
       )
      )
    (progn
      (xdrx-begin)
      (mapcar
'(lambda (x)
   (setq angles (xdrx-getpropertyvalue x "vertices" "angle")
angles (mapcar
  '(lambda (x y)
     (list x y)
   )
  (car angles)
  (cadr angles)
)
angles (vl-remove-if (function (lambda (x)
  (or
    (equal (last x) 0.0 1e-5)
    (equal (last x) pi 1e-5)
  )
)
      ) angles
)
pts (mapcar
       'car
       angles
     )
   )
   (xdrx-curve-getsplitcurves x pts)
)
(xdrx-ss->ents ss)
      )
      (xdrx-end)
    )
  )
  (princ)
)
« Last Edit: April 12, 2024, 06:24:35 AM by xdcad »
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net