TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Windsor on February 21, 2024, 10:43:22 AM

Title: Creating mtext with varying height and colours
Post by: Windsor 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!
Title: Re: Creating mtext with varying height and colours
Post by: Lee Mac on February 21, 2024, 12:49:44 PM
Yes - you can embed formatting codes (https://help.autodesk.com/view/ACD/2024/ENU/?guid=GUID-7D8BB40F-5C4E-4AE5-BD75-9ED7112E5967) within the MText content.
Title: Re: Creating mtext with varying height and colours
Post by: BIGAL 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}"
Title: Re: Creating mtext with varying height and colours
Post by: Windsor 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. )
Title: Re: Creating mtext with varying height and colours
Post by: BIGAL 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.
Title: Re: Creating mtext with varying height and colours
Post by: Lee Mac on February 26, 2024, 06:12:54 AM
Use itoa to convert your integer variables to a string before concatenation.
Title: Re: Creating mtext with varying height and colours
Post by: Windsor on February 27, 2024, 03:55:23 AM
Thanks guys, I have it working as expected now!
Title: Re: Creating mtext with varying height and colours
Post by: alanjt on February 27, 2024, 11:50:23 AM
Yes - you can embed formatting codes (https://help.autodesk.com/view/ACD/2024/ENU/?guid=GUID-7D8BB40F-5C4E-4AE5-BD75-9ED7112E5967) 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