@KerryBrown wrote:
....
;; select ALL the applicable hatches
....
;; convert the selection set to a list of ActiveX objects
....
;; make the layer (assume it doesn't exixts )
....
;; assign the HATCH layer to each object
....
;; set the color of each hatch object to 252
....
This is a situation in which a (command) function has advantages over the VLA-Property approach. The CHPROP command can change the Layer or the color or both of a whole selection all at once, rather than one at a time, and without the need to convert them to VLA objects, and with far fewer variables. Assuming the Layer does not yet exist [you can eliminate that line if it always will]:
(defun c:doit (/ ss)
(if (setq ss (ssget "X" '((0 . "HATCH") (2 . "SOLID"))))
(command ; then
"_layer" "_make" "HATCH" "_color" 252 "" ""
"_chprop" ss "" "_layer" "HATCH" "_color" "_bylayer" ""
); command
); if
(princ)
)
Or, if you want to assign the color 252 by color override on the objects, rather than by putting them on a Layer with that color, just this:
(defun c:doit (/ ss)
(if (setq ss (ssget "_X" '((0 . "HATCH") (2 . "SOLID"))))
(command "_chprop" ss "" "_color" 252 ""); then
); if
(princ)
)
If you know there will always be such Hatch patterns when you run it, you don't even need any variables at all. Back to the by-the-Layer's-color approach:
(defun c:doit ()
(command
"_layer" "_make" "HATCH" "_color" 252 "" ""
"_chprop" (ssget "_X" '((0 . "HATCH") (2 . "SOLID"))) "" "_layer" "HATCH" "_color" "_bylayer" ""
); command
(princ)
)
However, the VLA-Property approach will work on things in multiple spaces, whereas the CHPROP approach will work only on Hatch patterns in the current space. So if you might have such patterns in both Model and Paper space, or in different Paper space Layouts, don't do it with CHPROP.
Kent Cooper, AIA