# Thread: Divide a polyline at equal intervals and extract coordinates in excel

1. ## Divide a polyline at equal intervals and extract coordinates in excel

Registered forum members do not see this ad.

is there any lisp to do the following.
divide polylines into equal intervals and add vertex to ploylines and label the vertex and extract the coordinates to excel.

my situation is.

I have a number of polylines at different position of different length.

need to divide the polylines at defined uniform intervals. (presently I am doing it by means of measure command, block method)

Join all blocks generated by measure command along with the verticies of the polyline in the series.

Label the Blocks/Vertex with the numbers usually with a suffix in series of the flow. Sometimes need to show the easting and northing at the vertex itself.

Extract the coordinates to excel with the label.

2. The intervals (distance) between each vertex on your sample is very unusual. it doesnt follow a pattern (or maybe i just dont see it), sometimes it starts at the end and some the intervals are form a vertex along the pline? going towrads the other direction?

Can you be more precise in describing the intervals?

3. Hai pBe,

In the attached drawings the interval is 200m and if the vertex falls before 200m then the vertex is taken without dividing the polyline.

If the vertex is falling in between the 200m division and it is some what closer to the previous or next block (as in this drawing) may within 60-80m. then that block is ignored & the previous or next block may be slghtly more than 200m. For the surveyors convinience I have made it this way.

You can try for uniform intervals.

4. Are you looking for a chainage lisp?

5. Hai Dink,

I am looking for a coordinate lisp rather than chainage lisp, But a chainage lisp will also be useful.

I have the same problem to solve, please, I would appreciate if you can send me the lisp application.

Thanks a lot.

7. The answer was above just search "chainage" "divide" "vertex" there at least 3 lsp's for chainages or points along a pline.

Chlabeller.lsp ? label station ?

Another search can not remember lsp name
;; ;;
;; Divides selected objects into an LWPolyline with a ;;
;; specified number of segments ;;
;;------------------------------------------------------------;;
;; Author: Lee McDonnell, 2010 ;;
;; ;;
;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;;
;;--

8. Originally Posted by BIGAL
Another search can not remember lsp name
http://lee-mac.com/segmentcurve.html

9. still a variant: download archives, load pltools.fas or pltools.lsp and type in command line pl-divall. The length of the segment - a negative number, the number of segments - a positive number.
To extract coordinates of excell:
Point manager
Lisp: coordinates of points to excel sheet (+point number)
Export coordinates (both Geodetic and Mathematical)

10. Registered forum members do not see this ad.

Try this quick & dirty lisp, just change an interval and other stuffs inside the code
Code:
```(defun C:plb (/ acapp acpt acsp ang cnt cur_length datafile div ent ep filename gap i p pline pline_num pt
pt_list seg_length sp step str_text txtpt txt_height verts x)

(defun rem_dupes  (lst prec)
(if lst
(cons (car lst)
(rem_dupes
(vl-remove-if '(lambda(x)(equal x (car lst) prec)) lst) prec)
)
)
)
(setq acsp (vla-get-block
(vla-get-activelayout
(vla-get-activedocument
)
)
(setq pt_list nil div 100.0)

(setq ent (entsel "\n\tSelect polyline >> "))

(setq pline (vlax-ename->vla-object (car ent)))
(setq verts (vl-remove-if 'not
(mapcar '(lambda(x)(if (= 10 (car x))(trans (cdr x) 0 1)))
(entget (car ent))))
)
(setq cur_length 0.)
(repeat (1- (length verts))
(setq sp (car verts)
pt_list (cons sp pt_list)
)
(setq seg_length
(distance sp ep)
step 0.)
(if (> seg_length div)
(repeat (fix (/ seg_length div))
(setq cur_length (+ cur_length div))
(if (and (setq pt (vlax-curve-getpointatdist pline cur_length))
(> (distance pt ep) div))
(setq pt_list (cons (vlax-curve-getclosestpointto pline pt) pt_list))
)
)
)
(setq verts (cdr verts))
)
(setq pt_list (cons (vlax-curve-getendpoint pline) pt_list))
(setq pt_list (reverse (rem_dupes pt_list 1.0)))
(setq pline_num (getint "\n\tPline label number: "))

(setq cnt  0
txt_height 25
gap  (* 2 txt_height))

(mapcar '(lambda (pt)
(setq ang (angle '(0 0 0)
(trans (vlax-curve-getFirstDeriv
pline
(vlax-curve-getParamAtPoint pline (trans pt 1 0)))
0
1
T)))
(setq txtpt (polar pt (* pi 1.5) gap))
(setq str_text (strcat (itoa pline_num) "-" (itoa (setq cnt (1+ cnt)))))
(vlax-invoke acsp 'insertblock pt "tick" 1 1 1 ang)
(vlax-invoke acsp 'addtext str_text txtpt txt_height))
pt_list)

(initget 1 "Yes No")
(setq acpt (getkword "\nDo you want to write points to file ? [Yes/No] <Yes>: "))
(if (eq acpt "Yes")
(progn
(setq filename (strcat (getvar "dwgprefix")
(vl-filename-base (getvar "dwgname"))".csv")
)
(setq datafile (open filename "a"))

(setq i 1)

(foreach pt pt_list

(write-line (strcat (strcat (itoa pline_num) "-" (itoa i))
(chr 9);<--tab delimited, (chr 44) - comma delimited
(rtos (car pt)2 3);<--precision 3 decimals
(chr 9);<--tab delimited, (chr 44) - comma delimited
(chr 9);<--tab delimited, (chr 44) - comma delimited
datafile)
(setq i (1+ i))
)
(close datafile)
)
)
(princ)
)```
~'J'~

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts