Author Topic: Join Lines to Polylines  (Read 14201 times)

0 Members and 1 Guest are viewing this topic.

POCKETS

  • Guest
Join Lines to Polylines
« on: August 20, 2009, 05:27:00 PM »
The included list joins lines to polylines.
Since I am forced to use R2008 it doesn't work.  It worked great in R2002 but as I said not now.  :x

;;;;8:18 AM 05/09/2008 theexchange
;;The user selects a line, arc or polyline and then several lines, arcs or polylines and then the function joins all that touch into one polyline.
(defun c:JP (/ EntType SS)
  (princ "\nSelect lines, arcs or polylines to be joined into a polyline.")
  (if (setq SS (ssget))
    (progn
      (setq EntType (cdr (assoc 0 (entget (ssname SS 0)))))
      (if (or (= EntType "LINE")(= EntType "ARC"))
        (command ".PEDIT" SS "Y" "J" SS "" "X")
      )
      (if (or (= EntType "POLYLINE")(= EntType "LWPOLYLINE"))
        (command ".PEDIT" SS "J" SS "" "X")
      )
    )
    (princ "\nNo lines, arcs or polylines selected.")
  )
  (princ)
)

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Join Lines to Polylines
« Reply #1 on: August 20, 2009, 05:44:10 PM »
Perhaps:

