+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Full Member
    Using
    AutoCAD 2016
    Join Date
    Feb 2016
    Location
    Australia
    Posts
    30

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

    Thanks in advance,

  2. #2
    Super Member
    Computer Details
    ronjonp's Computer Details
    Operating System:
    Windows 10
    Using
    AutoCAD 2018
    Join Date
    Apr 2009
    Location
    Colorado
    Posts
    889

    Default

    You can use the function HERE to do this.

  3. #3
    Full Member benhubel's Avatar
    Computer Details
    benhubel's Computer Details
    Operating System:
    Windows 7
    Discipline
    Manufacture
    benhubel's Discipline Details
    Occupation
    Waterjet Programmer
    Discipline
    Manufacture
    Using
    AutoCAD 2012
    Join Date
    Dec 2015
    Location
    Dallas, Texas
    Posts
    90

    Default

    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))
    	)
    )
    I just now discovered for the first time that I am prone to memory loss.

  4. #4
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,474

    Default

    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. #5
    Full Member
    Using
    AutoCAD 2016
    Join Date
    Feb 2016
    Location
    Australia
    Posts
    30

    Default

    Quote Originally Posted by benhubel View Post
    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. #6
    Full Member
    Using
    AutoCAD 2016
    Join Date
    Feb 2016
    Location
    Australia
    Posts
    30

    Default

    Quote Originally Posted by Grrr View Post
    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. #7
    Quantum Mechanic BIGAL's Avatar
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,702

    Default

    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 "")
    )
    A man who never made mistakes never made anything

  8. #8
    Forum Deity
    Using
    AutoCAD 2002
    Join Date
    Sep 2006
    Location
    East Sussex, U.K.
    Posts
    4,146

    Default

    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.

Similar Threads

  1. How to : Draw polyline from A list of Points And check its intersections
    By handasa in forum AutoLISP, Visual LISP & DCL
    Replies: 7
    Last Post: 17th May 2017, 03:38 am
  2. coordinate in list not found
    By MJLM in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 28th Jan 2015, 05:10 am
  3. Drawing Circle on List Coordinate
    By lesliematt in forum AutoCAD General
    Replies: 5
    Last Post: 16th Jul 2010, 02:26 am
  4. List coordinate by select point group
    By jason tay in forum AutoLISP, Visual LISP & DCL
    Replies: 37
    Last Post: 27th Apr 2009, 12:36 am
  5. Coordinate list
    By Moesian in forum AutoCAD Beginners' Area
    Replies: 1
    Last Post: 15th Mar 2005, 03:25 pm

Bookmarks

Posting Permissions

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