### Author Topic: segment line to polyline(s)  (Read 1655 times)

0 Members and 1 Guest are viewing this topic.

#### dgpuertas

• Newt
• Posts: 78
##### segment line to polyline(s)
« on: November 15, 2022, 07:27:02 AM »
I have a list of segment represent lines:

(list (list 0 1) (list 1 0))  -..- (list (list 0 1) (list -1 0))  -..- (list (list -1 0) (list -3 3)) -..- (list (list 4 4) (list 4 6))

And i need to join all to obtain one (or more if not possible) polyline continuos.
There are not order in segment point (first, i think order by x and if equal x order by y)

to obtain (in sample 2 list of points continuos)

(list (list 0 1) (list 1 0))  -..- (list (list 0 1) (list -1 0))  -..- (list (list -1 0) (list -3 3)) -..- (list (list 4 4) (list 4 6))
|_______________________|             |_______________|
common point                          common point

one polyline                                               another polyline
(list -3 3) (list -1 0) (list 0 1) (list 1 0)         (list 4 4) (list 4 6)

Any idea to do this?

Thanks a lot.

#### Stefan

• Bull Frog
• Posts: 319
• The most I miss IRL is the Undo button
##### Re: segment line to polyline(s)
« Reply #1 on: November 15, 2022, 08:39:37 AM »
Draw all lines then Pedit.

Code - Auto/Visual Lisp: [Select]
1. (defun _plines (l / ss e pa ce el)
3.   (foreach x l
4.     (setq e (entmakex (list '(0 . "LINE") (cons 10 (car x) ) (cons 11 (cadr x)))))
6.   )
7.   (if
8.     (> (sslength ss) 0)
9.       (setq el (entlast))
10.
11.       (setq pa (getvar 'peditaccept))
12.       (setq ce (getvar 'cmdecho))
13.
14.       (setvar 'peditaccept 1)
15.       (setvar 'cmdecho 0)
16.
17.       (command "_pedit" "_m" ss "" "_j" 0 "")
18.
19.       (setvar 'cmdecho ce)
20.       (setvar 'peditaccept pa)
21.
23.       (while (setq el (entnext el))
25.       )
26.
27.       (if
28.         (> (sslength ss) 0)
29.           (sssetfirst nil ss)
30.           ss
31.         )
32.       )
33.
34.     )
35.   )
36. )

Code - Auto/Visual Lisp: [Select]
1. (_plines '(((0 1) (1 0)) ((0 1) (-1 0)) ((-1 0) (-3 3)) ((4 4) (4 6)))

#### dgpuertas

• Newt
• Posts: 78
##### Re: segment line to polyline(s)
« Reply #2 on: November 15, 2022, 09:37:24 AM »
Yes, is a good idea.

But i want to have a list of points to create polyline or spline and change width color layer etc..

Thanks for idea.

EDIT:
if i can use coordinates of pline and create spline then delete pline then works for me.
Thans a lot, lets autocad works for us.
« Last Edit: November 15, 2022, 09:51:36 AM by dgpuertas »

#### Stefan

• Bull Frog
• Posts: 319
• The most I miss IRL is the Undo button
##### Re: segment line to polyline(s)
« Reply #3 on: November 15, 2022, 10:09:16 AM »
_pline function returns a selectionset of the newly created polylines.
You can do whatever you want with these objects.

Or add the layer and color to the lines. You can change the global width in the "command" line.
Code - Auto/Visual Lisp: [Select]
1. (command "_pedit" "_m" ss "" "_j" 0 "_w" 0.5 "")