Update: Resolved by only passing in 1 argument into this method.
Beginner developer and autocad API user here whos had no luck googling this. Hoping someone can point me in the right direction.
The goal is to update the mtext .contents. The following code "opened .ForRead" can read mtext.contents perfectly fine. However, when i try to ".forWrite" i get the following exception:
Autodesk.AutoCAD.Runtime.Exception' in AcdbMgd.dll
Walking through the code it fails on line:
var obj = tr.GetObject(id, OpenMode.ForRead);
- but only on write mode.
The handle im passing in points back to an mtext object, and appears to be getting the correct object ID during conversion. I havent eliminated this to be cause the caues of the problem however.
Does anyone have any code i can refer to for updating MText or could point me in the right direction?
public static void editMtextContents(string handle, string newValue)
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Handle hn = new Handle(ConvertHandleToInt(handle));
Transaction tr = db.TransactionManager.StartTransaction();
ObjectId id = db.GetObjectId(false, hn, 0);
var obj = tr.GetObject(id, OpenMode.ForWrite, false);
var mtext = obj as MText;
mtext.Contents = newValue;
- Using Autocad 2015
- Drawings/layers arent locked