Jump to content

Draw Polyline by list of coordinate


RepCad

Recommended Posts

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,

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 years later...

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