I needed to know programmatically the width of various textstrings using various Styles.
The Text is just strings, not the value of a database resident object.
Persistance paid off ....
There are several nice methods in the
Autodesk.AutoCAD.GraphicsInterface namespace
This is a tester to prove the concept :
I haven't idiot-proofed it yet, so don't take it to the bank without some testing.
//================================================
[CommandMethod("TextExtentsTest2")]
static public void TextWidth() {
var ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
var ts
= new Autodesk
.AutoCAD.GraphicsInterface.TextStyle(); ts.FromTextStyleTableRecord("Standard");
ts.TextSize = 25;
ed.WriteMessage("AP " + ts.ExtentsBox("AP", true, false, null).MaxPoint.X);
ed.WriteMessage("\nAPPLE " + ts.ExtentsBox("APPLE", true, false, null).MaxPoint.X);
ed.WriteMessage("\nAPPLESAUCE " + ts.ExtentsBox("APPLESAUCE", true, false, null).MaxPoint.X);
}
//================================================