Author Topic: join lines  (Read 3894 times)

0 Members and 1 Guest are viewing this topic.

domenicomaria

  • Swamp Rat
  • Posts: 737
Re: join lines
« Reply #15 on: May 29, 2023, 02:02:19 PM »
@kasmo
because there are situations
where it's not the same thing
(and it's not easy to explain it)
and anyway it's more interesting
to write functions that are independent
from ACAD ...

ribarm

  • Gator
  • Posts: 3313
  • Marko Ribar, architect
Re: join lines
« Reply #16 on: May 29, 2023, 04:24:24 PM »
I had small mistake in chain.zip, so I reattached it again...

Sorry, but it happens from time to time...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

domenicomaria

  • Swamp Rat
  • Posts: 737
Re: join lines
« Reply #17 on: May 30, 2023, 02:49:18 AM »
https://drive.google.com/file/d/1BTd9jFE7b4hb0iiaAKV5HW0qp8o0u-1e/view?usp=sharing

Thank you VovKa
Your code and mine do the same thing.
And they both work well.
Yours is blue. Mine is red.

Your code is as always very elegant
and I still have to study it.

ciao

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: join lines
« Reply #18 on: May 30, 2023, 05:13:51 AM »
does not want to join these
Code: [Select]
(mapcar 'entmakex
'(((0 . "LINE") (10 6753.94 4368.45 0.0) (11 6768.27 4108.41 0.0))
  ((0 . "LINE") (10 6768.27 4108.41 0.0) (11 6469.86 3748.16 0.0))
  ((0 . "LINE") (10 6753.94 4368.45 0.0) (11 7467.73 4401.85 0.0))
  ((0 . "LINE") (10 7515.47 4172.82 0.0) (11 7467.73 4401.85 0.0))
  ((0 . "LINE") (10 7515.47 4172.82 0.0) (11 7396.11 3798.26 0.0))
  ((0 . "LINE") (10 7396.11 3798.26 0.0) (11 7157.39 3678.97 0.0))
  ((0 . "LINE") (10 7157.39 3678.97 0.0) (11 6768.27 4108.41 0.0))
)
)

domenicomaria

  • Swamp Rat
  • Posts: 737
Re: join lines
« Reply #19 on: May 30, 2023, 06:10:15 AM »
does not want to join these
Code: [Select]
(mapcar 'entmakex
'(((0 . "LINE") (10 6753.94 4368.45 0.0) (11 6768.27 4108.41 0.0))
  ((0 . "LINE") (10 6768.27 4108.41 0.0) (11 6469.86 3748.16 0.0))
  ((0 . "LINE") (10 6753.94 4368.45 0.0) (11 7467.73 4401.85 0.0))
  ((0 . "LINE") (10 7515.47 4172.82 0.0) (11 7467.73 4401.85 0.0))
  ((0 . "LINE") (10 7515.47 4172.82 0.0) (11 7396.11 3798.26 0.0))
  ((0 . "LINE") (10 7396.11 3798.26 0.0) (11 7157.39 3678.97 0.0))
  ((0 . "LINE") (10 7157.39 3678.97 0.0) (11 6768.27 4108.41 0.0))
)
)

Your code works perfectly !

My code fails !

Because the bad red segment !

I am not VovKa !
« Last Edit: May 30, 2023, 11:03:08 AM by domenicomaria »

domenicomaria

  • Swamp Rat
  • Posts: 737
Re: join lines
« Reply #20 on: May 30, 2023, 06:24:42 AM »
I'm not worried about this type of error anyway ...

which I didn't think about ...

because I suppose that the segments touch each other
and define a shape (closed or open)
without strange or particular situations

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: join lines
« Reply #21 on: May 30, 2023, 07:00:07 AM »
Your code works perfectly !
my code is by far not perfect
it produces different results depending on many random factors
i'd call it unpredictable :)

domenicomaria

  • Swamp Rat
  • Posts: 737
Re: join lines
« Reply #22 on: May 30, 2023, 08:40:06 AM »
@vovka
if we exclude the case where three or more segments have a common point, your code (but mine too) works perfectly...

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: join lines
« Reply #23 on: June 06, 2023, 05:04:16 PM »
My LM:sortedchainselection from this program may be useful in this regard: given a selection set (which could easily be a list of segments instead), it will return a list of chained segments.

domenicomaria

  • Swamp Rat
  • Posts: 737
Re: join lines
« Reply #24 on: June 07, 2023, 12:45:16 AM »
@Lee Mac
as always your code exceeds expectations

Thank you

ribarm

  • Gator
  • Posts: 3313
  • Marko Ribar, architect
Re: join lines
« Reply #25 on: June 12, 2023, 01:38:43 PM »
@meja has founded topic that may be of interes...
https://www.theswamp.org/index.php?topic=55918.0

