Source MTEXT <--- From here , to here --->Attribute block on the same drawing.
If that is the case then we wont be needing the clipboard when using lisp program with script. We can add more filter to select the MTEXT, like layers. even knowing the height of the MTEXT would help
Try this code
(defun c:demo (/ theMtextAtAGivenCoordinate theAttributeBlock i)
(if (and
(setq theMtextAtAGivenCoordinate
(ssget "_X"
'((0 . "MTEXT") (10 1551.0 22.00 0.0))))
(setq theMtextAtAGivenCoordinate
(ssname theMtextAtAGivenCoordinate 0))
(setq theMtextAtAGivenCoordinate
(cdr (assoc 1 (entget theMtextAtAGivenCoordinate))))
(setq theAttributeBlock
(ssget "_X" '((0 . "INSERT")
(66 . 1) (2 . "FR_ATTR-XX")))))
(repeat (setq i (sslength theAttributeBlock))
(foreach atb
(vlax-invoke
(vlax-ename->vla-object
(ssname theAttributeBlock
(setq i (1- i))))
'GetATtributes)
(if (eq (vla-get-tagstring atb) "FEUILLET")
(vla-put-textstring atb
theMtextAtAGivenCoordinate)))
)
)
)
The theMtextAtAGivenCoordinate variable initial value if not nil is a selection set.
There are a couple of ways to to a selection using a point, one is shown on the code above ("X"), another is using "C" and a point list
(setq theMtextAtAGivenCoordinate
(ssget "C" '(1551.0 22.00 0.0) '(1552.0 50.00 0.0)
'((0 . "MTEXT") )))
problem is only objects visible in the drawing area at the time of selection will be selected by this method.
(nentselp '(1551.00 22.00))
but this will depend if the part of the object is at a given point, though one can increase the size of pickbox for a bigger range.
........
AND back again to ssget "_X" , you can add range filter to make "X" behave like "C" minus the restriction of being visible in the drawing area
(setq ss (ssget "_X" '((0 . "MTEXT") (-4 . ">=,>=,*") (10 1551.0 22.0 0.0)(-4 . "<=,<=,*")
(10 1600.0 50.0 0.0) )))
And you can even add the layer name there (8 . "MTEXTLAYERName")
now for the script
(c:demo) <---or whatever you name the lisp program
_Qsave
_close
Play around with the code, and see what works for you.
Happy coding.
pBe