Author Topic: Qestion about MTEXT  (Read 2578 times)

0 Members and 1 Guest are viewing this topic.

FengK

  • Guest
Qestion about MTEXT
« on: February 05, 2008, 05:08:16 PM »
Hello,

Please see the attached image. Notice there is extra blank space in the MTEXT. It can be resized when you drag the grip. My question is how do you access this property via lisp? I'm going to dig into it myself, but thought I'd ask here as well. Maybe some of you already know the answer.

Thanks.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Qestion about MTEXT
« Reply #1 on: February 05, 2008, 05:20:44 PM »
Here is mine.

Code: [Select]
(defun VALUE (num ent /)
(cdr (assoc num ent))
)
;-------------------------------------------------------------------------
(defun DTR (a) ;Degrees to radians conversion
(* pi (/ a 180.0))
)
;-------------------------------------------------------------------------
(defun GetMTextBB (Ent / EntData InsPt TxtJust TxtWd TxtHt TxtRot 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 (trans (value 10 EntData) 0 1))
(setq TxtJust (value 71 EntData))
(setq TxtWd (value 42 EntData))
(setq TxtHt (value 43 EntData))
(setq TxtRot (value 50 EntData))
(cond
((= TxtJust 2)
(setq InsPt (polar InsPt (+ (DTR 180) TxtRot) (/ TxtWd 2.0)))
)
((= TxtJust 3)
(setq InsPt (polar InsPt (+ (DTR 180) TxtRot) TxtWd))
)
((= TxtJust 4)
(setq InsPt (polar InsPt (+ (DTR 90) TxtRot) (/ TxtHt 2.0)))
)
((= TxtJust 5)
(setq InsPt (polar InsPt (+ (DTR 90) TxtRot) (/ TxtHt 2.0)))
(setq InsPt (polar InsPt (+ (DTR 180) TxtRot) (/ TxtWd 2.0)))
)
((= TxtJust 6)
(setq InsPt (polar InsPt (+ (DTR 90) TxtRot) (/ TxtHt 2.0)))
(setq InsPt (polar InsPt (+ (DTR 180) TxtRot) TxtWd))
)
((= TxtJust 7)
(setq InsPt (polar InsPt (+ (DTR 90) TxtRot) TxtHt))
)
((= TxtJust 8)
(setq InsPt (polar InsPt (+ (DTR 90) TxtRot) TxtHt))
(setq InsPt (polar InsPt (+ (DTR 180) TxtRot) (/ TxtWd 2.0)))
)
((= TxtJust 9)
(setq InsPt (polar InsPt (+ (DTR 90) TxtRot) TxtHt))
(setq InsPt (polar InsPt (+ (DTR 180) TxtRot) TxtWd))
)
(t
(setq InsPt InsPt)
)
)
(list
InsPt
(setq tmpPt (polar InsPt TxtRot TxtWd))
(polar tmpPt (+ (DTR 270) TxtRot) TxtHt)
(polar InsPt (+ (DTR 270) TxtRot) TxtHt)
)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

FengK

  • Guest
Re: Qestion about MTEXT
« Reply #2 on: February 05, 2008, 06:00:10 PM »
Tim,

Thanks for your code! I'll look at it later. What I found is the height of grip has something to do with dxf group code 46, which is not documented in the DXF Reference.  When the value for group code 46 is changed, the height of grip is changed accordingly. But the BackgroundMask does not resize automatically.

Update:
The BackgroundMask is resized after close and re-open the drawing.
« Last Edit: February 05, 2008, 06:04:06 PM by Kelie »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Qestion about MTEXT
« Reply #3 on: February 05, 2008, 06:02:44 PM »
Tim,

Thanks for your code! I'll look at it later. What I found is the height of grip has something to do with dxf group code 46, which is not documented in the DXF Reference.  When the value for group code 46 is changed, the height of grip is changed accordingly. But the BackgroundMask does not resize automatically.

I have helped all I can.  :-)  I don't like mtext, and try not to use it, and I have never used a background mask, so I hope either you find out what needs to be done, or someone more knowledgeable than I will assist you.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

