command mtext with mask

command mtext with mask

mail
Explorer Explorer
1,546 Views
9 Replies
Message 1 of 10

command mtext with mask

mail
Explorer
Explorer

Got this peace of code, i would like to add a text mask to the mtext and set it to backround color and i would like to have the line spacing set to exactly. 

 

           (command "mtext" p2 "a" textausri "d" p1 p2 "h" textht "mask state" 1 "" ctext "")

 

Is there a commend i can add to the line above to achieve this?

0 Likes
Accepted solutions (2)
1,547 Views
9 Replies
Replies (9)
Message 2 of 10

Moshe-A
Mentor
Mentor

hi,

 

take a look at <<lee-mac>> website

 

moshe

 

0 Likes
Message 3 of 10

john.uhden
Mentor
Mentor
Accepted solution

Try adding this line after (command ...)

(vlax-put (vlax-ename->vla-object (entlast)) 'backgroundfill 1)

John F. Uhden

Message 4 of 10

mail
Explorer
Explorer

Nice, thanks a lot, that works fine. 2 more things i'd like to change :

- set the boarder offset from the mask from 1.5 to 1.2

- set line spacing style to exactly 

 

would be awsome if you could help mit with that too 🙂

 

And another question, my lisp is writing coordinates ctext is for example 1500500 Is there a way i can put signs in to the thousands? like 1'500'500?

 

0 Likes
Message 5 of 10

ambrosl
Autodesk
Autodesk

You can use the dumpallproperties and setpropertyvalue functions to modify a Mtext object.

 

Below are some AutoLISP statements that manipulate the properties of an Mtext object:

(setq ent (car (entsel)))
(setpropertyvalue ent "BackgroundFill" 1)
(setpropertyvalue ent "BackgroundFillColor" 1)
(setpropertyvalue ent "BackgroundScaleFactor" 1.2)
(setpropertyvalue ent "LineSpacingStyle" 2)


Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
Message 6 of 10

Moshe-A
Mentor
Mentor

@mail

 

 

about the comma format numbers, check this:

 

 

;;; comma-format
;;; return a number comma formated or nil if the argument is not a number
(defun comma-format (n / val-in val-out len p i ch)
 (if (numberp n)
  (progn
   (setq val-in (rtos n 2 0) val-out "")
   (setq len (strlen val-in) p 0 i (1+ len))
   (repeat len
    (setq p (1+ p) i (1- i) ch (substr val-in i 1))
    (if (and
	  (< p len)
	  (= (rem p 3) 0)
        )
     (setq val-out (strcat "," ch val-out))  
     (setq val-out (strcat ch val-out))
    )
   ); repeat
   
   val-out ; return 
  ); progn
 ); if
); comma-format

 

0 Likes
Message 7 of 10

mail
Explorer
Explorer

Ok, sounds easy. But sorry i am a total beginner. Where do i have to put those functions in the lisp i'm trying to manipulate? Thank you a lot for your help!

 

 

(setq cx_mb startx)
(setq minx (min liun_mb_x reun_mb_x)) ; es kann auch in negativer Richtung verlaufen
(setq maxx (max liun_mb_x reun_mb_x))
(while (<= cx_mb minx) ; ersten auf Rand im MB vorh. Wert ermitteln
(setq cx_mb (+ cx_mb delta_l))
) ; end while cx_mb
(while (< cx_mb maxx)
(setq delta_m1 (- cx_mb liun_mb_x)) ; Streckenverhältnisse
(setq cx_af (+ liun_af_x (* (/ delta_m1 delta_m) delta_a)))
(setq ctext (rtos cx_mb 2 0))
(setq p1 (list cx_af cy_af))
(setq p2 (polar p1 richtg 15))

(command "mtext" p2 "a" textausri "d" p1 p2 "h" textht "" ctext "")
(command "linie" p1 p2 "")

(setq cx_mb (+ cx_mb delta_l))
) ; end while cx_mb

0 Likes
Message 8 of 10

john.uhden
Mentor
Mentor
Accepted solution

To adjust the mask offset, add this after the previous line I provided:

(setq ent (entget entlast))
(setq offset 1.2) ;; or whatever you like
(if (assoc 45 ent)
  (entmod (subst (cons 45 offset)(assoc 45 ent) ent))
  (entmod (append ent (list (cons 45 offset))))
)

Rather than use (rtos), use this...

;;----------------------------------------------------
;; This function pads a numeric string with commas.
;; Revised to handle negative values (03-14-02)
;; Re-written (11-20-04):
(defun @rtoc (N Prec / Sign Str i j)
  (setq Prec (max 0 Prec)
        Sign (if (minusp N) "-" "")
        Str  (rtos (abs N) 2 Prec)
        i    (vl-string-search "." Str)
  )
  (if (not i)(setq i (strlen Str)))
  (setq j i)
  (if (zerop (setq i (rem i 3)))(setq i 3))
  (while (< i j)
    (setq Str (strcat (substr Str 1 i) "," (substr Str (1+ i)))
          i (+ i 4)
          j (1+ j)
    )
  )
  (strcat Sign Str)
)
Or in your case..
;;----------------------------------------------------
;; This function pads a numeric string with apostrophes.
;; Revised to handle negative values (03-14-02)
;; Re-written (11-20-04)
(defun @rtoapos (N Prec / Sign Str i j)
  (setq Prec (max 0 Prec)
        Sign (if (minusp N) "-" "")
        Str  (rtos (abs N) 2 Prec)
        i    (vl-string-search "." Str)
  )
  (if (not i)(setq i (strlen Str)))
  (setq j i)
  (if (zerop (setq i (rem i 3)))(setq i 3))
  (while (< i j)
    (setq Str (strcat (substr Str 1 i) "'" (substr Str (1+ i)))
          i (+ i 4)
          j (1+ j)
    )
  )
  (strcat Sign Str)
)

John F. Uhden

Message 9 of 10

mail
Explorer
Explorer

Wuauw, thanks a lot! just had to add a () with entlast. Also added this code to set stil of Mtext line spacing style to exact

 

(setq zeilenab 2) ;; or whatever you like
(if (assoc 73 ent)
(entmod (subst (cons 73 zeilenab)(assoc 73 ent) ent))
(entmod (append ent (list (cons 73 zeilenab))))
)

 

 

About the 

function pads a numeric string with apostrophe

 i don't really know where i have to put it in my lisp, bevor or after my command "mtext". And do i have to change the code, because my Value is setq ctext?

 

My code looks like this now: 

(setq delta_m (- reun_mb_x liun_mb_x)) ; dargestellte Koord.diff im Modellb.
(setq delta_a (- reun_af_x liun_af_x)) ; dargestellte Koord.diff im Ansichtsf.
(setq cy_af liun_af_y)
(if (and (> alpha (/ pi 2.)) (< alpha (* 3 (/ pi 2.)))) ; Richtg. der Linie in Abh. von Drehung MB in AF
(setq richtg (- alpha (/ pi 2.)))
(setq richtg (+ alpha (/ pi 2.)))
) ; end if
(if (< richtg 0) (setq richtg (+ richtg pi pi))) ; nur Richtung 0 .. 2pi zulässig
(if (> richtg (* 2 pi)) (setq richtg (- richtg pi pi)))
(setq textht 2)
(if (< richtg (/ pi 2)) ; Textrichtg. in Abh. von Linienrichtg.
(progn (setq textri (/ (* richtg 180 ) pi))
(setq textausri "ur")
) ; end progn
(progn (setq textri (/ (* (- richtg pi) 180 ) pi))
(setq textausri "ur")
) ; end progn
) ; end if
(setq cx_mb startx)
(setq minx (min liun_mb_x reun_mb_x)) ; es kann auch in negativer Richtung verlaufen
(setq maxx (max liun_mb_x reun_mb_x))
(while (<= cx_mb minx) ; ersten auf Rand im MB vorh. Wert ermitteln
(setq cx_mb (+ cx_mb delta_l))
) ; end while cx_mb
(while (< cx_mb maxx)
(setq delta_m1 (- cx_mb liun_mb_x)) ; Streckenverhältnisse
(setq cx_af (+ liun_af_x (* (/ delta_m1 delta_m) delta_a)))
(setq ctext (rtos cx_mb 2 0))
(setq p1 (list cx_af cy_af))
(setq p2 (polar p1 richtg 15))
(command "mtext" p2 "a" textausri "d" p1 p2 "h" textht "" ctext "")

(vlax-put (vlax-ename->vla-object (entlast)) 'backgroundfill 1)
(setq ent (entget (entlast)))
(setq offset 1.2) ;; or whatever you like
(if (assoc 45 ent)
(entmod (subst (cons 45 offset)(assoc 45 ent) ent))
(entmod (append ent (list (cons 45 offset))))
)

(setq zeilenab 2) ;; or whatever you like
(if (assoc 73 ent)
(entmod (subst (cons 73 zeilenab)(assoc 73 ent) ent))
(entmod (append ent (list (cons 73 zeilenab))))
)


(command "linie" p1 p2 "")

(setq cx_mb (+ cx_mb delta_l))
) ; end while cx_mb

 

 

Thanks a lot for your help, really apreciate it!

0 Likes
Message 10 of 10

john.uhden
Mentor
Mentor
Change:
(setq ctext (rtos cx_mb 2 0))
to:
(setq ctext (rtoapos cx_mb 0))

Of course you have to add the rtoapos function earlier into your code. 

John F. Uhden

0 Likes