1. ## connected polylines corners

Registered forum members do not see this ad.

Hello
I can not lisp.
Seeking a way with a lisp to connect the corners of a closed polyline.
These polylines are always so similar to the example.
There are very many such lines and it would be great if you could solve with a lisp.
Thank you!
Martin

2. Hi Martin

Try this, but be aware that it will fail if there are duplicate points or if any partial distance is shorter that the "offset" distance.
Code:
```(defun connect (e / _point d d1 l p1 p2 a b n i)
(setq _point vlax-curve-getpointatparam
d (vlax-curve-getdistatparam e (setq n (fix (+ 0.1 (vlax-curve-getendparam e))))))
(repeat (setq i (1+ n))
(setq l (cons (setq p1 (_point e (setq i (1- i)))) l))
(if
(if
(and
(< (setq d1 (distance p1 p2)) d)
(not (zerop d1))
)
(setq
d d1
a (rem (1+ i) n)
b i
)
)
)
)
(mapcar 'set '(a b) (list (max a b) (min a b)))
(while
(progn
(setq a (rem (1+ a) n))
(setq b (rem (+ n (1- b)) n))
(not (= (rem (1+ a) n) b))
)
(entmake
(list
'(0 . "LINE")
(cons 10 (_point e a))
(cons 11 (_point e b))
)
)
)
)

(defun c:test (/ ss i)
(if
(setq ss (ssget '((0 . "LWPOLYLINE"))))
(repeat (setq i (sslength ss))
(connect (ssname ss (setq i (1- i))))
)
)
(princ)
)```

3. Hello Stefan!

That's awesome !!
Many thanks.
It works wonderfully!

Thank you!
Martin

4. Just in case you would like an alternative which does not use lisp, draw a polyline at the centre, give it a width, and turn Fill off. The effect is the same

5. Hi Eldon

Only the corner joints are still missing.

thank you

Martin

6. You're welcome Martin

Duplicate points bug removed
Code:
```(defun connect (e / _point d d1 p1 p2 p11 p12 p21 p22 a b n i)
(setq _point vlax-curve-getpointatparam
d (vlax-curve-getdistatparam e
(setq n (fix (+ 0.1 (vlax-curve-getendparam e))))
)
)
(repeat (setq i (1+ n))
(setq p1 (_point e (setq i (1- i))))
(if p2
(if
(and
(< (setq d1 (distance p1 p2)) d)
(not (zerop d1))
)
(setq
d d1
a (rem (1+ i) n)
b i
)
)
)
(setq p2 p1)
)
(if (zerop b) (mapcar 'set '(a b) (list b a)))
(setq p11 (_point e a)
p21 (_point e b)
)
(while
(progn
(while
(equal p11 (setq p12 (_point e (setq a (rem (1+ a) n)))) 1e-8)
)
(while
(equal p21 (setq p22 (_point e (setq b (rem (+ n (1- b)) n)))) 1e-8)
)
(not
(or
(= (abs (- a b)) 1)
(= (abs (- a b)) n)
)
)
)
(entmake
(list
'(0 . "LINE")
(cons 10 (setq p11 p12))
(cons 11 (setq p21 p22))
)
)
)
)

(defun c:test (/ ss i)
(if
(setq ss (ssget '((0 . "LWPOLYLINE"))))
(repeat (setq i (sslength ss))
(connect (ssname ss (setq i (1- i))))
)
)
(princ)
)```

7. Hello Stefan!
Many thanks.

Thank you!
Martin

8. Hello Stefan,

One small thing is I have noticed.
There are drawn all the oblique connections.
But also a connection to the straight end of the polyline.
Would it still possible that you will not use it to create any line on the other is?
That would be great!

Many thanks!

Martin

9. sorry for my bad English

10. Registered forum members do not see this ad.

Updated previous post.
I'm not sure I have covered all the possibilities, I will check again later.

#### Posting Permissions

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