+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Junior Member
    Using
    AutoCAD 2000
    Join Date
    Dec 2011
    Posts
    10

    Default How to get start and end point of a single line pline

    I need to know how to get the start and end points of a polyline. I'm a rookie at this and just learned how to pull out the start and endpoints of a line and when I went to do it to a polyline I was completely lost.

    Another question: I use a comand that takes a line and turns it into a perforated line with each segment being a separate poly line. It creates them all in order down the line. Immediately following this command, would there be a way to call the first poly line created to extract its data, without manually selecting it?

  2. #2
    Forum Deity Dadgad's Avatar
    Using
    AutoCAD 2013
    Join Date
    Nov 2011
    Location
    At the confluence of worthlessness & invaluability
    Posts
    4,146

    Default

    I doubt this was how you did it way back on Autocad 2000, but on 2012 at the commandline type LIST> ENTER then select your polyline or line, or whatever else, then look down at the bottom of the list for the coordinates, as shown on the attachment.








    Whoops, I have inadvertently strayed into the deep end of the pool, just noticed that you are looking for coding help. Never mind.
    Attached Images
    Last edited by Dadgad; 12th Jan 2012 at 04:27 am.
    Volume and repetition do not validate opinions forged in the absence of thought.

  3. #3
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,743

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by jeremyearle5 View Post
    I need to know how to get the start and end points of a polyline. I'm a rookie at this and just learned how to pull out the start and endpoints of a line and when I went to do it to a polyline I was completely lost.
    Assuming you are referring to an LWPolyline entity and not a 3D Polyline or 2D Polyline, there are three ways that you can go about doing this:

    1) Using the DXF Group codes of the LWPolyline entity:


    The vertices of an LWPolyline are stored in multiple DXF Group 10 pairs, we can get them all using a simple foreach loop, then use the entries at each end of the list (noting that the list will be reversed by its construction using cons):

    Code:
    (foreach pair (entget <LWPolyline Entity>)
        (if (= 10 (car pair))
            (setq lst (cons (cdr pair) lst))
        )
    )
    (setq p1 (last lst))
    (setq p2 (car  lst))
    Or you can get the first and last pair directly from the start and end of the DXF data:

    Code:
    (setq el (entget <LWPolyline Entity>)
          p1 (cdr (assoc 10 el))
          p2 (cdr (assoc 10 (reverse el)))
    )
    2) Using the Coordinates property of the LWPolyline VLA-Object:

    When working with Visual LISP remember to call:

    Code:
    (vl-load-com)
    once during the session to load the Visual LISP functions.

    After converting the LWPolyline Entity to a VLA-Object using the vlax-ename->vla-object you can retrieve the Coordinates property and again use the start and end of the list:

    Code:
    (setq obj (vlax-ename->vla-object <LWPolyline Entity>)
          lst (vlax-get obj 'coordinates)
           p1 (list (car lst) (cadr lst))
          lst (reverse lst)
           p2 (list (cadr lst) (car lst))
    )
    Note that I use the undocumented vlax-get function to avoid the conversion from a Variant to a SafeArray, then to a List.

    3) Using the vlax-curve* functions:

    This is probably the easiest method since the vlax-curve* functions are intuitive to use and will work with all curve objects (Lines, Arcs, Circles, Ellipses, LWPolylines, Polylines, Splines etc.)

    Again, you will need to call (vl-load-com) to load the Visual LISP functions, then:

    Code:
    (setq p1 (vlax-curve-getstartpoint <LWPolyline Entity>)
          p2 (vlax-curve-getendpoint <LWPolyline Entity>)
    )
    Quote Originally Posted by jeremyearle5 View Post
    Another question: I use a comand that takes a line and turns it into a perforated line with each segment being a separate poly line. It creates them all in order down the line. Immediately following this command, would there be a way to call the first poly line created to extract its data, without manually selecting it?
    If you are using command calls to create your LWPolylines, before creating the LWPolylines, store the last entity in the database using entlast, then, following the creation of the LWPolylines you can step through each entity in the database which follows the 'entlast' entity using the entnext function.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. Replies: 10
    Last Post: 9th Jun 2011, 04:57 pm
  2. Anything (BLOCK, LINE, PLINE, TEXT, MTEXT) Align to LINE, PLINE
    By cadamrao in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 21st Jun 2010, 02:53 pm
  3. Break a line at a single point
    By Lucid in forum AutoCAD General
    Replies: 5
    Last Post: 20th Dec 2007, 10:55 pm
  4. Replies: 4
    Last Post: 27th Aug 2007, 11:35 pm
  5. Why can't I convert this to one single pline?
    By CADIDAC in forum AutoCAD 3D Modelling & Rendering
    Replies: 23
    Last Post: 27th Feb 2007, 03:11 pm

Tags for this Thread

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