create polyline from point-list-file

jeroenberkers

Usenet Archive
Joined
Jul 16, 2003
Messages
13
Reaction score
0
I have a file containing points (3D) to create a polyline. If there is only 1 list in the txt-file it works, but when there are 2 lists it only creates the first. Can anyone help me to find the bug...?

The text-file:
2022.982 , 6579.553 , 0.00
1998.863 , 6607.777 , 0.00
2048.866 , 6607.924 , 0.00
2037.688 , 6594.694 , 0.00
2058.425 , 6592.93 , 0.00
2072.837 , 6610.864 , 0.00
2108.869 , 6588.226 , 0.00
2086.368 , 6579.553 , 0.00
2077.544 , 6590.725 , 0.00
-----
2011.498 , 6550.25 , 50.00
2011.498 , 6583.774 , 50.00
2028.139 , 6559.902 , 50.00
2035.381 , 6582.998 , 50.00
2043.745 , 6550.336 , 50.00
2063.748 , 6581.533 , 50.00
2066.335 , 6554.904 , 50.00
2074.353 , 6573.605 , 50.00
2075.991 , 6559.299 , 50.00
-----
the "----" is the seperation for the different polylines

The lisp:
(defun C:PT2POLY ( / )
(setvar "CMDECHO" 0)
(setq again 1)
(setq fn (open (getfiled "Pointfile" (getvar "DWGPREFIX") "TXT" 0) "r")) (while again (command "_3DPOLY") ; create pline with different Z-points (while (setq regel (read-line fn)) (if regel (progn (if (not (= regel "-----")) (lees) (progn (command) (setq again 1) ) ; end progn ) ; end if ) ; end progn (setq again nil) ) ; end if ) ; end while ) ; end while (if fn (close fn)) (setvar "CMDECHO" 1) (princ)
) ; end defun

(defun lees ( / x_val y_val z_val)
(setq regel (string2list regel ","))
(setq x_val (atof (car regel))
y_val (atof (cadr regel))
z_val (atof (caddr regel)))
(setq r_punt (list x_val y_val z_val))
(command r_punt)
) ; end defun

Thanx in advance.
 
The problem I think is that you have two loops:

1. While again
2. While setq regel (which is reading a line from your text file)

The second loop will not finish while it still has line of text to read from the file, therefore even though it picks up the "-----" separator, because there is another line of text after it, it remains in the second loop and doesn't return to the "while again" loop until the entire text file has been read.

Therefore you need to reissue the 3Dpoly command within the second loop.

Hope thats of some help.

J

I have a file containing points (3D) to create a polyline. If there is only 1 list in the txt-file it works, but when there are 2 lists it only creates the first. Can anyone help me to find the bug...?

The text-file:
2022.982 , 6579.553 , 0.00
1998.863 , 6607.777 , 0.00
2048.866 , 6607.924 , 0.00
2037.688 , 6594.694 , 0.00
2058.425 , 6592.93 , 0.00
2072.837 , 6610.864 , 0.00
2108.869 , 6588.226 , 0.00
2086.368 , 6579.553 , 0.00
2077.544 , 6590.725 , 0.00
-----
2011.498 , 6550.25 , 50.00
2011.498 , 6583.774 , 50.00
2028.139 , 6559.902 , 50.00
2035.381 , 6582.998 , 50.00
2043.745 , 6550.336 , 50.00
2063.748 , 6581.533 , 50.00
2066.335 , 6554.904 , 50.00
2074.353 , 6573.605 , 50.00
2075.991 , 6559.299 , 50.00
-----
the "----" is the seperation for the different polylines

The lisp:
(defun C:PT2POLY ( / )
(setvar "CMDECHO" 0)
(setq again 1)
(setq fn (open (getfiled "Pointfile" (getvar "DWGPREFIX") "TXT" 0) "r")) (while again (command "_3DPOLY") ; create pline with different Z-points (while (setq regel (read-line fn)) (if regel (progn (if (not (= regel "-----")) (lees) (progn (command) (setq again 1) ) ; end progn ) ; end if ) ; end progn (setq again nil) ) ; end if ) ; end while ) ; end while (if fn (close fn)) (setvar "CMDECHO" 1) (princ)
) ; end defun

(defun lees ( / x_val y_val z_val)
(setq regel (string2list regel ","))
(setq x_val (atof (car regel))
y_val (atof (cadr regel))
z_val (atof (caddr regel)))
(setq r_punt (list x_val y_val z_val))
(command r_punt)
) ; end defun

Thanx in advance.
 

Latest threads

Back
Top