How about pairing Layer names with their intended pattern names, and having one selection set of all Hatch patterns on Layers with appropriate names, and substituting patterns and scale and angle into each one's entity data, pulling the pattern from the list of pairings, rather than using a Hatchedit command? Then you don't need a separate selection for each Layer, with its separate (if) function in case there are no Hatch patterns on that Layer, or if that Layer doesn't exist. It doesn't need to handle SOLID differently from other patterns.
Does this work [untested]?
(defun C:H-C (/ pairs ss n hatch edata)
(setq pairs '(("TEST1" "ANSI31") ("TEST2" "SOLID") ("TEST3" "ANSI33") ("TEST4" "DASH") ("TEST5" "ANSI33") ("TEST6" "ANSI31")))
(if (setq ss (ssget "_X" '((0 . "HATCH") (8 . "TEST#*")))); all Hatch patterns on Layers with such names
(repeat (setq n (sslength ss)); then
(setq
hatch (ssname ss (setq n (1- n))); the Hatch object
edata (entget hatch); its entity data
edata (subst (cons 2 (cadr (strcase (assoc 8 edata)) pairs)) (assoc 2 edata) edata); pattern
edata (subst '(41 . 1.0) (assoc 41 edata) edata); scale
edata (subst '(52 . 0.0) (assoc 52 edata) edata); angle
); setq
(entmod edata)
); repeat
); if
(princ)
); defun
[I used all-capitals Layer names in the 'pairs' list, and (strcase) in pulling the Layer names from entity data, because there it's case-sensitive. The (8 . "TEST#*") Layer filter in the (ssget) function is not case-sensitive. It uses "TEST#*" to allow for Layer names into more than one digit at the end. Using "TEST##" would not see those with only one digit, or three if it comes to that, but "TEST#*" would see something like "TEST7demo". If there's any need to avoid complications like that, they can be accounted for.
But maybe that's all moot, assuming those Layer names are not what you will really have. You can use:
(8 . "ThisLayer,ThatLayer,LayerA,LayerB,Whatever")
with all "real" Layer names comma-delimited in one string.]
EDIT: And it wouldn't be much work to have different scale factors and/or angles for the patterns on each Layer if needed -- they can be added to the 'pairs' sub-lists, and pulled in a similar way as the pattern name for substituting into entity data.
Kent Cooper, AIA