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.
(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)
)