@Anonymous hi,
here is a command MT2BL to integrate a mtext into block 😀 but it has it's conditions:
You need to define the block with one attribute and what that means?
say you have a block symbol (like in your pic) open it in bedit and add a tag attribute with what ever tag name you choose and place it on base point 0,0,0. set a reasonable height and angle.
run MT2BL command:
it start by echoing select object(s) ... you select the block + the text\mtext in one shoot. the function filter your selection so you can choose only 2 objects a block and a text but you'll be alerted if you fail meaning selecting 2 texts or 2 blocks is forbidden.
as you can understand MT2BL does not care about the block name or the attribute tag name all it cares is the block contains only one attribute.
your selection will be replaces by a new insert 😀
MT2BL copies these properties from the mtext to the attribute:
layer, text style, height, angle and of course the position.
a minor inaccuracy in attribute position may occur due to a difference in text alignment.
enjoy
Moshe
; integrate mtext into block
(defun c:mt2bl (/ count_attdef _dxfCode textCentroid textBottomLeft ; local functions
ss elist0 elist1 elist2 tmp bname n)
; return number of attributes definition in block
(defun count_attdef (elist / ctr)
(setq bname (cdr (assoc '2 elist)))
(setq ctr 0)
(vlax-for AcDbEntity (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) bname)
(if (eq (vla-get-objectName AcDbEntity) "AcDbAttributeDefinition")
(setq ctr (1+ ctr))
)
(vlax-release-object AcDbEntity)
); vlax-for
ctr
); count_attdef
; annonymous function
(setq _dxfCode (lambda (c e) (cdr (assoc c e))))
(defun textCentroid (elist / AcDbEntity MinPoint MaxPoint)
(setq AcDbEntity (vlax-ename->vla-object (cdar elist)))
(vla-getboundingBox AcDbEntity 'MinPoint 'MaxPoint)
(vlax-release-object AcDbEntity)
(setq pt (mapcar '(lambda (x0 x1) (/ (+ x0 x1) 2)) (vlax-safearray->list MinPoint) (vlax-safearray->list MaxPoint)))
); mtextCentroid
(defun textBottomLeft (elist / AcDbEntity MinPoint MaxPoint)
(setq AcDbEntity (vlax-ename->vla-object (cdar elist)))
(vla-getboundingBox AcDbEntity 'MinPoint 'MaxPoint)
(vlax-release-object AcDbEntity)
(vlax-safearray->list MinPoint)
); textBottomLeft
; here start c:mt2bl
(setvar "cmdecho" 0)
(command "._undo" "_begin")
(setq savAttdia (getvar "attdia"))
(setq savAttreq (getvar "attreq"))
(setvar "attdia" 0)
(setvar "attreq" 1)
(cond
((not (setq ss (ssget '((0 . "insert,text,mtext"))))) ; select an insert and a text\mtext
); case
((< (sslength ss) 2)
(vlr-beep-reaction)
(prompt "\ntoo few objects selected.")
); case
((> (sslength ss) 2)
(vlr-beep-reaction)
(prompt "\ntoo many objects selected.")
); case
((not
(or
(and
(wcmatch (cdr (assoc '0 (setq elist0 (entget (ssname ss 0))))) "INSERT")
(wcmatch (cdr (assoc '0 (setq elist1 (entget (ssname ss 1))))) "TEXT,MTEXT")
)
(and
(wcmatch (cdr (assoc '0 (setq elist1 (entget (ssname ss 1))))) "INSERT")
(wcmatch (cdr (assoc '0 (setq elist0 (entget (ssname ss 0))))) "TEXT,MTEXT")
)
); or
); not
(vlr-beep-reaction)
(prompt "\nrequire 1 insert and 1 text.")
); case
( t
(if (eq (cdr (assoc '0 elist1)) "INSERT")
(setq tmp elist0 elist0 elist1 elist1 tmp)
)
(setq n (count_attdef elist0))
(cond
((= n 0)
(vlr-beep-reaction)
(prompt "\nblock selected has no attributes.")
)
((> n 1)
(vlr-beep-reaction)
(prompt "\nblock selected has too many attributes.")
)
( t
(command "._insert" bname (trans (_dxfCode 10 elist0) 0 1) "xyz" (_dxfCode 41 elist0) (_dxfCode 42 elist0)
(_dxfCode 43 elist0) (angtos (_dxfCode 50 elist0) 0) (cdr (assoc '1 elist1)))
(setq elist2 (entget (entnext (entlast))))
(setq elist2 (subst (cons '8 (_dxfCode 8 elist1)) (assoc '8 elist2) elist2)) ; set layer
(setq elist2 (subst (cons '7 (_dxfCode 7 elist1)) (assoc '7 elist2) elist2)) ; set text style
(setq elist2 (subst (cons '40 (_dxfCode 40 elist1)) (assoc '40 elist2) elist2)) ; set height
(setq elist2 (subst (cons '50 (_dxfCode 50 elist1)) (assoc '50 elist2) elist2)) ; set angle
(cond
((or
(not (cdr (assoc '11 elist2)))
(equal (cdr (assoc '11 elist2)) '(0.0 0.0 0.0))
)
(entmod (subst (cons '10 (textBottomLeft elist1)) (assoc '10 elist2) elist2)) ; position attribute by dxf10
)
( t
(entmod (subst (cons '11 (textCentroid elist1)) (assoc '11 elist2) elist2)) ; position attribute by dxf11
)
); cond
(entdel (cdar elist0))
(entdel (cdar elist1))
); case
); cond
); case
); cond
(setvar "attdia" savAttdia)
(setvar "attreq" savAttreq)
(command "._undo" "_end")
(setvar "cmdecho" 1)
(princ)
); c:mt2bl