FengK

  • Guest
Re: Qestion about MTEXT
« Reply #4 on: February 06, 2008, 02:09:09 AM »
Tim, Yes I've solved my problem. All I had to do was set the value corresponding to group code 46 to 0.0. Something like (entmod (subst (cons 46 0.0) (assoc 46 ent) ent)) where ent is returned from ENTGET function applied to an ENAME. I had many MTEXT with Background Marks on and way too big. That's why I asked the question. 

As far as the code you posted, I can see what it does. But not sure about its usage. How will the info about actual bounding box be used? To draw a rectangle around the MTEXT?

Thanks again.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Qestion about MTEXT
« Reply #5 on: February 06, 2008, 11:03:21 AM »
Tim, Yes I've solved my problem. All I had to do was set the value corresponding to group code 46 to 0.0. Something like (entmod (subst (cons 46 0.0) (assoc 46 ent) ent)) where ent is returned from ENTGET function applied to an ENAME. I had many MTEXT with Background Marks on and way too big. That's why I asked the question. 

As far as the code you posted, I can see what it does. But not sure about its usage. How will the info about actual bounding box be used? To draw a rectangle around the MTEXT?

Thanks again.
Glad to hear you got it solved Kelie.

You are correct in the way that routine is used right now.  I have a command that will draw polylines around text entities, and to make it work correctly around mtext I had to do it that way.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

danielgp

  • Guest
Re: Qestion about MTEXT
« Reply #6 on: February 07, 2008, 01:56:52 PM »
Another variant with two arguments: The mtext and one distance around the text.
I change the function "value" by "dxf" because is my own function, and I pass the angles in radians.

If use
(GetMTextBBD ent 0.0)
its the same that
(GetMTextBB ent)

But you can use

(GetMTextBBD ent 2.0)

or

(GetMTextBBD ent (* (dxf 40 (entget ent)) 0.25))


And sorry about my english.

Code: [Select]
(defun GetMTextBBD (Ent dist / EntData InsPt TxtJust TxtWd TxtHt TxtRot 2d pi/2 tmpPt)
; Get real Bounding Box for MText
; Tim Willey 03/2005
; Thanks to OLD-CADaver for the tips on the DXF codes
; Sub's 'dxf

(setq EntData (entget Ent)
      InsPt (trans (dxf 10 EntData) 0 1)
      TxtJust (dxf 71 EntData)
      TxtWd (dxf 42 EntData)
      TxtHt (dxf 43 EntData)
      TxtRot (dxf 50 EntData)
      2d (+ dist dist)
      pi/2 (* pi 0.5))
(cond
((= TxtJust 2)
(setq InsPt (polar InsPt (+ pi TxtRot) (* TxtWd 0.5)))
)
((= TxtJust 3)
(setq InsPt (polar InsPt (+ pi TxtRot) TxtWd))
)
((= TxtJust 4)
(setq InsPt (polar InsPt (+ pi/2 TxtRot) (* TxtHt 0.5)))
)
((= TxtJust 5)
(setq InsPt (polar InsPt (+ pi/2 TxtRot) (* TxtHt 0.5)))
(setq InsPt (polar InsPt (+ pi TxtRot) (* TxtWd 0.5)))
)
((= TxtJust 6)
(setq InsPt (polar InsPt (+ pi/2 TxtRot) (* TxtHt 0.5)))
(setq InsPt (polar InsPt (+ pi TxtRot) TxtWd))
)
((= TxtJust 7)
(setq InsPt (polar InsPt (+ pi/2 TxtRot) TxtHt))
)
((= TxtJust 8)
(setq InsPt (polar InsPt (+ pi/2 TxtRot) TxtHt))
(setq InsPt (polar InsPt (+ pi TxtRot) (* TxtWd 0.5)))
)
((= TxtJust 9)
(setq InsPt (polar InsPt (+ pi/2 TxtRot) TxtHt))
(setq InsPt (polar InsPt (+ pi TxtRot) TxtWd))
)
;;; (t
;;; (setq InsPt InsPt)
;;; )
)
(list
(setq InsPt (polar (polar InsPt (+ pi TxtRot) dist) (+ pi/2 TxtRot) dist))
(setq tmpPt (polar InsPt TxtRot (+ 2d TxtWd)))
(polar tmpPt (+ -pi/2 TxtRot) (+ 2d TxtHt))
(polar InsPt (+ -pi/2 TxtRot) (+ 2d TxtHt))
)
)


