MText guide
Adding a MTEXT entity
The MTEXT entity can be added to any layout (modelspace, paperspace or block) by the addMText() method.
ts
modelSpace.addMText({
height: 10,
insertionPoint: point(15, 11),
value: "Hello World!",
});modelSpace.addMText({
height: 10,
insertionPoint: point(15, 11),
value: "Hello World!",
});XTextBuilder class
The XTextBuilder provide an esay interface to build MText content.
ts
const builder = new TextBuilder();
const txt = builder.add({
value: "Hello World!",
fontFamily: "Arial",
italic: true,
colorNumber: Colors.Green,
});
const mtext = modelSpace.addMText({
height: 10,
insertionPoint: point(15, 11),
});
mtext.value = builder.value;const builder = new TextBuilder();
const txt = builder.add({
value: "Hello World!",
fontFamily: "Arial",
italic: true,
colorNumber: Colors.Green,
});
const mtext = modelSpace.addMText({
height: 10,
insertionPoint: point(15, 11),
});
mtext.value = builder.value;To create multiple lines you can mark the text as paragraph.
ts
builder.add(
{
value: "Hello World!",
fontFamily: "Arial",
italic: true,
colorNumber: Colors.Green,
},
true // This will make sure to add a line break.
);
builder.add({
value: "Hello World!",
fontFamily: "Arial",
italic: true,
colorNumber: Colors.Green,
});builder.add(
{
value: "Hello World!",
fontFamily: "Arial",
italic: true,
colorNumber: Colors.Green,
},
true // This will make sure to add a line break.
);
builder.add({
value: "Hello World!",
fontFamily: "Arial",
italic: true,
colorNumber: Colors.Green,
});The result will be.
txt
{\C3;\fArial|i1;Hello World!}\P{\C3;\fArial|i1;Hello World!}{\C3;\fArial|i1;Hello World!}\P{\C3;\fArial|i1;Hello World!}Or you can access the property paragraph.
ts
txt1.paragraph = true;txt1.paragraph = true;You can create and style the text manually.