DATAEXTRACTION coordinates sequence question

DATAEXTRACTION coordinates sequence question

Anonymous
Not applicable
3,490 Views
23 Replies
Message 1 of 24

DATAEXTRACTION coordinates sequence question

Anonymous
Not applicable

Dear all:

 

I used spline to plot a path, after this I changed this path to pline and divided with 0.1 meter interval. Then I use DATAEXTRACTION to export the coordinates of every point on the pline to Excel file, and I try to plot the path in MATLAB. However, I found that the sequence of the (X, Y) coordinates is not from the beginning of the path to the end of the path, but in a kind of order that I don't want.

 

track.jpg

 

Could you give me some guidance on how to make the exported coordinates of the path from the start point to the end point? 

 

Thank you very much.

 

 

0 Likes
Accepted solutions (2)
3,491 Views
23 Replies
Replies (23)
Message 2 of 24

ВeekeeCZ
Consultant
Consultant
Accepted solution

You can't rely on it. Here is something you can rely on. Command name is bold.

Edit: You can select any geometrical object like polyline, spline, line, arc, circle. No points needed.

 

Spoiler
(defun c:pldiv2file ( / *error* file aa en int i mx file)

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if file (close file))
    (princ))

  (princ "\nRequired single geometrical object, ")
  (while (not (setq ss (ssget "_+.:E:S" '((0 . "*POLYLINE,SPLINE,ARC,CIRCLE,LINE"))))))

  (initget 7)
  (setq int (getdist "\nSet interval: ")
	en (ssname ss 0)
	i 0.
	mx (vlax-curve-getDistAtParam en (vlax-curve-getEndParam en)))


  (if (setq file (open (strcat (getvar 'DWGPREFIX) (vl-string-right-trim ".dwg" (getvar 'DWGNAME)) ".csv") "a"))
    (progn
      (while (< i mx)
	(if (setq pt (vlax-curve-getPointAtDist en i))
	  (write-line (strcat (rtos (car pt) 2) "," (rtos (cadr pt) 2) "," (rtos (last pt) 2)) file))
	(setq i (+ i int)))
      (if (setq pt (vlax-curve-getPointAtDist en mx))
	(write-line (strcat (rtos (car pt) 2) "," (rtos (cadr pt) 2) "," (rtos (last pt) 2)) file))))
  
  (*error* "end")
)

Save it as *.lsp, and see HERE how to run this. In case you do't now already.

Message 3 of 24

Anonymous
Not applicable

Dear Sir/Madam:

 

Thank you very much for the reply, I 've followed your instruction on that website and tried myself. However, after I typed pldiv2file into the command window, it asked me to select the object. I chose the path, but nothing happens, and the command window still requires me to select an object. I don't know whether I did something wrong. Could you give me some guidance? Thank you!

 

 

0 Likes
Message 4 of 24

ВeekeeCZ
Consultant
Consultant
Accepted solution

Assuming you have your file saved.

 

Routine allows you single selection of one of these types of entity: "*POLYLINE,SPLINE,ARC,CIRCLE,LINE"

Then you specify an interval.

 

Then go to working folder of your current drawing and look for a file with the same name and *.csv

 

BTW. Points are always added at the end of the file. You can add one line to separate reports from same file.

 

Spoiler
(defun c:pldiv2file ( / *error* file aa en int i mx file)

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if file (close file))
    (princ))

  (princ "\nRequired single geometrical object, ")
  (while (not (setq ss (ssget "_+.:E:S" '((0 . "*POLYLINE,SPLINE,ARC,CIRCLE,LINE"))))))

  (initget 7)
  (setq int (getdist "\nSet interval: ")
	en (ssname ss 0)
	i 0.
	mx (vlax-curve-getDistAtParam en (vlax-curve-getEndParam en)))


  (if (setq file (open (strcat (getvar 'DWGPREFIX) (vl-string-right-trim ".dwg" (getvar 'DWGNAME)) ".csv") "a"))
    (progn
      (write-line (strcat "---- " (rtos (getvar "CDATE") 2 4)  " ---------------") file)
      (while (< i mx)
	(if (setq pt (vlax-curve-getPointAtDist en i))
	  (write-line (strcat (rtos (car pt) 2) "," (rtos (cadr pt) 2) "," (rtos (last pt) 2)) file))
	(setq i (+ i int)))
      (if (setq pt (vlax-curve-getPointAtDist en mx))
	(write-line (strcat (rtos (car pt) 2) "," (rtos (cadr pt) 2) "," (rtos (last pt) 2)) file))))
  
  (*error* "end")
)

 

 

0 Likes
Message 5 of 24

Anonymous
Not applicable
Thank you! Now it works! Beautiful 🙂
0 Likes
Message 6 of 24

Anonymous
Not applicable

Hi, I tired to spline, but I stuck at the step to choose the object. However, if I convert the spline to pl, then I can use the code to select the object, define the interval, and output the csv file. Could you let me know where I did wrong for the spline? According to your last reply, it seems the code should also work directly on spline right?

 

Thank you very much.

0 Likes
Message 7 of 24

ВeekeeCZ
Consultant
Consultant

No special requirements for splines - it works for me. Make sure that you're using the latest version - post 4, posting again. My first version was limited for lwpolyline... but I edited the code couple minutes after first version was released (see edit note). If still this does not work for you, post the sample dwg were it's not.

 

Spoiler
(vl-load-com)

(defun c:pldiv2file ( / *error* file aa en int i mx file)

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if file (close file))
    (princ))

  (princ "\nRequired single geometrical object, ")
  (while (not (setq ss (ssget "_+.:E:S" '((0 . "*POLYLINE,SPLINE,ARC,CIRCLE,LINE"))))))

  (initget 7)
  (setq int (getdist "\nSet interval: ")
	en (ssname ss 0)
	i 0.
	mx (vlax-curve-getDistAtParam en (vlax-curve-getEndParam en)))


  (if (setq file (open (strcat (getvar 'DWGPREFIX) (vl-string-right-trim ".dwg" (getvar 'DWGNAME)) ".csv") "a"))
    (progn
      (write-line (strcat "---- " (rtos (getvar "CDATE") 2 4)  " ---------------") file)
      (while (< i mx)
	(if (setq pt (vlax-curve-getPointAtDist en i))
	  (write-line (strcat (rtos (car pt) 2) "," (rtos (cadr pt) 2) "," (rtos (last pt) 2)) file))
	(setq i (+ i int)))
      (if (setq pt (vlax-curve-getPointAtDist en mx))
	(write-line (strcat (rtos (car pt) 2) "," (rtos (cadr pt) 2) "," (rtos (last pt) 2)) file))))
  
  (*error* "end")
)

Have fun with MatLab! I hated these couple seminars we had...

0 Likes
Message 8 of 24

arshadmirza786
Collaborator
Collaborator

Pls. add an "object snap" to end OR write in select object " select object from a end of line"

0 Likes
Message 9 of 24

arshadmirza786
Collaborator
Collaborator

Thank you to #BeekeeCZ for this "pldiv2file.lsp" 

Should u pls. add some words for "END POINT OF A SEGMENT OF PLINE" in addition to the distance already specified 

it is a geat help I hope you should improve it 

Thanks

0 Likes
Message 10 of 24

ВeekeeCZ
Consultant
Consultant

Hi @arshadmirza786, sorry I don't understand what you need.

Would give me some example of txt outcome? thx.

0 Likes
Message 11 of 24

arshadmirza786
Collaborator
Collaborator

I hope attached dwg file will explain what I says

0 Likes
Message 12 of 24

ВeekeeCZ
Consultant
Consultant

Still one question, meaning of your 1st point.

Does it mean that the calculation should start from the end which is closer to the point where the selection was made?

0 Likes
Message 13 of 24

arshadmirza786
Collaborator
Collaborator

sorry, START POINT (one side end/ start point of object) not from I click the object, 

As per my observation it start from where I click the object

 

0 Likes
Message 14 of 24

ВeekeeCZ
Consultant
Consultant

Well, it's little complicated now... hope I understood you well.

I've added a default value for an interval, you can change it to by your preference, red.

 

(vl-load-com)

(defun c:pldiv+2file ( / *error* file ss en obj pt dst par file)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if file (close file))
    (if obj (vla-delete obj))
    (princ))
  
  (princ "\nRequired single geometrical object, ")
  (if (and (setq ss (ssget "_+.:E:S" '((0 . "*POLYLINE,SPLINE,ARC,CIRCLE,LINE"))))
           (setq en (ssname ss 0))
           (setq pt (cadar (cdddar (ssnamex ss))))
           (setq pt (vlax-curve-getClosestPointTo en pt))
           (setq pt (progn
                      (if (> (vlax-curve-getDistAtParam en (vlax-curve-getParamAtPoint en pt))
                             (/ (vlax-curve-getDistAtParam en (vlax-curve-getEndParam en)) 2))
                        (command "_.REVERSE" (setq en (vlax-vla-object->ename (setq obj (vla-copy (vlax-ename->vla-object en))))) ""))
                      (vlax-curve-getStartPoint en)))
           (or *pldiv2file-int*
               (setq *pldiv2file-int* 500))
           (not (initget 6))
           (setq *pldiv2file-int* (cond ((getdist pt (strcat "\nSet interval <" (rtos *pldiv2file-int*)">: ")))
                                        (*pldiv2file-int*)))
           (setq dst 0.
                 par 0)
           (setq file (open (strcat (getvar 'DWGPREFIX) (vl-string-right-trim ".dwg" (getvar 'DWGNAME)) ".csv") "a"))
           (write-line (strcat "---- " (rtos (getvar "CDATE") 2 4)  " ---------------") file)
           )
    (while (<= par (vlax-curve-getEndParam en))
      (if (setq pt (vlax-curve-getPointAtDist en dst))
        (write-line (strcat (rtos (car pt) 2) "," (rtos (cadr pt) 2) "," (rtos (last pt) 2)) file))
      (cond ((equal par (vlax-curve-getEndParam en))
             (setq par (1+ par)))
            ((or (> (vlax-curve-getParamAtDist en (+ dst *pldiv2file-int*)) (1+ par))
                 (not (vlax-curve-getParamAtDist en (+ dst *pldiv2file-int*))))
             (setq par (1+ par)
                   dst (vlax-curve-getDistAtParam en par)))
            (T
             (setq dst (+ dst *pldiv2file-int*))))))
  (*error* "end")
  )
0 Likes
Message 15 of 24

arshadmirza786
Collaborator
Collaborator

Thank you for this great help

but it has born twin problem

1- The pline length is 7638 ft but in CSV file no body guss and add 250 ft againt each set of coordinate, so the length become 8500ft

Pls add a new column for distance and the specified intervel and end of segment be writen in CSV file

2- 

0 Likes
Message 16 of 24

arshadmirza786
Collaborator
Collaborator

2- the end distance of segment be wrriten on dwg for appropriate distance, corelating with dwg location

0 Likes
Message 17 of 24

ВeekeeCZ
Consultant
Consultant

Not sure if I understood you right, so I hope that following code will cover your needs.

 

(vl-load-com)

(defun c:pldiv+2file ( / *error* file ss en obj pt dst par lst)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if file (close file))
    (if obj (vla-delete obj))
    (princ))
  
  (princ "\nRequired single geometrical object, ")
  (if (and (setq ss (ssget "_+.:E:S" '((0 . "LWPOLYLINE,SPLINE"))))
           (setq en (ssname ss 0))
           (setq pt (cadar (cdddar (ssnamex ss))))
           (setq pt (vlax-curve-getClosestPointTo en pt))
           (setq pt (progn
                      (if (> (vlax-curve-getDistAtParam en (vlax-curve-getParamAtPoint en pt))
                             (/ (vlax-curve-getDistAtParam en (vlax-curve-getEndParam en)) 2))
                        (command "_.REVERSE" (setq en (vlax-vla-object->ename (setq obj (vla-copy (vlax-ename->vla-object en))))) ""))
                      (vlax-curve-getStartPoint en)))
           (or *pldiv2file-int*
               (setq *pldiv2file-int* 100))
           (not (initget 6))
           (setq *pldiv2file-int* (cond ((getdist pt (strcat "\nSet interval <" (rtos *pldiv2file-int*)">: ")))
                                        (*pldiv2file-int*)))
           (setq dst 0.
                 par 0
                 lst '(0.))
           (setq file (open (strcat (getvar 'DWGPREFIX) (vl-string-right-trim ".dwg" (getvar 'DWGNAME)) ".csv") "a"))
           (write-line (strcat "---- " (rtos (getvar "CDATE") 2 4)  " ---------------") file)
           )
    (progn
      (while (<= (setq par (1+ par)) (vlax-curve-getEndParam en))
        (setq lst (cons (vlax-curve-getDistAtParam en par) lst)))
      (while (<= (setq dst (+ dst *pldiv2file-int*)) (vlax-curve-getDistAtParam en (vlax-curve-getEndParam en)))
        (setq lst (cons dst lst)))
      (setq lst (vl-sort lst '<))
      (foreach e lst
        (setq pt (vlax-curve-getPointAtDist en e))
        (write-line (strcat (rtos (car pt)) "," (rtos (cadr pt)) "," (rtos (last pt)) "," (rtos e)) file))))    
  (*error* "end")
  )
Message 18 of 24

arshadmirza786
Collaborator
Collaborator

thank you for spare your time for this huge lisp,  if u like pls add this second request too

2- the end distance of segment be wrriten on dwg for appropriate distance, corelating with dwg location

 

thanks

0 Likes
Message 19 of 24

arshadmirza786
Collaborator
Collaborator

Sorry sir 

the new twin are borns

1- the length of 3 lines are different due to inner curve and outer curves and widening of left & right lines in some places

 

2- The length of center line should be Governing length

According to both outer line lenght should be adjusted and the distance at widening remain same

I hope you will address these to points 

Thank you

0 Likes
Message 20 of 24

ВeekeeCZ
Consultant
Consultant

Hi @arshadmirza786,

I did what I could do to help you with your issue, but I am unable to cover all your newly born ones.

If you feel that you still need some help, feel free to post your question HERE to customization forums, where are more folks able to help with these kind of issues. Good luck!!

0 Likes