Note : After applying (c:joinlsp) on preselection, resulting entity is joined polyline/spline and it's always (entlast) "if connections were lines or arcs" - last entity (with splines/polylines with more vertices it's different - one of them in the chain inherited joinings - one of them from endings start/end)...
« Last Edit: June 12, 2023, 02:26:08 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

xdcad

  • Swamp Rat
  • Posts: 522
Re: join lines
« Reply #26 on: November 22, 2023, 03:40:47 PM »
Thank you VovKa ...

... in the meantime I solved it too

and it also works with various segment groups

I will study your code, because what you do is always interesting !

if you want to do some tests, use the attached dwg

thanks

bye



==========

Regarding 3dpolyline JOIN, ideas:
1. Project to XY (Z->0)
2. JOIN
3. Modify the Z coordinate to the original corresponding 3D point and regenerate the 3D polyline

==========

Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2. ;|
  3. Project the selection set curve to the XY plane, Z=0
  4. |;
  5.   (defun _Project->XY (ss)
  6.     (setq plane (xdge::constructor "kPlane" '(0 0 0) '(0 0 1.0)))
  7.      ;Coordinate origin 0,0, normal vector (0 0 1.0) AcGe kPlane
  8.     (mapcar '(lambda (x)
  9.                (setq g (xdge::constructor x))
  10.      ; Generate AcGe curve from AcDb curve
  11.                (setq g1 (xdge::getpropertyvalue g "orthoproject" plane))
  12.      ;Geometric curves are orthogonally projected onto the plane plane
  13.                (setq e1 (xdge::entity:make g1))
  14.      ;Generate entity after projection
  15.                (if (xdrx_object_isa x "AcDb2dPolyline")
  16.                  (xdrx_polyline_convertto e1)
  17.                ) ;_ end of if
  18.      ;If it is 2d Polyline, convert it to lwpolyline
  19.                (xdrx_entity_matchprop x e1)
  20.      ;The entity attributes match the original curve, color, layer, linetype....
  21.                (xdrx_object_swapid e1 x)
  22.      ;Entity ObjectId exchange to ensure that the newly generated curve entity name remains unchanged
  23.                (xdrx_entity_delete e1)
  24.      ;Delete the original curve
  25.                (xdge::free g)
  26.      ;Geometric curve entities release memory
  27.              ) ;_ end of lambda
  28.             (xdrx_pickset->ents ss)
  29.      ;Select set to entity table
  30.     ) ;_ end of mapcar
  31.     (xdge::free plane)
  32.      ;Geometry plane object releases memory
  33.   ) ;_ end of defun
  34. ;|
  35.    Two-dimensional points query the original three-dimensional point table to obtain the coordinate Z value.
  36.    Make a new table ((x y) z)
  37. |;
  38.   (defun _query (pt pts)
  39.     (last (assoc (list (car pt) (cadr pt)) pts))
  40.   ) ;_ end of defun
  41.   (if (and (xdrx_initssget "\nSelect Curve<Exit>:")
  42.            (setq ss (xdrx_ssget '((0 . "*line,arc,ellipse,circle"))))
  43.       ) ;_ end of and
  44.     (progn
  45.      ;|
  46.         Save the 3dpolyline vertex table for later querying the Z value corresponding to the two-dimensional point
  47.         ( ((x1 y1) z1)((x2 y2) z2) ... ((xn yn) zn) )
  48.      |;
  49.       (setq pts  (xdrx-getpropertyvalue ss "vertices")
  50.                                         ;Select set curve vertex table
  51.             pts  (xd::list:flat-point pts)
  52.                                         ;One level bracket point table
  53.             pts1 (mapcar '(lambda (x)
  54.                             (list (list (car x) (cadr x)) (caddr x))
  55.                           ) ;_ end of lambda
  56.                          pts
  57.                  ) ;_ end of mapcar
  58.       ) ;_ end of setq
  59.       (_Project->XY ss)
  60.       ;;3dpolyline -> lwpolyline
  61.       (xdrx-curve-join ss)
  62.       ;; LWPOLYLINE JOIN
  63.       (setq nPnts nil)
  64.       (foreach n verts
  65.         (setq z (_query n pts1))
  66.         (setq pt    (list (car n) (cadr n) z)
  67.               nPnts (cons pt nPnts)
  68.         ) ;_ end of setq
  69.         (setq i (1+ i))
  70.       ) ;_ end of foreach
  71.       (setq nPnts (reverse nPnts))
  72.       (setq pl3d (xdrx-3dpolyline-make nPnts ))
  73.       ;;Generate new 3dpolyline
  74.     ) ;_ end of progn
  75.   ) ;_ end of if
  76.   (princ)
  77. )
  78.  


=============

The above LISP code uses the XDRX-API, which can be downloaded from https://github.com/xdcad/XDrx-API and is updated at any time.

The XDRX API encapsulates AcDb, AcEd, AcGe, AcBr... C++ library, using C++ methods to develop LISP programs.Thousands of Lisp functions are available.

« Last Edit: November 22, 2023, 07:46:35 PM by xdcad »
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net