(defun c:cpoints ()
;; Creates the list of points for selected curve (LINE, PLINE, SPLINE) according to the iteration distance.
;; by maripali for Eng-Tips December 17, 2017
(setq snapmode (getvar "OSMODE")
cUCS (getvar "UCSORG")
curve-obj (car (entsel "\nSelect curve: "))
)
(setvar "OSMODE" 0)
;; Select bounding box of the selected curve
(vla-getBoundingBox (vlax-ename->vla-object curve-obj) 'mn 'mx)
;; Lower left corner point Upper right corner point of the curve
(setq LLP (vlax-safearray->list mn)
URP (vlax-safearray->list mx)
)
;; Select the iteration distance
(setq deltaX (getdist "Set the distance for the horizontal steps: ")
Count_X (1+ (fix (/ (- (car URP) (car LLP)) deltaX)))
i 0
Curve-Points nil
OX nil
)
;; Start analysis
(repeat Count_X
(setq P1 (list (+ (car LLP) (* deltaX i)) (1- (cadr LLP)) (caddr LLP))
P2 (list (+ (car LLP) (* deltaX i)) (1+ (cadr URP)) (caddr URP))
CP1 (vlax-curve-getClosestPointTo curve-obj P1)
CP2 (vlax-curve-getClosestPointTo curve-obj P2)
)
(while (not (or (equal P1 CP1 1e-6) (equal P2 CP2 1e-6)))
;; Finding the Y of the curve
(progn
(setq P1 (list (car P1) (cadr CP1) (caddr P1))
P2 (list (car P2) (cadr CP2) (caddr P2))
CP1 (vlax-curve-getClosestPointTo curve-obj P1)
CP2 (vlax-curve-getClosestPointTo curve-obj P2)
)
)
) ;; End of While
(setq Curve-Points (cons (if (< (distance P1 CP1) (distance P2 CP2)) (mapcar '- CP1 cUCS) (mapcar '- CP2 cUCS)) Curve-Points)
i (1+ i)
)
) ;repeat end
(setvar "OSMODE" snapmode)
(setq Curve-Points (Reverse Curve-Points))
;(princ "\n\nPoints list:\n")
;(foreach ppoint Curve-Points (print ppoint))
(setq file_name (getfiled "Generate point list file for the selected curve: " "" "txt" 1)
)
(setq file_write (open file_name "w"))
;;CarlB modification for text file output, "x,y" format Dec. 19 2017
(foreach ppoint Curve-Points (write-line (strcat (rtos (car ppoint) 2 4) "," (rtos (cadr ppoint) 2 4)) file_write))
(close file_write)
(princ)
)