Jump to content

Possible to change colors in the middle of a printed string?


ajs

Recommended Posts

I have a string that is printed in the upper right hand corner of my drawing.The string holds two variables.

 

The position that the text is printed depends on the type of drawing that is loaded up.

 

I was wondering if it was possible (with a reasonable amount of effort) to have the color switch on just the variable portion of the string.

 

Here's the string:

 

(setq PRINT_AREA (strcat "B Area: " B_AREA " s.f. T Area: " T_AREA " s.f." ))

 

I would like B_AREA and T_AREA to have different colors than the rest of the string which is set to color ByLayer

 

 

Here's the code that prints the string:

 

 

 

(Command "layer" "SET" "VARTEXT_1" "")

 

(If (OR(= LBN_TR "1")(= ALLN_TR "1")(= RBN_TR "1"))(Command "TEXT" "79.5842,96.8110" "2.25" "0" (princ PRINT_AREA)))

 

(If (= BN_TR "1")(Command "TEXT" "91.2543,96.8110" "2.25" "0" (princ PRINT_AREA)))

 

(If (= IS_TR "1")(Command "TEXT" "124.0738,101.7847" "2.25" "0" (princ PRINT_AREA)))

 

Thanks in advance for any advice on this

 

---AJS

Link to comment
Share on other sites

This may help you work it out :

 

(defun c:test  (/ B_AREA T_AREA BN_TR col1 col2 PRINT_AREA)
 (setq B_AREA "TEST1" T_AREA "TEST2" BN_TR "1")
 (setq col1 (itoa (acad_colordlg 0 T))
   col2 (itoa (acad_colordlg 0 T)))
 (setq PRINT_AREA (strcat "B Area: \{\\C" col1 ";" B_AREA "\} s.f. T Area: \{\\C" col2 ";" T_AREA "\} s.f."))
 (command "layer" "SET" "VARTEXT_1" "")
 (if (or (= LBN_TR "1") (= ALLN_TR "1") (= RBN_TR "1"))
   (command "-MTEXT" "79.5842,96.8110" "H" "2.25" "R" "0" "@50,-50" PRINT_AREA ""))
 (if (= BN_TR "1")
   (command "-MTEXT" "91.2543,96.8110" "H" "2.25" "R" "0" "@50,-50" PRINT_AREA ""))
 (if (= IS_TR "1")
   (command "-MTEXT" "124.0738,101.7847" "H" "2.25" "R" "0" "@50,-50" PRINT_AREA ""))
 (princ))

Link to comment
Share on other sites

No Worries AJS,

 

You will only be able to use MTEXT to accomplish this goal - as single-line text (DTEXT) does not allow this feature.

 

You have to mess around with the input string to change the text colour, using bracketed terms using curly braces "{" to enclose coloured text.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...