Message 1 of 5
How to create 3D text object?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
I have an issue that I would like to ask for expert advice on. I'm trying to create a 3D text line, but my code gets stuck at the "explode text" step. Here’s my approach:
- Prompt the user for the text content.
- Specify the insertion point.
- Execute the commands: TXTEXP, REGION, UNION, EXTRUDE.
Could someone please help me figure out what might be going wrong? I’m not sure why it’s not working.
Thank you!
[CommandMethod("Create3DText")]
public void Create3DText()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
Application.DocumentManager.MdiActiveDocument.SendStringToExecute("_PLAN ", true, false, false);
PromptStringOptions promptText = new PromptStringOptions("\nInsert your text: ");
PromptResult textResult = ed.GetString(promptText);
if (textResult.Status != PromptStatus.OK) return;
string textContent = textResult.StringResult;
PromptPointOptions promptPoint = new PromptPointOptions("\nSelect insert point: ");
PromptPointResult pointResult = ed.GetPoint(promptPoint);
if (pointResult.Status != PromptStatus.OK) return;
Point3d textPosition = pointResult.Value;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
DBText dbText = new DBText
{
TextString = textContent,
Position = textPosition,
Height = 10,
};
Application.DocumentManager.MdiActiveDocument.SendStringToExecute("_TXTEXP ", true, false, false);
Application.DocumentManager.MdiActiveDocument.SendStringToExecute("_REGION _ALL ", true, false, false);
Application.DocumentManager.MdiActiveDocument.SendStringToExecute("_UNION ", true, false, false);
Application.DocumentManager.MdiActiveDocument.SendStringToExecute("_EXTRUDE _P 5 ", true, false, false);
btr.AppendEntity(dbText);
tr.AddNewlyCreatedDBObject(dbText, true);
tr.Commit();
}
}