MText - Insertion Point in Middle Center

MText - Insertion Point in Middle Center

Anonymous
Not applicable
5,756 Views
15 Replies
Message 1 of 16

MText - Insertion Point in Middle Center

Anonymous
Not applicable

Hello,; I want to set an option, that all newly created MTexts will have Insertion Point in Middle Center.
Is it possible, to do this in lisp?
2. I want to write lisp "Select MTexts to change their Insertion Point to Middle Center".

0 Likes
Accepted solutions (1)
5,757 Views
15 Replies
Replies (15)
Message 2 of 16

Anonymous
Not applicable

Hi damian,

 

Something quick for changing to Middle Center:

 

(defun c:mc (/ ss ename vobj inspt)
  (if (setq ss (ssget '((0 . "MTEXT"))))
  (while (setq ename (ssname ss 0))
    (setq vobj (vlax-ename->vla-object ename))
    (setq inspt (vla-get-insertionpoint vobj))
    (vla-put-AttachmentPoint  vobj 5)
    (vla-put-insertionpoint vobj inspt)
    (ssdel ename ss)
    )
  )
  )

 I'm not sure that there is any variable which can change mtext justify, but maybe we could create a new command which is going to make mtext and automaticly change justify to middle center.

 

dicra

0 Likes
Message 3 of 16

hmsilva
Mentor
Mentor

@Anonymous wrote:

I want to set an option, that all newly created MTexts will have Insertion Point in Middle Center.
Is it possible, to do this in lisp?


Hi Damian,

 

do you mean 'Insertion Point in Middle Center' or 'Justification Middle Center'?

 

Henrique

EESignature

0 Likes
Message 4 of 16

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Hello,; I want to set an option, that all newly created MTexts will have Insertion Point in Middle Center.
....


I thought of Undefining Mtext and defining a new one that includes calling for Middle-Center justification immediately after the first corner-point selection.  But I tried to Undefine it in a (command) function and define a new command so both could be built into a .lsp routine that could be included in acaddoc.lsp so it would take effect in every drawing.

 

(command "_.undefine" "MTEXT")

(defun C:MTEXT () (command "_.mtext" pause "_j" "_mc"))

 

Oddly, at first it said MTEXT is an Unknown command name in the Undefine command, although doing it manually works with that name.  It later allowed that, even though I don't think I did anything differently, but then in the redefined command it said the same.  I hope I didn't do something wrong, but I tried it in two versions, and using MTEXT with and without the . and/or the _ leading characters.  Maybe there's something about Mtext that just operates differently from most commands.

 

HOWEVER, I find that putting this macro into some menu item/button/icon works fine:

 

^C^C_.MTEXT \J MC

Kent Cooper, AIA
0 Likes
Message 5 of 16

hmsilva
Mentor
Mentor

Maybe something like this

 

(defun c:cmt ()
  (initdia)
  (command "._MTEXT" (getpoint) "_J" "_MC")
  (princ)
)

 

 

Henrique

EESignature

0 Likes
Message 6 of 16

Kent1Cooper
Consultant
Consultant

@hmsilva wrote:

Maybe something like this....

 

 

If I do that using C:MTEXT as the command name after undefining the original, it still gives me an

 

Unknown command "MTEXT"

 

error.  I tried it with and without the (initdia), and using (getpoint) vs. pause, and with "._mtext" vs. "_.mtext", I even tried saving the point first and feeding it in.

 

But it works for me with a different command name as you did it, without first undefining MTEXT.  I was just trying to get the undefine/new-definition approach, still using MTEXT as the command name, to work, so that the standard T alias and any menu items calling for Mtext [if they don't include the . prefix] would all call up the always-middle-center-justified version, since it seems that having all Mtext justified that way is what the OP was after.  [They could still call for different justifications from within the command's options, when wanted, but MC would be the default.]  But there must be something special about the Mtext command that apparently prevents that from working as expected.

 

REALLY oddly, I find that if I leave Mtext's original definition alone [no Undefine], and do my definition of C:MTEXT anyway, using T or typing in MTEXT still gets the regular command, and putting in (C:MTEXT) gets my always-middle-center-justified version, which works.  I wouldn't have thought it would allow using a not-undefined command name in a new definition, but I find it does for others [e.g. LINE] as well.

Kent Cooper, AIA
0 Likes
Message 7 of 16

hmsilva
Mentor
Mentor

@Kent1Cooper wrote:

REALLY oddly, I find that if I leave Mtext's original definition alone [no Undefine], and do my definition of C:MTEXT anyway, using T or typing in MTEXT still gets the regular command, and putting in (C:MTEXT) gets my always-middle-center-justified version, which works.  I wouldn't have thought it would allow using a not-undefined command name in a new definition, but I find it does for others [e.g. LINE] as well.


Using AC2014, same behavior...weird...

 

I did add the 'initdia', because if not, i'll get the -mtext version, have to enter text at the command line...

 

Henrique

 

 

EESignature

0 Likes
Message 8 of 16

Anonymous
Not applicable

I meaned 'Insertion Point in Middle Center'. Thank all of you for your answers.

0 Likes
Message 9 of 16

hmsilva
Mentor
Mentor

Hi damian.wrobel, my question
'do you mean 'Insertion Point in Middle Center' or 'Justification Middle Center'?'
had a meaning...
With MTEXT, when we just change the 'Justification flag', the object location will change, we'll need to calculate the 'effective BoundingBox', recalculate the new insertion point with the new 'Justification flag', to ensure that MText object position will not be modified.

If you don't want the text position to be modified, and your AutoCAD version is not too old, you can use the AutoCAD command JUSTIFYTEXT, and if your AutoCAD version don't have that command, and you have Express Toos installed on your system the TJUST command will do the trick...

 

I hope this helps
Henrique

EESignature

0 Likes
Message 10 of 16

Anonymous
Not applicable

damian,

 

Did you check the code for changing Insertion Point in Middle Center of Mtexts?

Is that what you are looking for, your second task?

 

dicra

0 Likes
Message 11 of 16

Anonymous
Not applicable

 @dicra
Yes, both (your "mc" and Kent1Cooer's "MTEXT" are working.
Thank both of you, I didn't think, that MTEXT -> Justify
has effect not only on MText Justification,
but on Insertion Point too.

 

It is partially solution for my first question.

My first question would be fully revealed, if there would be a System Variable which I can

set to "MC" so that I type MTEXT, Enter, the every newly created MText will have Insertion Point

in Middle Center - that's what I meant when I asked this question.

 

These two lisps are not solution to my second question

, because these lisps create new MText,

, and I want "Select MTexts to change their Insertion Point to Middle Center: ".

0 Likes
Message 12 of 16

Anonymous
Not applicable

 @hmsilva
Luckily I have AutoCad 2012 and I have ExpressTools installed.
So I can use JUSTIFYTEXT = TJUST.


Hm... In ExpressTools there are commands
such as TORIENT = "Rotate Text"
or TCASE = "Change Text Case"
and I have lisps for them.


I mean not, that I have lisp that TC Buttons = "_TCASE" command.
Somebody else definied lisps to give all the users
(not only these with ExpressTools)
possibility to use these useful commands.


Maybe is there a man who could write this lisp for
"Change Insertion Point of selected MTexts: "
or
'Specify Insertion Point for the MTexts you will create from now on: "
(is there a System Variable which controls it?)
or
"Match MText's Insertion Point."
(If you use MATCHPROP, you will Match Insertion Point, but not only this property.
And I want a lisp for Matching only this one property).

Message 13 of 16

Anonymous
Not applicable

I tried to write lisp which would be solution for my problem number 2.
Here they are:

 

 

(defun c:MTEDMC1 ()
 (initdia)
 (princ "\nSelect MTexts to change theit Insertion Points to Middle Center: ")
 (command "_MTEDIT" pause "_J" "_MC")
)
;------------------------------------------------------------------
; WYświetla się MText Editor, czyli okno "Text Formatting".
; MTDIA = MText in DIAlogBox
(defun c:MTDIA ()
 (initdia)
 (command "_MTEXT")
)
;------------------------------------------------------------------
; Wyświetla się w CommandLine.
; MTKL = MText in (K=c)ommandLine
(defun c:MTKL ()
 (command "_MTEXT")
)
;------------------------------------------------------------------
; WYświetla się MText Editor, czyli okno "Text Formatting".
; MTDIA = MText in DIAlogBox
(defun c:MTEDDIA ()
 (initdia)
 (command "_MTEDIT")
)
;------------------------------------------------------------------
; Powinno z założenia Wyświetlać się w CommandLine.
; Ale wyświetla się w Dialog Boxie "Text Formatting".
; MTKL = MText in (K=c)ommandLine
(defun c:MTEDKL ()
 (command "_MTEDIT")
)
;------------------------------------------------------------------
; Nie działa
;Command: MTEDKL1
;Unknown command "-MTEDIT".  Press F1 for help.
; MTKL = MText in (K=c)ommandLine
(defun c:MTEDKL1 ()
 (command "_-MTEDIT")
)
;------------------------------------------------------------------
; Nie działa
;Command: MTEDJMC1
;*Invalid selection*
;Expects a point or Last
;; error: Function cancelled
(defun c:MTEDJMC1 ()
 (command "_MTEDIT" "_J" "_MC")
)
;------------------------------------------------------------------
; Nie działa
;Command: MTEDJMC2
;*Invalid selection*
;Expects a point or Last
;; error: Function cancelled
;Select an MTEXT object:
(defun c:MTEDJMC2 ()
 (initdia)
 (command "_MTEDIT" "_J" "_MC")
)
;------------------------------------------------------------------
; Nie działa
;Command: MTEDJMC3
;Unknown command "J".  Press F1 for help.
;Unknown command "MC".  Press F1 for help.
(defun c:MTEDJMC3 ()
 (initdia)
 (command "_MTEDIT" (getpoint) "_J" "_MC")
)
;------------------------------------------------------------------
; Nie działa
;Select objects: 1 found
;Select objects:  Unknown command "J".  Press F1 for help.
(defun c:MTEDJMC4 ()
 (initdia)
 (setq zbior (ssget))
 (command "_MTEDIT" zbior "_J" "_MC")
)

 

 

The problem is, that command "MTEDIT" is not opened in CommandLine.
Even if I use "-MTEDIT", there is prompt, that there is no such a command.

 

0 Likes
Message 14 of 16

Anonymous
Not applicable
Accepted solution

@Anonymous wrote:

Hi damian,

 

Something quick for changing to Middle Center:

 

(defun c:mc (/ ss ename vobj inspt)
  (if (setq ss (ssget '((0 . "MTEXT"))))
  (while (setq ename (ssname ss 0))
    (setq vobj (vlax-ename->vla-object ename))
    (setq inspt (vla-get-insertionpoint vobj))
    (vla-put-AttachmentPoint  vobj 5)
    (vla-put-insertionpoint vobj inspt)
    (ssdel ename ss)
    )
  )
  )

 

dicra



Damian,

 

This was for your second task, it change existing Mtexts insertion to midle center.

 

dicra

Message 15 of 16

Anonymous
Not applicable

Thank you, it works.

0 Likes
Message 16 of 16

Anonymous
Not applicable

damian,

 

I'm glad I could help.

 

dicra

0 Likes