;; Lisp to convert Arc, Circle or Ellipse to polyline with user defined segment length

;;;
(defun c:Sx (/ CLEN ENT I J PTS SEGNUM SS)

(vl-load-com); Lee Mac ~ 30.01.10

(setq *doc (cond (*doc) ((vla-get-ActiveDocument (vlax-get-acad-object))))

*sLen (cond (*sLen) (10.)))

(if (and (setq j -1 ss (ssget "_:L" '((0 . "ARC,CIRCLE,*POLYLINE,SPLINE,LINE,ELLIPSE"))))

(not (initget 6))

(setq *sLen (cond ((getdist (strcat "\nSpecify Segment Length : "))) (*sLen))))

(while (setq ent (ssname ss (setq j (1+ j))))

(vla-StartUndoMark *doc)

(setq cLen (vlax-curve-getDistAtParam ent

(vlax-curve-getEndParam ent)) segNum (fix (/ cLen *sLen)) i -1)

(or (zerop (rem cLen *sLen)) (setq segNum (1+ segNum)))

(repeat (1+ segNum)

(setq pts (cons (cond ((vlax-curve-getPointAtDist ent

(* (setq i (1+ i)) *sLen)))

((vlax-curve-getEndPoint ent))) pts)))

(entmake (append (list (cons 0 "LWPOLYLINE")

(cons 100 "AcDbEntity")

(cons 100 "AcDbPolyline")

(cons 90 (length pts))

(cons 70 0))

(mapcar (function (lambda (a) (cons 10 a))) pts)))

(entdel ent) (setq pts nil)

(vla-EndUndoMark *doc)))

(princ))
(c:sx)

Advertisements