TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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!
-
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.
-
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}"
-
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.
(defun c:test
( / p Des A1 A3
)
(setq txt
(strcat "{\\C4;\\H4x;" Des
"}\\P{\\C7;\\H2x;A1 SCALE 1:" A1
"}\\P{\\C7;\\H2x;A3 SCALE 1:" A3
"}"))
'(000 . "MTEXT")
'(100 . "AcDbEntity")
'(100 . "AcDbMText")
'(001 . txt)
'(007 . "standard")
'(041 . 0)
'(040 . 1.0)
)
)
)
)
-
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.
-
Use itoa to convert your integer variables to a string before concatenation.
-
Thanks guys, I have it working as expected now!
-
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!
\Tvalue;
Adjusts the space between characters. Valid values range from a minimum of .75 to 4 times the original spacing between characters.
\T2;Autodesk