Exchange Forum > AutoLISP and Visual LISP
Help joining polylines
Page 1 of 2
1 2
Help joining polylines

#1

Randall
Join Date:
03-21-2008
We have been using this JPL function for a while to join polylines with lines and arcs. Is there any way it can be revised so that it automatically joins all lines, arcs and polylines that are on the same layer that can be joined?
Randall
 
Code:
(defun c:JPL (/ enttype selset)
  (princ "\nSelect lines, arcs or polylines to be joined into a polyline.")
  (if (setq selset (ssget))
    (progn
      (setq enttype (cdr (assoc 0 (entget (ssname selset 0)))))
      (cond
        ((or (= enttype "LINE")(= enttype "ARC"))
          (command "_pedit" selset "_y" "_j" selset "" "_x")
        )
        ((or (= enttype "LWPOLYLINE")(= enttype "POLYLINE"))
          (command "_pedit" selset "_j" selset "" "_x")
        )
      )
    )
  )
  (princ)
)
Help joining polylines

#2

alanjt
Join Date:
04-05-2008
Try this on for size:
Code:
(defun c:JPL (/ enttype selset AT:entsel GetLyr obj_layer)
 
(defun AT:entsel ( msg / x) 
  (while (not (setq x (car (entsel msg)))) 
    (princ "\nMissed, keep trying.")) x)
(defun GetLyr (ent) 
  (cdr (assoc 8 (entget ent))))
 
(setq obj_layer (GetLyr (AT:entsel "\nSelect object on desired layer: ")))
 
  (if (setq selset (ssget "_X" (list (cons '0 "LINE,*POLYLINE,ARC")(cons '8 obj_layer))))
    (progn
      (if (equal (getvar 'peditaccept) 1)
        (command "pedit" "m" selset "" "j" "" "")
        (command "pedit" "m" selset "" "y" "j" "" "")
      );if
    );progn
    (prompt (strcat "\nSorry, nothing on layer \"" obj_layer "\" to work with."))
  );if
  (princ)
);defun
 
I took into account the peditaccept variable and added a while for your entsel for missed picks.
Help joining polylines

#3

Randall
Join Date:
03-21-2008
alanjt,
I appreciate your program. It is already easier and better than ours. Can your program be revised to cycle through all the layers for me, to make it faster for drawings with many layers? I am just learning lsp and every time I try to revise something I really mess it up.
Randall
Help joining polylines

#4

alanjt
Join Date:
04-05-2008
Quote:
alanjt, 
I appreciate your program. It is already easier and better than ours. Can your program be revised to cycle through
all the layers for me, to make it faster for drawings with many layers? I am just learning lsp and every time I try to
revise something I really mess it up. 
Randall
Little rewrite, just have to get a list of layers, then cycle through each layer, select what you want (lines, plines, arcs) and then run pedit.
 
Code:
;Join All Lines
;will join all lines, arcs, plines on all layers (xref & frozen layers ignored)
;created by: alan thompson, 9.22.08
 
(defun c:JAL (/ selset GetNames layer_list)
(defun GetNames (/ data result)
  (while (setq data (tblnext "layer" (null data)))
    (if (zerop (logand 21 (cdr (assoc 70 data))))
      (setq result (cons (cdr (assoc 2 data)) result))
    );if
  );while
  (acad_strlsort result)
);defun
(setq layer_list (getnames))
 (foreach x layer_list
  (if (setq selset (ssget "_X" (list (cons '0 "LINE,*POLYLINE,ARC")(cons '8 x))))
    (progn
      (if (equal (getvar 'peditaccept) 1)
        (command "pedit" "m" selset "" "j" "" "")
        (command "pedit" "m" selset "" "y" "j" "" "")
      );if
      (setq selset nil)
    );progn
  );if
 );foreach
(princ (strcat "\nProcessed " (rtos (length layer_list) 2 0) " layers.\n"))
(princ layer_list)
(princ)
);defun
Help joining polylines

#5

Randall
Join Date:
03-21-2008
Alan,
I ran your JAL function on several old drawings that I have to work with, and it’s great. It makes these drawings so much easier to work with. Thanks for your help. I would have got stuck in a loop and unable to find my way out.
This is awesome beyond belief!
Randall
Help joining polylines

#6

alanjt
Join Date:
04-05-2008
Quote:
Alan, 
I ran your JAL function on several old drawings that I have to work with, and it’s great. It makes these drawings so
much easier to work with. Thanks for your help. I would have got stuck in a loop and unable to find my way out. 
This is awesome beyond belief! 
Randall 
No problem. Had some free time and thought I'd help.
Help joining polylines

#7

Flynn
Join Date:
07-24-2007
Alan,
Your "Join All Lines" routine it great! I can definitely see a need for this one.
Flynn
Help joining polylines

#8

alanjt
Join Date:
04-05-2008
Quote:
Alan, 
Your "Join All Lines" routine it great! I can definitely see a need for this one. 
Flynn 
Hey, thanks for the compliment; glad you like it.
Help joining polylines

#9

KyleMcClure
Join Date:
07-14-2008
Dude, you rock! Cool function. We love it at work.
Kyle
Help joining polylines

#10

alanjt
Join Date:
04-05-2008
Quote:
Dude, you rock! Cool function. We love it at work. 
Kyle 
Heck yeah, that's what I'm talking about. Thanks
Page 1 of 2
1 2