Perfect @pkenewell, thanks a lot.
Here's the working version. I don't know if I remember if there was a vla-get to get items that can be hatched. But for now this brute force method works.
(vl-load-com)
; Tharwat 18th Sept 2013
; Modified on 2022.12.12 by 3dwannab to hatch everything inside the block. Help over here: https://www.cadtutor.net/forum/topic/76450-hatch-objects-inside-a-block/
;; TO DO: Only hatch entities that can be hatched. Think there may be a vla-get for this. Not sure.
; https://www.cadtutor.net/forum/topic/46782-deleting-hatch-from-blocks/?do=findComment&comment=396412
(defun c:BKHatchAll_Solid (/ *error* acDoc blkn cnt ss1 var_cmdecho var_osmode)
(defun *error* (errmsg)
(and acDoc (vla-EndUndoMark acDoc))
(and errmsg
(not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*"))
(princ (strcat "\n<< Error: " errmsg " >>\n"))
)
(setvar 'cmdecho var_cmdecho)
(setvar 'osmode var_osmode)
)
(setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc))
(setq var_cmdecho (getvar "cmdecho"))
(setq var_osmode (getvar "osmode"))
(setvar 'cmdecho 0)
(setvar 'osmode 0)
(prompt "\nSelect blocks to hatch with solid hatch: ")
(if (setq ss1 (ssget '((0 . "INSERT"))))
(progn
(setq cnt 0)
(repeat (setq cnt (sslength ss1))
(setq cnt (1- cnt)
blkn (cons (vla-get-effectivename (vlax-ename->vla-object (_dxf -1 (entget (ssname ss1 cnt))))) blkn)
)
)
(setq blkn (_removedup blkn))
(foreach x blkn
(command "-bedit" x)
(command "_.-hatch" "_P" "_S" "_LA" "." "_advanced" "_associativity" "_yes" "" "_select" "_all" "" "")
(command "_.bsave")
(command "_.bclose")
(redraw)
)
(setvar 'cmdecho var_cmdecho)
)
)
(*error* nil)
(princ)
)
;; removes duplicate element from the list
(defun _removedup (l)
(if l
(cons (car l) (_removedup (vl-remove (car l) (cdr l))))
)
)
;;----------------------------------------------------------------------;;
;; _dxf
;; Finds the association pair, strips 1st element
;; args - dxfcode elist
;; Example - (_dxf -1 (entget (ssname (ssget) 0)))
;; Returns - <Entity name: xxxxxxxxxxx>
(defun _dxf (code elist)
(cdr (assoc code elist))
)
; (c:BKHatchAll_Solid)