Hi Steve, welcome to the forum
Try this...
The routine will print out the number of objects in the selection set based on your attribute name. I wasn't sure if the name of your attribute is the tag string or the text string so the program will look for both. I'm guessing that your blocks are in model space, but if they are in different layout tabs too the code can be modified to work with that. You can remove the (princ) line and add you code to modify the selection set.
Code:
(defun c:test ( / ss)
(vl-load-com)
; CREATE AN EMPTY SELECTION SET
(setq ss (ssadd))
; ITERATE THROUGH THE OBJECTS IN MODEL SPACE
(vlax-for blks (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
(if (and
(= (vla-get-ObjectName blks) "AcDbBlockReference")
(vlax-property-available-p blks 'Hasattributes)
)
(foreach att (append (vlax-invoke blks 'GetAttributes)(vlax-invoke blks 'GetConstantAttributes))
(if (or
(= (vla-get-TagString att) "MX_ATT")
(= (vla-get-TextString att) "MX_ATT")
)
(ssadd (vlax-vla-object->ename blks) ss) ; <<< ADD OBJECTS TO THE SELECTION SET
)
)
)
)
; PUT YOUR CODE HERE...
(princ (strcat "\nNumber of objects in the selection set: " (itoa (sslength ss))))
)