Author Topic: Creating mtext with varying height and colours  (Read 604 times)

0 Members and 1 Guest are viewing this topic.

Windsor

  • Mosquito
  • Posts: 14
Creating mtext with varying height and colours
« on: February 21, 2024, 10:43:22 AM »
Is it possible to create an mtext object via autolisp where the user inputs a string of text  (i.e. "PLAN ON BASE") which is has a specified height and colour, then skip a line and write a new line with a different text height and colour? (see image attached for reference)

I know that I can use dtext to do this but is there a method where either these are joined into an mtext object or done directly to mtext.


Any help would be greatly appreciated!

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Creating mtext with varying height and colours
« Reply #1 on: February 21, 2024, 12:49:44 PM »
Yes - you can embed formatting codes within the MText content.

BIGAL

  • Swamp Rat
  • Posts: 1417
  • 40 + years of using Autocad
Re: Creating mtext with varying height and colours
« Reply #2 on: February 21, 2024, 11:02:50 PM »
An example of text, the Cx is color number, the H is a height factor. The \\P is line break.

{\\C1;\\H1.6x;PLAN ON BASE}\\P{\\C3;A1 Scale 1:250}\\P{\\C4;A3 scale 1:500}"
A man who never made a mistake never made anything

Windsor

  • Mosquito
  • Posts: 14
Re: Creating mtext with varying height and colours
« Reply #3 on: February 23, 2024, 07:59:32 AM »
Thanks a million guys, with my limited AutoLisp experience, I would have just attempted to insert individual texts and change their properties individually.

I am attempting to create code to go along with this to insert into a drawing. can you give me any pointers as to where to go from here? I'm attempting to specify the description, A1 scale and A3 scale then put it all together with the relevant formatting.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / p Des A1 A3)
  2.        
  3.         (setq Des (getstring "\nEnter Description: "))
  4.         (setq A1 (getint "\nEnter Scale at A1: "))
  5.         (setq A3 (* A1 2))
  6.         (setq txt (strcat "{\\C4;\\H4x;" Des "}\\P{\\C7;\\H2x;A1 SCALE 1:" A1 "}\\P{\\C7;\\H2x;A3 SCALE 1:" A3 "}"))
  7.  
  8.        
  9.         (if (setq p (getpoint "\nText Insertion Point: "))
  10.         (entmake
  11.             (list
  12.                '(000 . "MTEXT")
  13.                '(100 . "AcDbEntity")
  14.                '(100 . "AcDbMText")
  15.                 (cons 010 (trans p 1 0))
  16.                '(001 . txt)
  17.                            '(007 . "standard")
  18.                '(041 . 0)
  19.                '(040 .  1.0)
  20.             )
  21.         )
  22.     )
  23.     (princ)
  24. )

BIGAL

  • Swamp Rat
  • Posts: 1417
  • 40 + years of using Autocad
Re: Creating mtext with varying height and colours
« Reply #4 on: February 23, 2024, 11:02:02 PM »
In the strcat you must have strings A1 is a number so is A3 (* A1 2) need to use (rtos A1 2 0) look up help Rtos and what the 2 0 means.
A man who never made a mistake never made anything

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Creating mtext with varying height and colours
« Reply #5 on: February 26, 2024, 06:12:54 AM »
Use itoa to convert your integer variables to a string before concatenation.

Windsor

  • Mosquito
  • Posts: 14
Re: Creating mtext with varying height and colours
« Reply #6 on: February 27, 2024, 03:55:23 AM »
Thanks guys, I have it working as expected now!

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Creating mtext with varying height and colours
« Reply #7 on: February 27, 2024, 11:50:23 AM »
Yes - you can embed formatting codes within the MText content.

I did not know this one existed. Good stuff!

Code: [Select]
\Tvalue;

Adjusts the space between characters. Valid values range from a minimum of .75 to 4 times the original spacing between characters.

\T2;Autodesk
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox