Author Topic: Setting Color for 2nd Character in Mtext  (Read 524 times)

0 Members and 1 Guest are viewing this topic.

MeasureUp

  • Bull Frog
  • Posts: 441
Setting Color for 2nd Character in Mtext
« on: January 27, 2021, 07:45:34 PM »
As the title mentioned I want to set color (other than the default) for the 2nd character in mtext that I am creating.
I don't find anything that can do the setting for individual character from the group codes of entmake for mtext.
Your helps are much appreciated.

d2010

  • Newt
  • Posts: 154
Re: Setting Color for 2nd Character in Mtext
« Reply #1 on: January 27, 2021, 11:31:25 PM »
Sărbătoarea Aducerii moaștelor Sfântului Ierarh Ioan Gură de Aur

BIGAL

  • Swamp Rat
  • Posts: 665
  • 30 + years of using Autocad
Re: Setting Color for 2nd Character in Mtext
« Reply #2 on: January 27, 2021, 11:41:23 PM »
You may need to entmake the mtext as a dummy text "a" then use vl-put-textstring with the correct coding of the top of my head "a{\\C1b}cdef"

The "b" will be red.
A man who never made a mistake never made anything

MeasureUp

  • Bull Frog
  • Posts: 441
Re: Setting Color for 2nd Character in Mtext
« Reply #3 on: January 28, 2021, 05:33:27 PM »
Sorry, I don't get it.
Here is a simple code.

Code: [Select]
(defun c:MyMessage (/ GetMessage InsertPoint)

(setq GetMessage (getstring T "Enter Message: "))

; As an example the message is "R+ will be added on Level 2."
; How to set the 2nd character color as yellow?

(setq InsertPoint (getpoint  "Insert Message"))

(entmake
(list '(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") (cons 1 GetMessage) (cons 10 InsertPoint) (cons 40 25))
); end of entmake

); end of code

Thanks.

Tharwat

  • Swamp Rat
  • Posts: 597
  • Hypersensitive
Re: Setting Color for 2nd Character in Mtext
« Reply #4 on: January 28, 2021, 06:21:03 PM »
Here you go.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:MyMessage (/ GetMessage InsertPoint two)
  2.   (and (/= "" (setq GetMessage (getstring T "\nEnter Message: ")))
  3.        (setq InsertPoint (getpoint "\nInsert Message"))
  4.        (or (and (> (strlen GetMessage) 1)
  5.                 (/= (setq two (substr GetMessage 2 1)) " ")
  6.                 (setq GetMessage
  7.                        (strcat (substr GetMessage 1 1)
  8.                                "{\\C2;"
  9.                                two
  10.                                "}"
  11.                                (substr GetMessage 3)
  12.                        )
  13.                 )
  14.            )
  15.            GetMessage
  16.        )
  17.        (entmake (list '(0 . "MTEXT")
  18.                       '(100 . "AcDbEntity")
  19.                       '(100 . "AcDbMText")
  20.                       (cons 1 GetMessage)
  21.                       (cons 10 InsertPoint)
  22.                       (cons 40 25)
  23.                 )
  24.        )
  25.   )
  26.   (princ)
  27. )
  28.  

MeasureUp

  • Bull Frog
  • Posts: 441
Re: Setting Color for 2nd Character in Mtext
« Reply #5 on: January 28, 2021, 10:46:13 PM »
Thanks Tharwat.
The {\\Cx; A} works!
Just wondering the written form of {\\Cx; A} for the color setup of individual character.

More questions here.
1. Is there any documentation about the mtext character property setup like {\\Cx; A}?
2. How to add or change the following properties for specified character(s) in mtext?
    2.1. Underline (we use "%%U" for single line text);
    2.2. Strikethrough;
    2.3. Overline (we use "%%O" for single line text);
    2.4. Bold;
    2.5. Italic;
    2.6. Text Style.

Tharwat

  • Swamp Rat
  • Posts: 597
  • Hypersensitive
Re: Setting Color for 2nd Character in Mtext
« Reply #6 on: January 29, 2021, 08:40:29 AM »
You need to read about DXF document in this case and here is the one that is for Mtext object and you can explore for more in the same link:
http://help.autodesk.com/view/OARX/2020/ENU/?guid=GUID-5E5DB93B-F8D3-4433-ADF7-E92E250D2BAB


MeasureUp

  • Bull Frog
  • Posts: 441
Re: Setting Color for 2nd Character in Mtext
« Reply #7 on: February 01, 2021, 07:02:19 PM »
Quote
You need to read about DXF document in this case

Thanks again. But...
I have read it but don't find anything mentioning the use of {\\Cx; A}. And this function doesn't use any DXF group code.

PKENEWELL

  • Bull Frog
  • Posts: 260
Re: Setting Color for 2nd Character in Mtext
« Reply #8 on: February 02, 2021, 03:11:12 PM »
Quote
You need to read about DXF document in this case

Thanks again. But...
I have read it but don't find anything mentioning the use of {\\Cx; A}. And this function doesn't use any DXF group code.

Search your AutoCAD Help for "Format Codes for Alternate Text Editor Reference": https://knowledge.autodesk.com/support/autocad-lt/learn-explore/caas/CloudHelp/cloudhelp/2019/ENU/AutoCAD-LT/files/GUID-7D8BB40F-5C4E-4AE5-BD75-9ED7112E5967-htm.html
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

BIGAL

  • Swamp Rat
  • Posts: 665
  • 30 + years of using Autocad
Re: Setting Color for 2nd Character in Mtext
« Reply #9 on: February 02, 2021, 05:21:26 PM »
A quick and dirty use this 1 liner to look at your mtext, just make it the way you want, color font ht etc you will see the codes used.

(vla-get-textstring  (vlax-Ename->Vla-Object (car (entsel "\pick mtext"))))

pick mtext  "text {\\C1;this red} not red"
A man who never made a mistake never made anything