@dani-perez wrote:
....
The idea will be any others that be a boundary, such as plines, circles, boundaries, Ellipses, Splines, or Blocks you know.
Then I select the text and the object and the text will move to its center.
....
This seems to do that [adding the possibility of Mtext], whether you select one thing in addition to a Text/Mtext object, or multiple things as in the Lines earlier. But be aware of a few things:
If there are more than one Text/Mtext objects in the selection, the first one it "sees" will be Moved, and the other(s) will become part of the "shape"-defining collection of other objects.
Since it uses bounding boxes, in some cases you can get slightly different results than you might expect. The bounding box of Mtext includes the full width of its defining box [if other than zero], whether or not the content in it uses that full width. [There are routines around to pull the defining box in to match the width of the content, if you need to do that.] And Splines can sometimes have a bounding box that extends farther than their visible shape. And Blocks at other-than-zero rotation can get a bigger bounding box than they deserve, depending on their shape. For example, here's:

a wall-mounted toilet Block, at the left at zero rotation, and at the right at 45 degrees. The dashed red is its bounding box on the left [what you would expect] -- it is not part of the Block, which is only the white and grey parts. On the right, the yellow is the Block's bounding box -- note that it "reaches out" to the extents of the rotated virtual bounding box [the darker red] of the Block as if that were actually part of the Block's contents, so the yellow bounding box goes beyond the visible extents of the rotated Block itself.
But given those caveats, try this:
(defun C:TCW ; = Text Centered Within other object(s)
(/ ss sst txt txtLL txtUR n ent LL UR otherLL otherUR)
(prompt "\nTo Move Text/Mtext to middle of other object(s), collectively")
(setq
ss (ssget)
sst (ssget "_P" '((0 . "*TEXT")))
txt (ssname sst 0); first Text/Mtext object in selection
); setq
(ssdel txt ss); take Text/Mtext object out of overall selection
(vla-getboundingbox (vlax-ename->vla-object txt) 'minpt 'maxpt)
(setq
txtLL (vlax-safearray->list minpt)
txtUR (vlax-safearray->list maxpt)
); setq
(repeat (setq n (sslength ss)); other object's/objects' extents
(setq ent (ssname ss (setq n (1- n))))
(vla-getboundingbox (vlax-ename->vla-object ent) 'minpt 'maxpt)
(setq
LL (vlax-safearray->list minpt)
UR (vlax-safearray->list maxpt)
otherLL (if otherLL (mapcar 'min otherLL LL) LL)
otherUR (if otherUR (mapcar 'max otherUR UR) UR)
); setq
); repeat
(command "_.move" txt ""
"_none" (mapcar '/ (mapcar '+ txtLL txtUR) '(2 2 2)); from midpoint of Text/Mtext
"_none" (mapcar '/ (mapcar '+ otherLL otherUR) '(2 2 2)); to midpoint of other(s)
); command
(princ)
); defun
Kent Cooper, AIA