Lee,
I have modified your code a bit:
; The following code was modified from code posted by Lee Mac at: http://www.theswamp.org/index.php?topic=35517.msg407350#msg407350
; This code was based of original code by Chris Wade
(defun Lay0s ( / i ss e el d e f )
(if (setq i -1 ss (ssget "_X" '((8 . "0"))))
(while (setq e (ssname ss (setq i (1+ i)))) (setq el (entget e))
(setq d (cond ( (cdr (assoc 2 el)) ) ("Misc"))
e (cond ( (cdr (assoc 0 el)) ) ("MiscTyp"))
f (cond ( (cdr (assoc 5 el)) ) ("MiscOb"))
)
(entmod (subst (cons 8 (vl-string-translate ":;*?,<>/\\|." "$$$$$$$$$$$" (strcat "WAS0 - " d "-" e "-" f))) (assoc 8 el) el))
)
)
(princ)
)
I am going to use this code with the new ScriptPro that was posted on AutoDesk labs today, which will simply resume if AutoCAD crashes, so I think that I can risk AutoCAD crashing. But looking into it, I think the conditions that caused CAD to crash with having entmod crash AutoCAD is if there are chracters in the layer name that are not valid, which is the reason for the vl-string-translate, so that it will remove any invalid characters from the layer name. I know I had problems with this when manually creating the layer using the layer command, which was the reason for the string substitution.
By the way this code is substantially faster:
700 Objects
Old code: 7 seconds
Code above: ~0.25 seconds
Thank you Lee