Try this, No Error checking or filtering.
You do not need to pick each point, the programs
find them at every 20 meters.
You do have to enter a filename in the getfiled dialog box,
because you did not organize your data properly. The section
should be in a single folder and at least have a name that could
be translated to a chainage. Alternatively the first line in every
cross section file could be a real corresponding to the chainage.
You still have not answered my question!!!!!
(defun c:section2points (/ ** an en f fname lg p path pnum ps rst sect title
angleatpoint readcsv in_range rtosta)
;; ;
;; Return angle along curve, at specified point (on curve) ;
;; e - valid curve (ENAME or VLA-OBJECT) ;
;; p - point on curve ;
;; Alan J. Thompson, 11.04.10 ;
;; ;
(defun AngleAtPoint (e p)
(angle '(0. 0. 0.) (vlax-curve-getFirstDeriv e (vlax-curve-getParamAtPoint e p)))
)
;; ReadCSV - Lee Mac ;
;; Parses a CSV file into a list of lists, each sublist is a row ;
;; of CSV cell values. ;
(defun ReadCSV ( filename / _csv->lst file line lst )
(defun _csv->lst ( str / pos )
(if (setq pos (vl-string-position 44 str))
(cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2))))
(list str)
)
)
(if (setq file (open filename "r"))
(progn
(while (setq line (read-line file))
(setq lst (cons (_csv->lst line) lst))
)
(close file)
)
)
(reverse lst)
)
;; ;
;; in_range by ElpanovEvgeniy (recursive) ;
;; ;
;; Similar to the Python Function ;
;; ;
(defun in_range (s e i)
(if (or (and (> i 0) (< s e)) (and (< i 0) (> s e)))
(cons s (in_range (+ i s) e i))
)
)
;; ;
;; rtosta by ymg September 2013 ;
;; Arguments: sta, Real number to format as a Station ;
;; unit, 1 for Imperials, ;
;; 2 for Metrics. ;
;; prec, Integer for number of decimals ;
;; DIMZIN must be set to 0 or 1 outside this routine. ;
;; ;
;; Examples: (rtosta 0 1 0) -> "0+00" (rtosta 1328.325 1 2) -> "13+28.33";
;; (rtosta 0 2 0) -> "0+000" (rtosta 1328.325 2 2) -> "1+328.33";
;; ;
;; If sta is negative, format is as follow: ;
;; (rtosta -1328.325 1 2) -> "13-28.33" ;
;; (rtosta -1328.325 2 2) -> "1-328.33" ;
;; ;
(defun rtosta (sta unit prec / str a b dz)
(setq str (rtos (abs sta) 2 prec))
(while (< (strlen str) (if (= prec 0) (+ unit 2) (+ prec (+ unit 3))))
(setq str (strcat "0" str))
)
(setq a (if (= prec 0) (- (strlen str) unit) (- (strlen str) prec (+ unit 1)))
b (substr str 1 (- a 1))
a (substr str a)
)
(strcat b (if (minusp sta) "-" "+") a)
)
;;-------------------------- Main Program ---------------------------------;
(setq en (car (entsel "\nSelect the Polyline Representing the Alignment: "))
lg (vlax-curve-getdistatpoint en (vlax-curve-getendpoint en))
pnum 1
path ""
)
(foreach d (in_range 0 lg 20)
(setq title (strcat "Select File for Chainage " (rtosta d 2 0))
** (princ (strcat "\n" title))
fname (getfiled title path "txt" 0)
path (if (setq tmp (vl-filename-directory fname)) (strcat tmp "\\") "")
)
(if fname
(progn
(setq sect (readcsv fname)
p (vlax-curve-getpointatdist en d)
an (+ (angleatpoint en p) (/ pi 2))
)
(foreach i sect
(setq ps (polar p an (atof (car i)))
rst (cons (list pnum (car ps) (cadr ps) (atof (cadr i))) rst)
pnum (1+ pnum)
)
)
)
)
)
;; List rst now contains all points generated from the section ;
(setq f (open (strcat path "Section Points.txt") "w"))
(foreach i (reverse rst)
(write-line (strcat (itoa (car i)) ","
(rtos (cadr i)) ","
(rtos (caddr i)) ","
(rtos (cadddr i))
)
f
)
)
(close f)
(princ)
)
ymg