Automatically Have Background In Typed Text In MText

Automatically Have Background In Typed Text In MText

omorah
Collaborator Collaborator
719 Views
5 Replies
Message 1 of 6

Automatically Have Background In Typed Text In MText

omorah
Collaborator
Collaborator

If possible, either with a variable setting, or otherwise, I would like to have MText texts, created with automatic background masking. That is, whenever I create an MText, type any text in the MText, the texts will automatically have background.

 

Would this be possible to have this as a style to  add in the office template? Sometimes, I would need to add background masking in existing drawings, add a background masking to one MText, and Match Property to the rest, In this case, the rest of the MText changes to match the Alignment of the source MText.

 

Cheers

0 Likes
720 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant

It doesn't appear to be a setting that could be a standard -- I don't use masking, generally, but I don't see a way to get it except after the fact -- applied to a completed Mtext object.

 

Presumably the MTEXT command could have its definition altered to immediately do the following upon completion of an Mtext.  This [in simplest terms and minimally tested] does it to a selected existing one:

(defun C:MTM (/ edata) ; = MText Mask
  (setq edata (entget (car (entsel "\nSelect Mtext to Mask: "))))
  (entmod (append edata '((90 . 3) (45 . 1.5))))
)

It could also be adjusted to allow selection of multiple existing Mtexts to mask all at once.

Kent Cooper, AIA
0 Likes
Message 3 of 6

omorah
Collaborator
Collaborator

@Kent1Cooper wrote:

It doesn't appear to be a setting that could be a standard -- I don't use masking, generally, but I don't see a way to get it except after the fact -- applied to a completed Mtext object.

 

Presumably the MTEXT command could have its definition altered to immediately do the following upon completion of an Mtext.  This [in simplest terms and minimally tested] does it to a selected existing one:

 

(defun C:MTM (/ edata) ; = MText Mask
  (setq edata (entget (car (entsel "\nSelect Mtext to Mask: "))))
  (entmod (append edata '((90 . 3) (45 . 1.5))))
)

 

It could also be adjusted to allow selection of multiple existing Mtexts to mask all at once.


Thank you so much for this routine. Well appreciated.

I have to change the call function since "MTM" is already in AutoCAD. Also, I replaced the 1.5 Border Offset Factor to 1.2, since that's what I usually use. Though this function is for existing MText, which will always come out very handy for me; it's a keeper.

 

Would be nice to have it as part of the MText function for newly existing one.

0 Likes
Message 4 of 6

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

....

Presumably the MTEXT command could have its definition altered to immediately do the following upon completion of an Mtext.  ....


This is the kind of thing I had in mind:

(command "_.undefine" "MTEXT")
(defun C:MTEXT ()
  (command-s "_.mtext")
  (entmod (append (entget (entlast)) '((90 . 3) (45 . 1.2))))
  (prin1)
)

And it "works" except for some unfortunate shortcomings.  You don't see the content building on-screen as you type, and picking in empty space doesn't end it [Shift+Enter or Ctrl+Enter is required].  Maybe there's a way to accomplish the same without losing those features, but I haven't hit on it yet.

 

[I also tried the approach of starting the command and then watching the CMDACTIVE System Variable, and as long as it's more than 0 [the command is still running], keep waiting for User input.  But that locked up AutoCAD entirely.]

Kent Cooper, AIA
0 Likes
Message 5 of 6

Sea-Haven
Mentor
Mentor

Just some random code I have but seems to set the background mask on, so type a string.

 

(defun c:test ( / str)
(setq str (getstring "\nEnter text "))
 (entmake
	(list
		(cons 100 "AcDbEntity")
		(cons 100 "AcDbMText")
		(cons 0 "MTEXT")
		(cons 1 str)
		(cons 7 "Standard")
		(cons 8 "0")
		(cons 10 (list 100 100 0.0))
		(cons 11 (list 0.0 0.0 0.0))
		(cons 40 2.5)
		(cons 41 0.0)
		(cons 42 1)
		(cons 42 1) 
		(cons 43 0) 
		(cons 44 1)
		(cons 45 1.2)
		(cons 50 0.75)
		(cons 71 6)
		(cons 72 1)
		(cons 90 3)
		)
)
(princ)
)
(c:test)

 Very limited testing

 

0 Likes
Message 6 of 6

komondormrex
Mentor
Mentor

reactor used. to add reactor run (add_object_added_reactor). to remove reactor run (remove_object_added_reactor). when added, reactor will check every added entity to database and if it is mtext it will add a background mask to it. 

 

;***********************************************************************************************************

(vl-load-com)

;***********************************************************************************************************

(defun add_object_added_reactor ()
  (setq object_added_reactor (vlr-acdb-reactor "Object_Added" '((:vlr-objectappended . mtext_added))))
)

;***********************************************************************************************************

(defun mtext_added (reactor_object dbase_object_list)
  (if (= "MTEXT" (cdr (assoc 0 (entget (cadr dbase_object_list)))))
    (entmod (append (entget (cadr dbase_object_list)) '((90 . 3) (63 . 9) (45 . 1.5))))
  )
)

;***********************************************************************************************************

(defun remove_object_added_reactor ()
   (vlr-remove object_added_reactor)
)

;***********************************************************************************************************

 

0 Likes