# Thread: Draw Polyline by list of coordinate

1. ## Draw Polyline by list of coordinate

Registered forum members do not see this ad.

Hello everybody,,
how can i draw polyline by list of x,y coordinate ?? :
list = ((x1 y1)(x2 y2)(x3 y3)(x4 y4) ......)

example my coordinate :

((2420.96 1612.3) (2422.96 1612.25) (2423.96 1612.12) (2424.96 1612.24) (2425.96 1612.09) (2426.96 1612.14) (2427.96 1612.0 (2429.84 1612.0 (2430.06 1612.15) (2430.96 1612.12) (2431.96 1612.17) (2432.46 1612.17))

2. You can use the function HERE to do this.

3. Apparently I'm just a couple minutes too late. Still, I'll post what I wrote anyway. It's really simple and there may be bugs, but it seems to work with your data-set, at least.
Code:
```(defun c:writepoints ( / verts index)
(setq verts '((2420.96 1612.3)(2422.96 1612.25)(2423.96 1612.12)(2424.96 1612.24)(2425.96 1612.09)(2426.96 1612.14)(2427.96 1612.08)(2429.84 1612.08)(2430.06 1612.15)(2430.96 1612.12)(2431.96 1612.17)(2432.46 1612.17)))
(setq index 0)
(repeat (1- (length verts))
(command "_.line" (append (nth index verts) '(0.0)) (append (nth (1+ index) verts) '(0.0)) "")
(setq index (1+ index))
)
)```

4. Code:
```(defun C:test ( / PointList )

(setq PointList
'(
(2420.96 1612.3) (2422.96 1612.25) (2423.96 1612.12) (2424.96 1612.24)
(2425.96 1612.09) (2426.96 1612.14) (2427.96 1612.0) (2429.84 1612.0)
(2430.06 1612.15) (2430.96 1612.12) (2431.96 1612.17) (2432.46 1612.17)
)
)

(LWPoly PointList
(if (progn (initget "Yes No") (member (getkword "\nClosed ? [Yes/No] <Yes>: ") '(nil "Yes"))) 1 0)
)
(princ)
); defun

(defun LWPoly (lst cls) ; LM's entmake functions
(entmakex
(append
(list
(cons 0 "LWPOLYLINE")
(cons 100 "AcDbEntity")
(cons 100 "AcDbPolyline")
(cons 90 (length lst))
(cons 70 cls)
)
(mapcar (function (lambda (p) (cons 10 p))) lst)
)
)
)```

5. Originally Posted by benhubel
Apparently I'm just a couple minutes too late. Still, I'll post what I wrote anyway. It's really simple and there may be bugs, but it seems to work with your data-set, at least.
Code:
```(defun c:writepoints ( / verts index)
(setq verts '((2420.96 1612.3)(2422.96 1612.25)(2423.96 1612.12)(2424.96 1612.24)(2425.96 1612.09)(2426.96 1612.14)(2427.96 1612.08)(2429.84 1612.08)(2430.06 1612.15)(2430.96 1612.12)(2431.96 1612.17)(2432.46 1612.17)))
(setq index 0)
(repeat (1- (length verts))
(command "_.line" (append (nth index verts) '(0.0)) (append (nth (1+ index) verts) '(0.0)) "")
(setq index (1+ index))
)
)```
Thanks benhubel, your code is work and it dont have any bugs. thanks alot for your help

6. Originally Posted by Grrr
Code:
```(defun C:test ( / PointList )

(setq PointList
'(
(2420.96 1612.3) (2422.96 1612.25) (2423.96 1612.12) (2424.96 1612.24)
(2425.96 1612.09) (2426.96 1612.14) (2427.96 1612.0) (2429.84 1612.0)
(2430.06 1612.15) (2430.96 1612.12) (2431.96 1612.17) (2432.46 1612.17)
)
)

(LWPoly PointList
(if (progn (initget "Yes No") (member (getkword "\nClosed ? [Yes/No] <Yes>: ") '(nil "Yes"))) 1 0)
)
(princ)
); defun

(defun LWPoly (lst cls) ; LM's entmake functions
(entmakex
(append
(list
(cons 0 "LWPOLYLINE")
(cons 100 "AcDbEntity")
(cons 100 "AcDbPolyline")
(cons 90 (length lst))
(cons 70 cls)
)
(mapcar (function (lambda (p) (cons 10 p))) lst)
)
)
)```
Grrr, Thank you for your time, your code that's what I want, thanks alot.

7. Another way

Code:
```; create pline from a list
; by Alan H
(command "_pline")
(while (= (getvar "cmdactive") 1 )
(repeat (setq x (length lst))
(command (nth (setq x (- x 1)) lst))
)
(command "")
)```

8. Registered forum members do not see this ad.

Writing a lisp to draw one polyline seems an awful lot of effort with maximum chance of mistakes whilst typing all those digits.

If your data is in the form of a csv file of coordinates, there are simpler ways of drawing a polyline.

#### Posting Permissions

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