Here is the final version:
;;; Based on PJOIN.LSP v1.1 by Zoltan Toth
;;;
;;; Description:
;;; This program takes any number of LINES, ARCS and/or LWPOLYLINES,
;;; joins them into a single LWPOLYLINE if the objects are contiguous
;;; and reports number of joined objects.
;;;
;;; define program name & localize variables
(defun c:pjoin (/ sfirst sset ename etype i cnt)
;; get objects to join into a single LWPOLYLINE
(prompt "\nSelect first object:")
(setq sfirst nil)
(while (not (setq sfirst
(ssget "_:S" '((-4 . "<OR")
(0 . "LINE")
(0 . "LWPOLYLINE")
(0 . "ARC")
(-4 . "OR>")))))
(princ " Select LINE, LWPOLINE or ARC...")
)
(setq ename (ssname sfirst 0)) ;get name of first object
(redraw ename 3)
(prompt "\nSelect objects to join into a polyline:")
(while (not (setq sset
(ssget '((-4 . "<OR")
(0 . "LINE")
(0 . "LWPOLYLINE")
(0 . "ARC")
(-4 . "OR>")))))
(princ "Select LINE, LWPOLINE or ARC...")
)
(redraw ename 4)
(if (and sset sfirst)
(progn
(setq etype (cdr (assoc 0 (entget ename)))) ;get object type
(ssdel ename sset) ;correct report
;; if first object is a LWPOLYLINE ...
(if (= "LWPOLYLINE" etype)
;; then: join objects into LWPOLYLINE
(command "._PEDIT" ename "_J" sset "" "")
;; else: convert object and join them
(command "._PEDIT" ename "_Y" "_J" sset "" "")
)
;; check for deleted enames and report
(setq i -1 cnt 0)
(while (setq ename (ssname sset (setq i (1+ i))))
(or (entget ename) (setq cnt (1+ cnt))))
(prompt (strcat (itoa cnt) " joined, "
(itoa (- i cnt)) " left"))
)
(prompt "\nNo objects selected")
)
)
(princ "\nPJOIN - join contiguous plines, lines and arcs")
(princ)
Thanks for your help bye