T.Willey

  • Needs a day job
  • Posts: 5251
Re: Qestion about MTEXT
« Reply #7 on: February 07, 2008, 05:05:32 PM »
Nice one danielgp, but I get an error here.
Quote
Command: (polar tmpPt (+ -pi/2 TxtRot) (+ 2d TxtHt))
Error:  bad argument type: numberp: nil

I don't think it likes the -pi/2, as shown here
Quote
Command: (setq test -pi/2)
nil

ps.  Welcome to theSwamp.  Enjoy your stay.   :-)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

danielgp

  • Guest
Re: Qestion about MTEXT
« Reply #8 on: February 11, 2008, 03:15:01 AM »
Yes its an error.
This is the correct code:

Sorry

Code: [Select]
(defun dxf (num ent) (cdr (assoc num ent)))


(defun GetMTextBBD (Ent dist / EntData InsPt TxtJust TxtWd TxtHt TxtRot 2d pi/2 -pi/2 tmpPt)
; Get real Bounding Box for MText
; Tim Willey 03/2005
; Thanks to OLD-CADaver for the tips on the DXF codes
; Sub's 'dxf

(setq EntData (entget Ent)
      InsPt (trans (dxf 10 EntData) 0 1)
      TxtJust (dxf 71 EntData)
      TxtWd (dxf 42 EntData)
      TxtHt (dxf 43 EntData)
      TxtRot (dxf 50 EntData)
      2d (+ dist dist)
      pi/2 (* pi 0.5)
              [color=red]-pi/2[/color] (- pi/2)
        )
(cond
((= TxtJust 2)
(setq InsPt (polar InsPt (+ pi TxtRot) (* TxtWd 0.5)))
)
((= TxtJust 3)
(setq InsPt (polar InsPt (+ pi TxtRot) TxtWd))
)
((= TxtJust 4)
(setq InsPt (polar InsPt (+ pi/2 TxtRot) (* TxtHt 0.5)))
)
((= TxtJust 5)
(setq InsPt (polar InsPt (+ pi/2 TxtRot) (* TxtHt 0.5)))
(setq InsPt (polar InsPt (+ pi TxtRot) (* TxtWd 0.5)))
)
((= TxtJust 6)
(setq InsPt (polar InsPt (+ pi/2 TxtRot) (* TxtHt 0.5)))
(setq InsPt (polar InsPt (+ pi TxtRot) TxtWd))
)
((= TxtJust 7)
(setq InsPt (polar InsPt (+ pi/2 TxtRot) TxtHt))
)
((= TxtJust 8)
(setq InsPt (polar InsPt (+ pi/2 TxtRot) TxtHt))
(setq InsPt (polar InsPt (+ pi TxtRot) (* TxtWd 0.5)))
)
((= TxtJust 9)
(setq InsPt (polar InsPt (+ pi/2 TxtRot) TxtHt))
(setq InsPt (polar InsPt (+ pi TxtRot) TxtWd))
)
;;; (t
;;; (setq InsPt InsPt)
;;; )
)
(list
(setq InsPt (polar (polar InsPt (+ pi TxtRot) dist) (+ pi/2 TxtRot) dist))
(setq tmpPt (polar InsPt TxtRot (+ 2d TxtWd)))
(polar tmpPt (+ [color=red]-pi/2[/color] TxtRot) (+ 2d TxtHt))
(polar InsPt (+ [color=red]-pi/2[/color] TxtRot) (+ 2d TxtHt))
)
)
 

<edit: highlight added - CAB>
« Last Edit: February 11, 2008, 10:11:45 AM by CAB »