var obj = tr.GetObject(id, OpenMode.ForRead);- but only on write mode.
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();
using (tr)
{
ObjectId id = db.GetObjectId(false, hn, 0);
var obj = tr.GetObject(id, OpenMode.ForWrite, false);
var mtext = obj as MText;
mtext.Contents = newValue;
tr.Commit();
}
}
public static void EditMtextContents(UpdatedTag tag)
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
//create handle from long int
Handle hn = new Handle(ConvertHandleToInt(tag.Handle));
//attempt to get an ObjectID for the handle
ObjectId id = db.GetObjectId(false, hn, 0);
//open the object to edit it
using (DocumentLock doclock = doc.LockDocument())
{
Transaction tr = doc.TransactionManager.StartTransaction();
using (tr)
{
DBObject obj = tr.GetObject(id, OpenMode.ForWrite);
//testing editing mtext contents
MText mtext = obj as MText;
mtext.Contents = tag.NewValue;
tr.Commit();
}
}
}
public class UpdatedTag
{
public string Handle { get; set; }
public string NewValue { get; set; }
public UpdatedTag(string handle, string newValue)
{
Handle = handle;
NewValue = newValue;
}
}
public class UpdatedTag
{
public string Handle { get; set; }
public string NewValue { get; set; }
public UpdatedTag(string handle, string newValue)
{
Handle = handle;
NewValue = newValue;
}
}
Are you storing the UpdatedTag object between sessions? If not, then why not just use the ObjectId?