Code: [Select]
(defun c:jp (/ ope ss)
  (setq ope (getvar "PEDITACCEPT"))
  (if (setq ss (ssget '((0 . "ARC,*POLYLINE,LINE"))))
    (progn
      (setvar "PEDITACCEPT" 1)
      (command "_.pedit" "_M" ss "" "_J" "" "")))
  (setvar "PEDITACCEPT" ope)
  (princ))

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Join Lines to Polylines
« Reply #2 on: August 20, 2009, 10:10:00 PM »
Code: [Select]
(defun c:JP (/ ss)
  (and (setq ss (ssget ":L" '((0 . "ARC,*POLYLINE,LINE"))))
       (if (zerop (getvar "peditaccept"))
         (command "_.pedit" "_m" ss "" "_y" "_j" "" "")
         (command "_.pedit" "_m" ss "" "_j" "" "")
       ) ;_ if
  ) ;_ and
  (princ)
) ;_ defun

don't have to change any variables & objects on locked layers are ignored.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Join Lines to Polylines
« Reply #3 on: August 21, 2009, 06:47:24 AM »
Much better  :wink:

Chris

  • Swamp Rat
  • Posts: 547
Re: Join Lines to Polylines
« Reply #4 on: August 21, 2009, 07:52:49 AM »
Code: [Select]
(defun c:JP (/ ss)
  (and (setq ss (ssget ":L" '((0 . "ARC,*POLYLINE,LINE"))))
       (if (zerop (getvar "peditaccept"))
         (command "_.pedit" "_m" ss "" "_y" "_j" "" "")
         (command "_.pedit" "_m" ss "" "_j" "" "")
       ) ;_ if
  ) ;_ and
  (princ)
) ;_ defun

don't have to change any variables & objects on locked layers are ignored.
please forgive my ignorance, but what is the : in front of the L for?  and wouldn't it work better if selection method wasn't specified?
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Join Lines to Polylines
« Reply #5 on: August 21, 2009, 07:56:43 AM »
:L means ignore objects on locked layers  :-)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Join Lines to Polylines
« Reply #6 on: August 21, 2009, 08:37:37 AM »
selection method? are you talking about the filter in ssget?

Code: [Select]
(defun c:JP (/ ss)
  (and (setq ss (ssget ":L" '((0 . "ARC,*POLYLINE,LINE"))))
       (if (zerop (getvar "peditaccept"))
         (command "_.pedit" "_m" ss "" "_y" "_j" "" "")
         (command "_.pedit" "_m" ss "" "_j" "" "")
       ) ;_ if
  ) ;_ and
  (princ)
) ;_ defun

don't have to change any variables & objects on locked layers are ignored.
please forgive my ignorance, but what is the : in front of the L for?  and wouldn't it work better if selection method wasn't specified?
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Join Lines to Polylines
« Reply #7 on: August 22, 2009, 03:55:11 PM »
It appears that Chris mistook the :L for Last selection method when in fact it is as Lee said "Reject Locked Layers".
Nice one Alan.
I've reached the age where the happy hour is a nap. (°Ώ°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Join Lines to Polylines
« Reply #8 on: August 22, 2009, 03:57:49 PM »
It appears that Chris mistook the :L for Last selection method when in fact it is as Lee said "Reject Locked Layers".
Nice one Alan.

Thanks Alan.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Chris

  • Swamp Rat
  • Posts: 547
Re: Join Lines to Polylines
« Reply #9 on: August 24, 2009, 07:51:34 AM »
It appears that Chris mistook the :L for Last selection method when in fact it is as Lee said "Reject Locked Layers".
Nice one Alan.

I get it, it's one of those undocumented things. (or if it is documented, could someone please point it out?)
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Join Lines to Polylines
« Reply #10 on: August 24, 2009, 07:58:03 AM »
Check out Page 8 of this from AU - quite interesting. :-)

« Last Edit: August 24, 2009, 08:13:25 AM by Lee Mac »

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Join Lines to Polylines
« Reply #11 on: August 24, 2009, 08:11:14 AM »
Check out Page 8 of this from AU - quite interesting:


Thanks
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

POCKETS

  • Guest
Re: Join Lines to Polylines
« Reply #12 on: August 24, 2009, 08:14:57 AM »
My thanks to one and all
Pockets

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Join Lines to Polylines
« Reply #13 on: August 24, 2009, 08:16:42 AM »
Check out Page 8 of this from AU - quite interesting:


Thanks

My thanks to one and all
Pockets

Not a problem guys, you're welcome   8-)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Join Lines to Polylines
« Reply #14 on: August 24, 2009, 08:55:02 AM »
here's some of them i had in a text file
Quote
    *  (ssget "_:S") - selecting a single object
    * (ssget "_:E") - selecting all objects crossing the selection box (can be also combined to e.g. (ssget "_:E:S")
    * (ssget "_:N") - selecting objects including nested/child objects - e.g. with block references
    * (ssget "_:D") - duplicate objects counted separately (2x selected object = 2 selections)
    * (ssget "_:L") - stops users from selecting objects on locked layers
    * (ssget "_:P") - rejects selection of viewports
    * (ssget "+.") - allows window selection even in the single selection mode - (ssget "+.:E:S") (may not work in localized versions)




Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Crank

  • Water Moccasin
  • Posts: 1503
Re: Join Lines to Polylines
« Reply #15 on: August 24, 2009, 02:44:39 PM »
You can add this to your list:
Quote
:N Call ssnamex for additional information on container blocks and transformation matrices for any entities selected during the ssget operation. This additional information is available only for entities selected through graphical selection methods such as Window, Crossing, and point picks. Unlike the other object selection methods, :N may return multiple entities with the same entity name in the selection set. For example, if the user selects a subentity of a complex entity such as a BlockReference, PolygonMesh, or old style polyline, ssget looks at the subentity that is selected when determining if it has already been selected. However, ssget actually adds the main entity (BlockReference, PolygonMesh, and so on) to the selection set. The result could be multiple entries with the same entity name in the selection set (each will have different subentity information for ssnamex to report).

:R Allows entities in a long transaction to be selected.

:U Enables subentity selection. Cannot be combined with the duplicate (":D") or nested (":N") selection modes. In this mode, top-level entities are selected by default, but the user can attempt to select subentities by pressing the CTRL key while making the selection. This option is supported only with interactive selections, such as window, crossing, and polygon. It is not supported for all, filtered, or group selections.

:V Forces subentity selection. Treats all interactive, graphic selections performed by the user as subentity selections. The returned selection set contains subentities only. This option cannot be combined with the duplicate (":D") or nested (":N") selection modes. This option is supported only with interactive selections, such as window and crossing. It is not supported for all, filtered, or group selections.
Vault Professional 2023     +     AEC Collection

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Join Lines to Polylines
« Reply #16 on: August 24, 2009, 06:49:38 PM »
Thanks Crank - never heard of half of those!   :lol:

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Join Lines to Polylines
« Reply #17 on: August 24, 2009, 07:09:45 PM »
nice crank, i added those to my ssget options txt file.
we're still missing "_F".
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Join Lines to Polylines
« Reply #18 on: August 24, 2009, 09:41:55 PM »
Here is my text file, well part of it. :evil:
Code: [Select]
SSGET

the underscore (_) is needed with W, F, WP, :S but not with X, A, C, CP, I, L, P, :E ...

(ssget '(2 2))
Create a selection set of the object passing through (2,2):
                                                                                              
+.  The undocumented “+.” mode forces (ssget) to remain in “point” mode, similar to
    setting PickAuto to 0.... the "+." puts (ssget) into "point" mode. It helps the ":S"
    single-mode act just like (entsel) by avoiding implied selection windows.

A  All like "X" but filters frozen out
   Selects all objects on thawed layers.

B  Box
   Selects all objects inside or crossing a rectangle specified by two points. If
   the rectangle's points are specified from right to left, Box is equivalent to
   Crossing. Otherwise, Box is equivalent to Window.

C  Crossing  Simular to Window selection
   Selects objects within and crossing an area defined by two points. A crossing
   selection is displayed as dashed or otherwise highlighted to differentiate it
   from window selection. Specifying the corners from right to left creates a
   crossing selection. *** (Specifying the corners from left to right creates a window
   selection.)  (ssget "_C" '(0 0) '(1 1))
   Caution: the area must be on the screen for this to work properly - CAB
  
CP Crossing Polygon
   Selects objects within and crossing a polygon defined by specifying points. The
   polygon can be any shape but cannot cross or touch itself. AutoCAD draws the
   last segment of the polygon so that it is closed at all times. CPolygon is not
   affected by the PICKADD system variable.
   (ssget "_CP" '((1 1)(3 1)(5 2)(2 4)))
   Example with filters (ssget "_CP" '(Point list) '(Filter List))
   (setq ss (ssget "_CP" '((0 0)(10 0)(10 10)(0 10)) '((0 . "INSERT") (66 . 1))  ))
   Caution: the area must be on the screen for this to work properly - CAB
   (vl-cmdf "._zoom" "_E") ; Extents
  
:D Duplicates OK, else duplicates are ignored

:E Everything in aperture
   Everything within the cursor's object selection pickbox.

F Fence
  Selects all objects crossing a selection fence. The Fence method is similar to
  CPolygon except that AutoCAD does not close the fence, and a fence can cross
  itself. Fence is not affected by the PICKADD system variable.

G Groups
  Selects all objects within a specified group.

I Implied
  Implied selection (objects selected while PICKFIRST is in effect).

L Last
  Last visible object added to the database
 
:L Rejects locked layers

M  Multiple
   Specifies multiple points without highlighting the objects, thus speeding up
   the selection process for complex objects. The Multiple method also selects two
   intersecting objects if the intersection point is specified twice.
 
:N Nested
   Call ssnamex for additional information on container blocks and transformation
   matrices for any entities selected during the ssget operation. This additional
   information is available only for entities selected via graphical selection
   methods such as Window, Crossing, and point picks.
  
   Unlike the other object selection methods, :N may return multiple entities with
   the same entity name in the selection set. For example, if the user selects a
   subentity of a complex entity such as a BlockReference, PolygonMesh, or old
   style polyline, ssget looks at the subentity that is selected when determining
   if it has already been selected. However,  ssget actually adds the main entity
   (BlockReference, PolygonMesh, etc.) to the selection set. The result could be
   multiple entries with the same entity name in the selection set (each will have
   different subentity information for ssnamex to report).

P  Previous
   Selects the most recent selection set. The Previous selection set is cleared by
   operations that delete objects from the drawing. AutoCAD keeps track of whether
   each selection set was specified in model space or paper space. The Previous
   selection set is ignored if you switch spaces.

:P Rejects Viewport

:R Allows entities in a long transaction to be selected.

:S Force single object selection only

:U Enables subentity selection - 2006+
Cannot be combined with the  duplicate (":D") or nested (":N")  selection modes.
In this  mode, top-level  entities are  selected by  default, but  the user  can
attempt  to  select  subentities  by pressing  the  CTRL  key  while making  the
selection. This option  is supported only  with interactive selections,  such as
window, crossing, and polygon. It is  not supported for all, filtered, or  group
selections.

:V Forces subentity selection - 2006+
Treats all interactive,  graphic selections performed  by the user  as subentity
selections. The returned  selection set contains  subentities only. This  option
cannot be combined with the  duplicate (":D") or nested (":N")  selection modes.
This option is  supported only with  interactive selections, such  as window and
crossing. It is not supported for all, filtered, or group selections.

W  Window
   Selects all objects completely inside a rectangle defined by two points.
   Specifying the corners from left to right creates a window selection.
   (Specifying the corners from right to left creates a crossing selection.)

WP Window Polygon
   Selects objects completely inside a polygon defined by points. The polygon can
   be any shape but cannot cross or touch itself. AutoCAD draws the last segment of
   the polygon so that it is closed at all times. WPolygon is not affected by the
   PICKADD system variable.

X  Extended search (search whole database)
   Entire database. If you specify the X selection method and do not provide a
   filter-list, ssget selects all entities in the database, including entities on
   layers that are off, frozen, and out of the visible screen.
  
   Also at the command prompt "Select objects:" you can enter
   Add, Remove, Undo,

:U Enables subentity selection. Cannot be combined with the duplicate (":D") or
   nested (":N") selection modes. In this mode, top-level entities are selected by
   default, but the user can attempt to select subentities by pressing the CTRL key
   while making the selection. This option is supported only with interactive
   selections, such as window, crossing, and polygon. It is not supported for all,
   filtered, or group selections.

:V Forces subentity selection. Treats all interactive, graphic selections
   performed by the user as subentity selections. The returned selection set
   contains subentities only. This option cannot be combined with the duplicate
   (":D") or nested (":N") selection modes. This option is supported only with
   interactive selections, such as window and crossing. It is not supported for
   all, filtered, or group selections.

Systen Var
  PICKADD controls whether subsequent selections replace the current selection set or add to it.
I've reached the age where the happy hour is a nap. (°Ώ°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Join Lines to Polylines
« Reply #19 on: August 24, 2009, 09:44:14 PM »
Note on the :N flag, can't remember but it does not work in all versions of ACAD, should have recorded that.
It's here in the swamp somewhere. 8-)
I've reached the age where the happy hour is a nap. (°Ώ°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Join Lines to Polylines
« Reply #20 on: August 24, 2009, 10:03:50 PM »
that's what i'm talking about. you can always count on Alan (not me) to provide well documented info. :)

thanks Alan.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Join Lines to Polylines
« Reply #21 on: August 25, 2009, 06:30:51 AM »
Thanks Alan!  8-)

Definitely gonna keep hold of that one!  :-)

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Join Lines to Polylines
« Reply #22 on: August 25, 2009, 06:37:51 AM »
Just been studying it, and I'm not too sure on the ":R" mode - what are entities in long transactions?   :?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Join Lines to Polylines
« Reply #23 on: August 25, 2009, 09:00:06 AM »
I can't explain it, xRef mumbo jumbo. 8-)
But go here :
http://dml.chania.teicrete.gr/mathimata/Simeiwseis/Cad/AutoCAD%202000%20Migration%20Guide.pdf
Search on long transaction
I've reached the age where the happy hour is a nap. (°Ώ°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Join Lines to Polylines
« Reply #24 on: August 25, 2009, 09:04:40 AM »
Thanks Alan,

That explains it... not that I could understand too much  :ugly:

KewlToyZ

  • Guest
Re: Join Lines to Polylines
« Reply #25 on: August 25, 2009, 10:45:47 AM »
Much more elegant than this.

Code: [Select]
(defun c:join (/     a    b ai    va    vb    dst1 dst2  a1
       b1    a2    b2 ent1  ent2  ce    end1 end2  dst3
       dst4  oldlst newlst
      )
  (princ "\nJoins two line entities.")
  (defun mid (w z)
    (list (/ (+ (car w) (car z)) 2) (/ (+ (cadr w) (cadr z)) 2))
  )
  (setq a (cadr (entsel "\nSelect first line: ")))
  (setq b (cadr (entsel "\nSelect second:")))
  (setq ai (mid a b))
  (setq va (ssget a))
  (setq vb (ssget b))
  (setq a1 (cdr (assoc 10 (entget (setq ent1 (ssname va 0))))))
  (setq b1 (cdr (assoc 11 (entget (ssname va 0)))))
  (setq a2 (cdr (assoc 10 (entget (setq ent2 (ssname vb 0))))))
  (setq b2 (cdr (assoc 11 (entget (ssname vb 0)))))
  (setq dst1 (distance ai a1))
  (setq dst2 (distance ai b1))
  (if (< dst1 dst2)
    (setq end1 b1)
    (setq end1 a1)
  )
  (setq dst3 (distance ai a2))
  (setq dst4 (distance ai b2))
  (if (< dst3 dst4)
    (setq end2 b2)
    (setq end2 a2)
  )
  (setq oldlst (entget ent1))
  (setq newlst (subst (cons 10 end1) (assoc 10 oldlst) oldlst))
  (setq newlst (subst (cons 11 end2) (assoc 11 newlst) newlst))
  (entdel ent2)
  (entdel ent1)
  (entmake (cdr newlst))
  ;(end)
)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Join Lines to Polylines
« Reply #26 on: August 25, 2009, 11:04:10 AM »
Much more elegant than this.

Code: [Select]
(defun c:join (/     a    b ai    va    vb    dst1 dst2  a1
       b1    a2    b2 ent1  ent2  ce    end1 end2  dst3
       dst4  oldlst newlst
      )
  (princ "\nJoins two line entities.")
  (defun mid (w z)
    (list (/ (+ (car w) (car z)) 2) (/ (+ (cadr w) (cadr z)) 2))
  )
  (setq a (cadr (entsel "\nSelect first line: ")))
  (setq b (cadr (entsel "\nSelect second:")))
  (setq ai (mid a b))
  (setq va (ssget a))
  (setq vb (ssget b))
  (setq a1 (cdr (assoc 10 (entget (setq ent1 (ssname va 0))))))
  (setq b1 (cdr (assoc 11 (entget (ssname va 0)))))
  (setq a2 (cdr (assoc 10 (entget (setq ent2 (ssname vb 0))))))
  (setq b2 (cdr (assoc 11 (entget (ssname vb 0)))))
  (setq dst1 (distance ai a1))
  (setq dst2 (distance ai b1))
  (if (< dst1 dst2)
    (setq end1 b1)
    (setq end1 a1)
  )
  (setq dst3 (distance ai a2))
  (setq dst4 (distance ai b2))
  (if (< dst3 dst4)
    (setq end2 b2)
    (setq end2 a2)
  )
  (setq oldlst (entget ent1))
  (setq newlst (subst (cons 10 end1) (assoc 10 oldlst) oldlst))
  (setq newlst (subst (cons 11 end2) (assoc 11 newlst) newlst))
  (entdel ent2)
  (entdel ent1)
  (entmake (cdr newlst))
  ;(end)
)

mmm, Glue
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox