Jump to content

Divide a polyline at equal intervals and extract coordinates in excel


Recommended Posts

Posted

Dear cadtutors,

 

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.

AFTER.dwg

BEFORE.dwg

Posted

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?

Posted

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.

Posted

Are you looking for a chainage lisp?

Posted

Hai Dink,

 

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

  • 2 months later...
Posted

Dear Cad Tutors

 

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

 

Thanks a lot.

Posted

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 ;;

;; ;;

;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;;

;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;;

;;--

Posted (edited)

Try this quick & dirty lisp, just change an interval and other stuffs inside the 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)
(vl-load-com)

(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 acapp (vlax-get-acad-object))))
       )
)
(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)
ep (cadr 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
       (rtos (cadr pt) 2 3)
       (chr 9);<--tab delimited, (chr 44) - comma delimited
       (rtos (caddr pt)2 3))
  datafile)
     (setq i (1+ i))
 )
      (close datafile)
 )
    )
(princ)
 )

 

~'J'~

Edited by fixo
last coordinate: (rtos (caddr pt)2 3))
Posted

Dear Cad Tutor

 

I'll really appreciate if you explain me how to divide a 3D polyline into "n" equal segments and export to a txt or cvs file.

 

Thanks a lot.

Posted

Try this code

This will write all measured points include start and end points

to csv file

You'd be easily save it then as .xls


;;write 3dpoly points to csv

(defun C:pcd(/ cnt datafile dimz en ent num filename pline pt pt_list step 
)


(vl-load-com)
 (setq dimz (getvar "dimzin"))
 (setvar 
"dimzin" 3);<-- change to suit
(if (and
    (setq 
num (getint "\n\tEnter a number of divisions: ")) 
(setq ent (entsel 
"\n\tSelect polyline >> "))
(eq "POLYLINE"(cdr(assoc 0 (entget 
(setq en(car ent)))))))
  (progn
    (setq 
pt_list nil)
   (setq pline (vlax-ename->vla-object 
en))
   (setq step (/ (vla-get-length pline ) num))
(setq 
pt_list nil)
(setq pt_list (cons (vlax-curve-getstartpoint pline) 
pt_list))
 (setq cnt 0)
 (repeat (1- 
num)
   (setq  pt 
(trans

(vlax-curve-getPointAtDist pline  (* (setq  cnt (1+ cnt)) 
step)

)
         0 
1
       )

)
   (setq pt_list (cons pt pt_list))
 )
(setq 
pt_list (cons (vlax-curve-getendpoint pline) 
pt_list))

(setq pt_list (reverse 
pt_list))


(setq filename (strcat (getvar 
"dwgprefix")
       (vl-filename-base 
(getvar "dwgname"))".csv")
)
 (setq datafile (open filename 
"w"))

    (setq i 
1)

      (foreach pt 
pt_list

 (write-line (strcat (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
       (rtos (cadr pt) 2 
3)
       (chr 9);<--tab delimited, 
(chr 44) - comma delimited
       (rtos 
(caddr pt)2 3))
  datafile)

(setq i (1+ i))
 )
      (close 
datafile)
 )
    )
(setvar "dimzin" 
dimz)
(princ)
 )  
   (princ "\n\t===  
Type PCD to execute  ===")
(prin1)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...