Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MText - Set Limits Box to minimum

17 REPLIES 17
Reply
Message 1 of 18
BMcAnney
2656 Views, 17 Replies

MText - Set Limits Box to minimum

Hello,

I would like to write a routine to resize the MText limits box to the
minimum size required to cover the text, for background masking purposes.
From the DXF codes, I see that I can simply set code 41 to match code 42 in
order to set the width. However, I cannot seem to figure out how the
vertical dimension is defined. (entget) shows no change in the DXF codes
after I resize the mtext box.

I do know how to figure out the height that I need, using
(acet-geom-textbox), but I can't seem to figure out how to apply this height
the MText entity. Anyone know?

Thanks!
-Brent McAnney
17 REPLIES 17
Message 2 of 18
Anonymous
in reply to: BMcAnney

See if this works for you.
[code]
(defun c:ChangeMtextBox (/ temp1 Ent)

(if (setq temp1 (GetMTextBB (setq Ent (car (entsel "\n Select Mtext: ")))))
(progn
(if (equal (caar temp1) (caadr temp1) 0.0001)
(progn
(entmod (subst (cons 43 (distance (car temp1) (cadr temp1))) (assoc 43
(entget Ent)) (entget Ent)))
(entmod (subst (cons 41 (distance (car temp1) (caddr temp1))) (assoc 41
(entget Ent)) (entget Ent)))
)
(progn
(entmod (subst (cons 43 (distance (car temp1) (caddr temp1))) (assoc 43
(entget Ent)) (entget Ent)))
(entmod (subst (cons 41 (distance (car temp1) (cadr temp1))) (assoc 41
(entget Ent)) (entget Ent)))
)
)
)
)
(princ)
)
;---------------------------------------------------------------------
(defun GetMTextBB (Ent / EntData EnsPt TxtJust TxtWd TxtHt TxtRot LeftX
RightX TopY BottomY Oldos RtnList tmpPt)
; Get real Bounding Box for MText
; Tim Willey 03/2005
; Thanks to OLD-CADaver for the tips on the DXF codes
; Sub's 'value 'DTR

(setq EntData (entget Ent))
(setq InsPt (value 10 EntData))
(setq TxtJust (value 71 EntData))
(setq TxtWd (value 42 EntData))
(setq TxtHt (value 43 EntData))
(setq TxtRot (value 50 EntData))
(setq Oldos (getvar "osmode"))
(setvar "osmode" 0)
(command "_.ucs" "_3" InsPt (polar InsPt TxtRot 0.001) (polar InsPt (+ (DTR
90) TxtRot) 0.001))
(setq InsPt (trans (value 10 (entget Ent)) 0 1))
(setq TxtRot (value 50 (entget Ent)))
(cond
((or (= TxtJust 1) (= TxtJust 4) (= TxtJust 7))
(setq LeftX (car InsPt))
(setq RightX (car (polar InsPt TxtRot TxtWd)))
)
((or (= TxtJust 2) (= TxtJust 5) (= TxtJust 8))
(setq LeftX (car (polar InsPt TxtRot (/ TxtWd 2))))
(setq RightX (car (polar InsPt (+ (DTR 180) TxtRot) (/ TxtWd 2))))
)
((or (= TxtJust 3) (= TxtJust 6) (= TxtJust 9))
(setq LeftX (car (polar InsPt (+ (DTR 180) TxtRot) TxtWd)))
(setq RightX (car InsPt))
)
)
(cond
((or (= TxtJust 1) (= TxtJust 2) (= TxtJust 3))
(setq TopY (cadr InsPt))
(setq BottomY (cadr (polar InsPt (+ (DTR 270) TxtRot) TxtHt)))
)
((or (= TxtJust 4) (= TxtJust 5) (= TxtJust 6))
(setq TopY (cadr (polar InsPt (+ (DTR 90) TxtRot) (/ TxtHt 2))))
(setq BottomY (cadr (polar InsPt (+ (DTR 270) TxtRot) (/ TxtHt 2))))
)
((or (= TxtJust 7) (= TxtJust 😎 (= TxtJust 9))
(setq TopY (cadr (polar InsPt (+ (DTR 90) TxtRot) TxtHt)))
(setq BottomY (cadr InsPt))
)
)
(setvar "osmode" Oldos)
(setq RtnList (mapcar '(lambda (a) (trans a 1 0)) (list (list LeftX BottomY)
(list RightX BottomY) (list RightX TopY) (list LeftX TopY))))
(command "_.ucs" "_p")
(setq RtnList (mapcar '(lambda (a) (trans a 0 1)) RtnList))
)
;---------------------------------------------------------------------------
-----
(defun DTR (a) ;Degrees to radians conversion
(* pi (/ a 180.0)))
;---------------------------------------------------------------------------
---------
(defun VALUE (num ent /)
(cdr (assoc num ent))
)
[/code]

--

Tim
"A blind man lets nothing block his vision."



wrote in message news:5056121@discussion.autodesk.com...
Hello,

I would like to write a routine to resize the MText limits box to the
minimum size required to cover the text, for background masking purposes.
From the DXF codes, I see that I can simply set code 41 to match code 42 in
order to set the width. However, I cannot seem to figure out how the
vertical dimension is defined. (entget) shows no change in the DXF codes
after I resize the mtext box.

I do know how to figure out the height that I need, using
(acet-geom-textbox), but I can't seem to figure out how to apply this height
the MText entity. Anyone know?

Thanks!
-Brent McAnney
Message 3 of 18
EC-CAD
in reply to: BMcAnney

Tim beat me to it..
DXF 43 seems to be the over-all Height.

Bob
Message 4 of 18
BMcAnney
in reply to: BMcAnney

Tim,

Thanks, but this doesn't work for me in 2006. It sets the width, but the
height doesn't change. Also, I see no change in DXF 43 when I resize an
MText box. Odd...

-Brent McAnney

"T.Willey" wrote in message
news:5056189@discussion.autodesk.com...
See if this works for you.
[code]
(defun c:ChangeMtextBox (/ temp1 Ent)

(if (setq temp1 (GetMTextBB (setq Ent (car (entsel "\n Select Mtext: ")))))
(progn
(if (equal (caar temp1) (caadr temp1) 0.0001)
(progn
(entmod (subst (cons 43 (distance (car temp1) (cadr temp1))) (assoc 43
(entget Ent)) (entget Ent)))
(entmod (subst (cons 41 (distance (car temp1) (caddr temp1))) (assoc 41
(entget Ent)) (entget Ent)))
)
(progn
(entmod (subst (cons 43 (distance (car temp1) (caddr temp1))) (assoc 43
(entget Ent)) (entget Ent)))
(entmod (subst (cons 41 (distance (car temp1) (cadr temp1))) (assoc 41
(entget Ent)) (entget Ent)))
)
)
)
)
(princ)
)
;---------------------------------------------------------------------
(defun GetMTextBB (Ent / EntData EnsPt TxtJust TxtWd TxtHt TxtRot LeftX
RightX TopY BottomY Oldos RtnList tmpPt)
; Get real Bounding Box for MText
; Tim Willey 03/2005
; Thanks to OLD-CADaver for the tips on the DXF codes
; Sub's 'value 'DTR

(setq EntData (entget Ent))
(setq InsPt (value 10 EntData))
(setq TxtJust (value 71 EntData))
(setq TxtWd (value 42 EntData))
(setq TxtHt (value 43 EntData))
(setq TxtRot (value 50 EntData))
(setq Oldos (getvar "osmode"))
(setvar "osmode" 0)
(command "_.ucs" "_3" InsPt (polar InsPt TxtRot 0.001) (polar InsPt (+ (DTR
90) TxtRot) 0.001))
(setq InsPt (trans (value 10 (entget Ent)) 0 1))
(setq TxtRot (value 50 (entget Ent)))
(cond
((or (= TxtJust 1) (= TxtJust 4) (= TxtJust 7))
(setq LeftX (car InsPt))
(setq RightX (car (polar InsPt TxtRot TxtWd)))
)
((or (= TxtJust 2) (= TxtJust 5) (= TxtJust 8))
(setq LeftX (car (polar InsPt TxtRot (/ TxtWd 2))))
(setq RightX (car (polar InsPt (+ (DTR 180) TxtRot) (/ TxtWd 2))))
)
((or (= TxtJust 3) (= TxtJust 6) (= TxtJust 9))
(setq LeftX (car (polar InsPt (+ (DTR 180) TxtRot) TxtWd)))
(setq RightX (car InsPt))
)
)
(cond
((or (= TxtJust 1) (= TxtJust 2) (= TxtJust 3))
(setq TopY (cadr InsPt))
(setq BottomY (cadr (polar InsPt (+ (DTR 270) TxtRot) TxtHt)))
)
((or (= TxtJust 4) (= TxtJust 5) (= TxtJust 6))
(setq TopY (cadr (polar InsPt (+ (DTR 90) TxtRot) (/ TxtHt 2))))
(setq BottomY (cadr (polar InsPt (+ (DTR 270) TxtRot) (/ TxtHt 2))))
)
((or (= TxtJust 7) (= TxtJust 😎 (= TxtJust 9))
(setq TopY (cadr (polar InsPt (+ (DTR 90) TxtRot) TxtHt)))
(setq BottomY (cadr InsPt))
)
)
(setvar "osmode" Oldos)
(setq RtnList (mapcar '(lambda (a) (trans a 1 0)) (list (list LeftX BottomY)
(list RightX BottomY) (list RightX TopY) (list LeftX TopY))))
(command "_.ucs" "_p")
(setq RtnList (mapcar '(lambda (a) (trans a 0 1)) RtnList))
)
;---------------------------------------------------------------------------
-----
(defun DTR (a) ;Degrees to radians conversion
(* pi (/ a 180.0)))
;---------------------------------------------------------------------------
---------
(defun VALUE (num ent /)
(cdr (assoc num ent))
)
[/code]

--

Tim
"A blind man lets nothing block his vision."



wrote in message news:5056121@discussion.autodesk.com...
Hello,

I would like to write a routine to resize the MText limits box to the
minimum size required to cover the text, for background masking purposes.
From the DXF codes, I see that I can simply set code 41 to match code 42 in
order to set the width. However, I cannot seem to figure out how the
vertical dimension is defined. (entget) shows no change in the DXF codes
after I resize the mtext box.

I do know how to figure out the height that I need, using
(acet-geom-textbox), but I can't seem to figure out how to apply this height
the MText entity. Anyone know?

Thanks!
-Brent McAnney
Message 5 of 18
Anonymous
in reply to: BMcAnney

I remember doing this not to long ago here. Someone else posted the same
thing. Maybe if you search you can find the post. I don't use mtext, so I
don't know how helpful I can be after what I have posted already, and I'm
still on 2004. Sorry.

--

Tim
"A blind man lets nothing block his vision."



wrote in message news:5056336@discussion.autodesk.com...
Tim,

Thanks, but this doesn't work for me in 2006. It sets the width, but the
height doesn't change. Also, I see no change in DXF 43 when I resize an
MText box. Odd...

-Brent McAnney

"T.Willey" wrote in message
news:5056189@discussion.autodesk.com...
See if this works for you.
[code]
(defun c:ChangeMtextBox (/ temp1 Ent)

(if (setq temp1 (GetMTextBB (setq Ent (car (entsel "\n Select Mtext: ")))))
(progn
(if (equal (caar temp1) (caadr temp1) 0.0001)
(progn
(entmod (subst (cons 43 (distance (car temp1) (cadr temp1))) (assoc 43
(entget Ent)) (entget Ent)))
(entmod (subst (cons 41 (distance (car temp1) (caddr temp1))) (assoc 41
(entget Ent)) (entget Ent)))
)
(progn
(entmod (subst (cons 43 (distance (car temp1) (caddr temp1))) (assoc 43
(entget Ent)) (entget Ent)))
(entmod (subst (cons 41 (distance (car temp1) (cadr temp1))) (assoc 41
(entget Ent)) (entget Ent)))
)
)
)
)
(princ)
)
;---------------------------------------------------------------------
(defun GetMTextBB (Ent / EntData EnsPt TxtJust TxtWd TxtHt TxtRot LeftX
RightX TopY BottomY Oldos RtnList tmpPt)
; Get real Bounding Box for MText
; Tim Willey 03/2005
; Thanks to OLD-CADaver for the tips on the DXF codes
; Sub's 'value 'DTR

(setq EntData (entget Ent))
(setq InsPt (value 10 EntData))
(setq TxtJust (value 71 EntData))
(setq TxtWd (value 42 EntData))
(setq TxtHt (value 43 EntData))
(setq TxtRot (value 50 EntData))
(setq Oldos (getvar "osmode"))
(setvar "osmode" 0)
(command "_.ucs" "_3" InsPt (polar InsPt TxtRot 0.001) (polar InsPt (+ (DTR
90) TxtRot) 0.001))
(setq InsPt (trans (value 10 (entget Ent)) 0 1))
(setq TxtRot (value 50 (entget Ent)))
(cond
((or (= TxtJust 1) (= TxtJust 4) (= TxtJust 7))
(setq LeftX (car InsPt))
(setq RightX (car (polar InsPt TxtRot TxtWd)))
)
((or (= TxtJust 2) (= TxtJust 5) (= TxtJust 8))
(setq LeftX (car (polar InsPt TxtRot (/ TxtWd 2))))
(setq RightX (car (polar InsPt (+ (DTR 180) TxtRot) (/ TxtWd 2))))
)
((or (= TxtJust 3) (= TxtJust 6) (= TxtJust 9))
(setq LeftX (car (polar InsPt (+ (DTR 180) TxtRot) TxtWd)))
(setq RightX (car InsPt))
)
)
(cond
((or (= TxtJust 1) (= TxtJust 2) (= TxtJust 3))
(setq TopY (cadr InsPt))
(setq BottomY (cadr (polar InsPt (+ (DTR 270) TxtRot) TxtHt)))
)
((or (= TxtJust 4) (= TxtJust 5) (= TxtJust 6))
(setq TopY (cadr (polar InsPt (+ (DTR 90) TxtRot) (/ TxtHt 2))))
(setq BottomY (cadr (polar InsPt (+ (DTR 270) TxtRot) (/ TxtHt 2))))
)
((or (= TxtJust 7) (= TxtJust 😎 (= TxtJust 9))
(setq TopY (cadr (polar InsPt (+ (DTR 90) TxtRot) TxtHt)))
(setq BottomY (cadr InsPt))
)
)
(setvar "osmode" Oldos)
(setq RtnList (mapcar '(lambda (a) (trans a 1 0)) (list (list LeftX BottomY)
(list RightX BottomY) (list RightX TopY) (list LeftX TopY))))
(command "_.ucs" "_p")
(setq RtnList (mapcar '(lambda (a) (trans a 0 1)) RtnList))
)
;---------------------------------------------------------------------------
-----
(defun DTR (a) ;Degrees to radians conversion
(* pi (/ a 180.0)))
;---------------------------------------------------------------------------
---------
(defun VALUE (num ent /)
(cdr (assoc num ent))
)
[/code]

--

Tim
"A blind man lets nothing block his vision."



wrote in message news:5056121@discussion.autodesk.com...
Hello,

I would like to write a routine to resize the MText limits box to the
minimum size required to cover the text, for background masking purposes.
From the DXF codes, I see that I can simply set code 41 to match code 42 in
order to set the width. However, I cannot seem to figure out how the
vertical dimension is defined. (entget) shows no change in the DXF codes
after I resize the mtext box.

I do know how to figure out the height that I need, using
(acet-geom-textbox), but I can't seem to figure out how to apply this height
the MText entity. Anyone know?

Thanks!
-Brent McAnney
Message 6 of 18
Anonymous
in reply to: BMcAnney

Looks like the height of the mask is stored as xdata.
Run this on a piece of mtext and look at code 1040.

(entget (car (entsel)) '("acad"))

--
Autodesk Discussion Group Facilitator



wrote in message news:5056121@discussion.autodesk.com...
Hello,

I would like to write a routine to resize the MText limits box to the
minimum size required to cover the text, for background masking purposes.
From the DXF codes, I see that I can simply set code 41 to match code 42 in
order to set the width. However, I cannot seem to figure out how the
vertical dimension is defined. (entget) shows no change in the DXF codes
after I resize the mtext box.

I do know how to figure out the height that I need, using
(acet-geom-textbox), but I can't seem to figure out how to apply this height
the MText entity. Anyone know?

Thanks!
-Brent McAnney
Message 7 of 18
BMcAnney
in reply to: BMcAnney

Thanks Jason! I am now making an attempt to update Tim's code; however, I
have never worked with xdata so it may take some fumbling around. If anyone
would care to enlighten me in the meantime, I would greatly appreciate it!

-Brent McAnney

"Jason Piercey" wrote in message
news:5056432@discussion.autodesk.com...
Looks like the height of the mask is stored as xdata.
Run this on a piece of mtext and look at code 1040.

(entget (car (entsel)) '("acad"))

--
Autodesk Discussion Group Facilitator



wrote in message news:5056121@discussion.autodesk.com...
Hello,

I would like to write a routine to resize the MText limits box to the
minimum size required to cover the text, for background masking purposes.
From the DXF codes, I see that I can simply set code 41 to match code 42 in
order to set the width. However, I cannot seem to figure out how the
vertical dimension is defined. (entget) shows no change in the DXF codes
after I resize the mtext box.

I do know how to figure out the height that I need, using
(acet-geom-textbox), but I can't seem to figure out how to apply this height
the MText entity. Anyone know?

Thanks!
-Brent McAnney
Message 8 of 18
Anonymous
in reply to: BMcAnney

try this

bmcanney wrote:
> Thanks Jason! I am now making an attempt to update Tim's code; however, I
> have never worked with xdata so it may take some fumbling around. If anyone
> would care to enlighten me in the meantime, I would greatly appreciate it!
>
> -Brent McAnney
>
> "Jason Piercey" wrote in message
> news:5056432@discussion.autodesk.com...
> Looks like the height of the mask is stored as xdata.
> Run this on a piece of mtext and look at code 1040.
>
> (entget (car (entsel)) '("acad"))
>
Message 9 of 18
BMcAnney
in reply to: BMcAnney

Thanks, that works perfectly!

-Brent McAnney

"C Witt" wrote in message
news:5056687@discussion.autodesk.com...
try this

bmcanney wrote:
> Thanks Jason! I am now making an attempt to update Tim's code; however, I
> have never worked with xdata so it may take some fumbling around. If
> anyone
> would care to enlighten me in the meantime, I would greatly appreciate it!
>
> -Brent McAnney
>
> "Jason Piercey" wrote in message
> news:5056432@discussion.autodesk.com...
> Looks like the height of the mask is stored as xdata.
> Run this on a piece of mtext and look
at code 1040.
>
> (entget (car (entsel)) '("acad"))
>
Message 10 of 18
burgerlim
in reply to: BMcAnney

Thanks! think this works for me... too..
having been thinking of how to do this... for quite some time.. already.. since i defaulted to the old editor.. (dun quite like the vertical text option)...

Again thanks!
Message 11 of 18
tkrush
in reply to: BMcAnney

Ahh did not work for me. I beilive because of R2007.

It reset the width but not the height
Message 12 of 18
rogerio_brazil
in reply to: BMcAnney

My version. Only to test. Works in AC 2k7.

(defun c:rw (/ mtexts idx ename EntData dxf42 dxf43 EntData1);Reset Width - Mtext
(prompt "\n Select MText(s) object(s): ")
(if
(setq mtexts (ssget '((0 . "MTEXT"))))
(progn
(setq idx 0)
(repeat (sslength mtexts)
(setq ename (ssname mtexts idx))
(setq EntData (entget ename '("*")))
(setq dxf42 (cdr (assoc 42 EntData)))
(setq dxf43 (cdr (assoc 43 EntData)))
(setq EntData1 (entmod (subst (cons 41 dxf42) (assoc 41 EntData) EntData)))
(entmod (subst (cons 46 dxf43) (assoc 46 EntData1) EntData1))
(setq idx (1+ idx))
);progn
);repeat
(princ "\n Null Selection!")
);if
(princ))
Message 13 of 18
Anonymous
in reply to: BMcAnney

Hi Everyone,

Is there anyway to minimize the bounding box for the text in ACAD 2008 when using an annotative text with a scale other than 1:1?

Thanks,

K
Message 14 of 18
gilsoto13
in reply to: BMcAnney

Greatopolus...

It is the best lisp I could find for it...

thank you very much Rogerio..

Gracias maestro..
Message 15 of 18
gilsoto13
in reply to: BMcAnney

Hey Rogerio, I found your routine works better if you add a factor to mtext width... as in this example... I think it works a little better
;;http://discussion.autodesk.com/forums/thread.jspa?threadID=448625&tstart=0
;;Made by Rogerio Brazil
;;It will fit Mtext box size -height and width- to minimum for selected mtexts.

(defun c:mw (/ mtexts idx ename EntData dxf42 dxf43 EntData1);Reset Width - Mtext
(prompt "\n Select MText(s) object(s): ")
(if
(setq mtexts (ssget '((0 . "MTEXT"))))
(progn
(setq idx 0)
(repeat (sslength mtexts)
(setq ename (ssname mtexts idx))
(setq EntData (entget ename '("*")))
(setq dxf42 (* (CDR (ASSOC 42 EntData))1.015))
(setq dxf43 (cdr (assoc 43 EntData)))
(setq EntData1 (entmod (subst (cons 41 dxf42) (assoc 41 EntData) EntData)))
(entmod (subst (cons 46 dxf43) (assoc 46 EntData1) EntData1))
(setq idx (1+ idx))
);progn
);repeat
(princ "\n Null Selection!")
);if
(princ)
)
(PRINC
"\Type \"MW\" to adjust selected mtext boxes size to their own text value"
)
Message 16 of 18
JGAo1
in reply to: Anonymous

Thanks for providing FX,lsp, it works great for both associative & non-associative Mtext.

JGA
Message 17 of 18
martinaitken5856
in reply to: tkrush

I know this is resurrecting  an old thread, but does anyone have the same function for Mtext in Multileaders?

 

Thanks

Martin

Message 18 of 18
troma
in reply to: BMcAnney

Can't help with lisp, but I do know that if you set the width and height to 0 (zero) it works perfectly for masking.


Mark Green

Working on Civil 3D in Canada

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost