OK, looking at this code,
http://www.theswamp.org/index.php?topic=20705.msg251590#msg251590there are some similarities. That code gets lines within rectangles. You want text within closed plines.
Here is the psudo code.
Get closed plines on a spacific layer in current space
Use the vertex points for a second ssget to get any mtext within the pline boundaries
If you find any mtext, hatch the pline
How is that for what you want to do?
What is the layer name for the closed pline.
What is the hatch pattern?
What is the hatch scale?
What is the hatch layer?
So looking at the routine I pointed to you would need to allow ssget to get ANY closed pline.
This already does that:
(setq ss (ssget '((0 . "LWPOLYLINE,POLYLINE") (-4 . "&") (70 . 1))))
So all you need to do is add the layer and eliminate the test for the rectangle.
Here is the layer added:
(setq ss (ssget '((8 . "[color=red]LayerName[/color]")(0 . "LWPOLYLINE,POLYLINE") (-4 . "&") (70 . 1))))
and this is the rectangle test (if (is_rectangle pts) so delete that line & the closing parens.
This line gets any LINES within the rectangle and you want MTEXT, so change this
(setq ss2 (ssget "f" pts (list '(0 . "LINE") (cons 8 lay))))
to this, deleting the layer filter & changing the Fence to Crossing Polygon
(setq ss2 (ssget "cp" pts (list '(0 . "MTEXT"))))
Get rid of this line:
(setq lay (vla-get-layer obj))
and this line
(setq lines (get_lines lst2 pts lay))
Remove sub functions:
make_line
get_lines
is_rectangle
Change the routine name to FindMText
Oh, change the prompt to:
(prompt "\nSelect Plines for Text Identification.")
Remove the delete lines code
;; got two lines for X so remove them
(vl-catch-all-apply '(lambda ()
(mapcar '(lambda (x) (vla-delete (vlax-ename->vla-object x))) lines)))
Remove the make lines function calls:
(make_line (car pts) (caddr pts) lay)
(make_line (cadr pts) (last pts) lay)
Now we have this:
(defun c:FindmText (/ ss lst obj pts lay ss2 lst2 lines)
(vl-load-com)
(defun group_on2 (InpLst / OutLst)
(while InpLst
(setq OutLst (cons (list (car InpLst) (cadr InpLst)) OutLst))
(setq InpLst (cddr InpLst))
)
OutLst
)
;; **** S T A R T H E R E ****
(prompt "\nSelect Plines for Text Identification.")
(setq ss (ssget '((8 . "[color=red]LayerName[/color]")(0 . "LWPOLYLINE,POLYLINE") (-4 . "&") (70 . 1))))
(if ss
(progn
(setq lst (mapcar 'vlax-ename->vla-object
(vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
(foreach obj lst
(setq pts (group_on2 (vlax-get obj 'coordinates)))
(progn
(setq lay (vla-get-layer obj))
(if (and
(setq ss2 (ssget "cp" pts (list '(0 . "MTEXT"))))
(setq lst2 (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss2))))
)
(progn
(command "-bhatch" "S" (vlax-vla-object->ename obj)
"" "P" "[color=red]ANSI31[/color]" "[color=red]100[/color]" "0" "")
)
)
)
)
)
)
(princ)
)
Notice that I added a command bhatch.
You will need to change the bhatch hatch name & scale
Also you will need to replace
LayerName in the ssget.