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

0 Members and 1 Guest are viewing this topic.

dgpuertas

  • Newt
  • Posts: 80
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)
  2.   (setq ss (ssadd))
  3.   (foreach x l
  4.     (setq e (entmakex (list '(0 . "LINE") (cons 10 (car x) ) (cons 11 (cadr x)))))
  5.     (ssadd e ss)
  6.   )
  7.   (if
  8.     (> (sslength ss) 0)
  9.     (progn
  10.       (setq el (entlast))
  11.      
  12.       (setq pa (getvar 'peditaccept))
  13.       (setq ce (getvar 'cmdecho))
  14.      
  15.       (setvar 'peditaccept 1)
  16.       (setvar 'cmdecho 0)
  17.      
  18.       (command "_pedit" "_m" ss "" "_j" 0 "")
  19.      
  20.       (setvar 'cmdecho ce)
  21.       (setvar 'peditaccept pa)
  22.      
  23.       (setq ss (ssadd))
  24.       (while (setq el (entnext el))
  25.         (ssadd el ss)
  26.       )
  27.      
  28.       (if
  29.         (> (sslength ss) 0)
  30.         (progn
  31.           (sssetfirst nil ss)
  32.           ss
  33.         )
  34.       )
  35.      
  36.     )
  37.   )
  38. )

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