Jump to content
amir0914

Draw Polyline by list of coordinate

Recommended Posts

amir0914

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.08) (2429.84 1612.08) (2430.06 1612.15) (2430.96 1612.12) (2431.96 1612.17) (2432.46 1612.17))

 

Thanks in advance,

Share this post


Link to post
Share on other sites
ronjonp

You can use the function HERE to do this.

Share this post


Link to post
Share on other sites
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.

(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))
)
)

Share this post


Link to post
Share on other sites
Grrr
(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)
   )
 )
)

Share this post


Link to post
Share on other sites
amir0914
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.

(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 :)

Share this post


Link to post
Share on other sites
amir0914
(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.

Share this post


Link to post
Share on other sites
BIGAL

Another way

 

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

Share this post


Link to post
Share on other sites
eldon

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×