Message 1 of 9
Not applicable
02-13-2012
09:57 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi.
I've got a problem with inserting MText into drawings.
The code below works perfectly in new file (AutoCAD 2012 18.2.0.0) and in some files, but in some other files the MText field just doesn't show.
There's no exception thrown, no error messages, debugging shows everything is OK.
How to check, what is wrong?
I mean - what's the difference between those files which I can't insert MText into and those, which I can?
The test code:
[CommandMethod("WTEST3")]
public void wtest3()
{
acApp.Document doc = acApp.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptPointOptions getPointOptions = new PromptPointOptions("Click the point for MText");
PromptPointResult getPointResult = ed.GetPoint(getPointOptions);
if (getPointResult.Status != PromptStatus.OK)
return;
Transaction tr = db.TransactionManager.StartTransaction();
try
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
MText mt = new MText();
mt.Contents = "blah";
mt.Location = new Point3d(getPointResult.Value.X, getPointResult.Value.Y, getPointResult.Value.Z);
btr.AppendEntity(mt);
tr.AddNewlyCreatedDBObject(mt, true);
tr.Commit();
ed.Regen();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
MessageBox.Show("Something went wrong: " + ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
tr.Dispose();
}
}
Solved! Go to Solution.