So, I've been using this routine for quite some time - been through several rewrites (original only let you select one layer). After my last rewrite to allow for multiple select to process several layers, I noticed a strange error. I never investigated it and would just limit my selections. today, I decided to figure out why I was receiving an invalid ssget list error. I finally found that I was somehow selecting an entity that nil'ed when dumping it's entity data with entget. I decided to change the 'check' to see if the object actually returns an error before checking it against a list of already processed layers.
Thought the find was really weird and thought I'd share.
Here's the problem version:
(defun c:MJL (/ ss)
;; Join all on selected object(s)' layer
;; Alan J. Thompson, 09.09.10
(if (setq ss (ssget "_:L"))
((lambda (i ctab / e la lst all)
(while (setq e (ssname ss (setq i (1+ i))))
(or (vl-position (cdr (setq la (assoc 8 (entget e)))) lst)
(and (setq lst (cons la lst))
(setq all (ssget "_X" (list '(0 . "ARC,LINE,LWPOLYLINE") ctab la)))
(if (eq (getvar 'peditaccept) 1)
(vl-cmdf "_.pedit" "_m" all "" "_J" "" "")
(vl-cmdf "_.pedit" "_m" all "" "_Y" "_J" "" "")
)
)
)
)
)
-1
(cons 410 (getvar 'ctab))
)
)
(princ)
)
and here's the rewrite I did today:
(defun c:MJL (/ pedit 4ten ss i l lst all)
;; Join all on selected object(s)' layer
;; Alan J. Thompson, 06.28.11
(if (setq pedit (eq (getvar 'PEDITACCEPT) 1)
4ten (if (eq (getvar 'CVPORT) 1)
(cons 410 (getvar 'CTAB))
(cons 410 "Model")
)
ss (ssget "_:L")
)
(repeat (setq i (sslength ss))
(if (and (setq l (assoc 8 (entget (ssname ss (setq i (1- i))))))
(not (vl-position l lst))
(setq all (ssget "_X"
(list '(0 . "ARC,LINE,LWPOLYLINE")
4ten
(car (setq lst (cons l lst)))
)
)
)
)
(if pedit
(vl-cmdf "_.pedit" "_m" all "" "_J" "" "")
(vl-cmdf "_.pedit" "_m" all "" "_Y" "_J" "" "")
)
)
)
)
(princ)
)