Hello All,
I try not to just ask for lisp routines, but I'm not sure how to write what I want or modify something similar I've found. Some direction would be great.
I'd like to move every object in modelspace to its own layer, maintaining its color/lineweight/etc.
I've found a nifty routine from Lee Mac (posted below), but it's got a couple of problems:
1.) I don't want it to assign a random color, but inherit the layer's properties from the object,
2.) it looks at the number of objects in the selection and prefixes the layer name with the appropriate amount of zeros, where I just want to prefix the layer name with 4 zeros; right now, if I run the routine and select all the objects, it'll assign a layer name like "3d004" if there's more than a hundred objects, but if I rerun the routine and select less than 10 objects, it'll move those objects to layers similar to "3d4". If an object's already on a "3d0000" layer, I don't want to ever assign it to another layer (so ignore objects that are already on a "3dxxxx" layer).
Can anyone offer some advice to get this done?
I appreciate it,
stu
(defun c:Solids2Layers ( / _padzeros a b e i l n p s )
(setq p "3d")
(defun _padzeros ( s l )
(if (< (strlen s) l) (_padzeros (strcat "0" s) l) s)
)
(if (setq s (ssget "_:L" '((0 . "*SOLID"))))
(progn
(setq
i (sslength s)
l (1+ (fix (/ (log i) (log 10))))
n 0
)
(repeat i
(setq e (entget (ssname s (setq i (1- i)))))
(entmod
(subst
(cons 8 (strcat p (_padzeros (itoa (setq n (1+ n))) l)))
(assoc 8 e)
e
)
)
)
(setq n 0)
(while (setq a (tblnext "LAYER" (null a)))
(if (wcmatch (setq b (cdr (assoc 2 a))) (strcat p "*"))
(entmod
(setq b (entget (tblobjname "LAYER" b))
b (subst (cons 62 (setq n (1+ (rem n 254)))) (assoc 62 b) b)
)
)
)
)
)
)
(princ)
)