1. ## Polyline Vertex Question

Registered forum members do not see this ad.

Hi Guys,

Hope you are all having a great Christmas, and have a equally good New Year.

Just a quick question, which I am sure can be answered in minutes.

When looking at a problem posted on here recently (about marking points on a golf course...), I was thinking how I would approach the problem, and thought about using the vertices of a user-drawn polyline.

To experiment, I drew myself a polyline (attached), and performed an entget operation on it to see what it would return.

This is the result:

Code:
```((-1 . <Entity name: 7ef62ed8>)
(0 . "LWPOLYLINE")  <<--- Entity Type
(330 . <Entity name: 7ef53cc0>)
(5 . "2DC3")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")  <<--- Tab Name
(8 . "3")  <<--- Layer Name
(100 . "AcDbPolyline")
(90 . 4)
(70 . 0)
(43 . 0.0)
(38 . 0.0)
(39 . 0.0)
(10 0.0 0.0)  <<--- First Vertex (Start Point)
(40 . 0.0)   <<--- Starting Thickness for First Segment
(41 . 0.0)  <<--- Ending Thickness for First Segment
(42 . 0.0)
(10 10.0 0.0)   <<--- Second Vertex
(40 . 0.0)
(41 . 0.0)
(42 . 0.0)
(10 10.0 10.0)  <<--- Third Vertex
(40 . 0.0)
(41 . 0.0)
(42 . 0.0)
(10 0.0 10.0)  <<--- Fourth Vertex (End Point)
(40 . 0.0)
(41 . 0.0)
(42 . 0.0)
(210 0.0 0.0 1.0))```
These coordinates correspond to the various vertices on my attached drawing. But my question is, how does one obtain these values through LISP?

My initial assumption would be something of the form:

Code:
```(defun c:test (/ ent Vertex)
(setq ent (entget (car (entsel))))
(setq Vertex (cdr (assoc 10 ent)))
(princ)
) ;_  end defun```
But how would one retrieve the next vertex, and every other vertex after that? How do you cycle through the different entries for the DXF code 10?

Many thanks for any advice and help provided

2. Try in command line:

Click polyline to get DXF list:

Code:
```Command: (setq plDxf(entget(car(entsel))))

Select object: ((-1 . <Entity name: 7efa3368>) (0 . "LWPOLYLINE") (330 .
<Entity name: 7efa1cf8>) (5 . "1AD") (100 . "AcDbEntity") (67 . 0) (410 .
"Model") (8 . "0") (100 . "AcDbPolyline") (90 . 4) (70 . 0) (43 . 0.0) (38 .
0.0) (39 . 0.0) (10 0.0 0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 10.0 0.0) (40
. 0.0) (41 . 0.0) (42 . 0.0) (10 10.0 10.0) (40 . 0.0) (41 . 0.0) (42 . 0.0)
(10 0.0 10.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (210 0.0 0.0 1.0))```
Remove all non 10 groups:

Code:
```Command: (setq lst10(vl-remove-if '(lambda(x)(/= 10(car x)))plDxf))
((10 0.0 0.0) (10 10.0 0.0) (10 10.0 10.0) (10 0.0 10.0))```
Remove first member of each list"

Code:
```Command: (setq verLst(mapcar 'cdr lst10))
((0.0 0.0) (10.0 0.0) (10.0 10.0) (0.0 10.0))```
Or at once:

Code:
```Command: (mapcar 'cdr(vl-remove-if '(lambda(x)(/= 10(car x)))(entget(car(entsel)))))
((0.0 0.0) (10.0 0.0) (10.0 10.0) (0.0 10.0))```

3. Thank you for your reply, ASMI - I have learnt a lot from it.

But, I note that this would only work for this example - for instance, if I had vertices with co-ordinates:

(1.0 5.0 0.0)
(2.0 6.0 0.0)
(3.0 7.0 0.0)

How would I deal with this situation?

Is there not a generic function for dealing with multiple occurences of the same DXF group code?

Thanks for your help ASMI, much appreciated.

4. It will work with every lwpolyline.

5. Ahh, Sorry, I misread you last post - when you removed the DXF 10 code. Sorry!

6. Thanks lpseifert,

Thats very interesting!

7. Code:
```(defun massoc (key alist / x nlist)
(foreach x alist
(if (eq key (car x))
(setq nlist (cons (cdr x) nlist))))
(reverse nlist))```
This will return a list of values for the key in alist. It was made to deal with just such a scenario.

You would have to do some extra coding for every other one etc.

-David

8. Excellent David,

Simple and effective. Nice one

Thanks

9. Registered forum members do not see this ad.

I might be missing something here, but would it be possible to take the points taken from the polyline and save them as pt1, pt2, pt3.... so they can be used in another command?

#### Posting Permissions

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