;; Convert Radius Elbow to Segmented one with user difined number of segments RJP version
;; Saved from here: https://www.theswamp.org/index.php?topic=52135.0
;; Little modified by Igal Averbuh 2016 (added option for user define of number of segments)

(defun c:sg (/ _makepolyline arc arc2 arcs cp d i p1 p2 pst sp x)
;; RJP 10.13.2016
(defun _makepolyline (layer pts)
(entmakex (apply 'append
(list (list '(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
(cons 8 layer)
'(100 . "AcDbPolyline")
(cons 90 (length pts))
'(43 . 0)
'(70 . 1)
)
(mapcar '(lambda (x) (list 10 (car x) (cadr x))) pts)
)
)
)
)
;; Change 'i' for number of segments

(setq i (getint
(strcat "\nNumber of Segments per Arc:"

)
)
)

; (setq i 4)
(if (setq arcs (ssget ":L" '((0 . "arc"))))
(progn (setq arcs (vl-remove-if 'listp (mapcar 'cadr (ssnamex arcs))))
(while (setq arc (car arcs))
(setq cp (cdr (assoc 10 (entget arc))))
(if (setq arc2 (car (vl-remove-if-not
'(lambda (x) (equal cp (cdr (assoc 10 (entget x))) 0.0001))
(setq arcs (cdr arcs))
)
)
)
(progn (setq arcs (vl-remove arc2 arcs))
(setq sp (vlax-curve-getstartparam arc))
(setq d (/ (- (vlax-curve-getendparam arc) sp) i))
(repeat i
(setq p1 (vlax-curve-getpointatparam arc sp))
(setq p2 (vlax-curve-getpointatparam arc (setq sp (+ d sp))))
(_makepolyline
(cdr (assoc 8 (entget arc)))
(list p1
p2
(vlax-curve-getclosestpointto arc2 p2)
(vlax-curve-getclosestpointto arc2 p1)
)
)
)
(entdel arc)
(entdel arc2)
)
)
)
)
)
(princ)
)
(c:sg)

Advertisements