Jump to content

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


jeremyearle5

Recommended Posts

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?

Link to comment
Share on other sites

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.

pline endpoint coordinated.jpg

Edited by Dadgad
Link to comment
Share on other sites

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

 

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

 

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

 

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

 

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

 

(setq p1 (vlax-curve-getstartpoint <LWPolyline Entity>)
     p2 (vlax-curve-getendpoint <LWPolyline Entity>)
)

 

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.

Link to comment
Share on other sites

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