Code Red > .NET

Updating MTEXT C#

(1/3) > >>

nocent:
Update: Resolved by only passing in 1 argument into this method.

Hi all,
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:
--- Quote ---var obj = tr.GetObject(id, OpenMode.ForRead);
--- End quote ---
- 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?




--- Code: ---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();
}
}
--- End code ---

Thanks!  -Bruce

Updates:

* Using Autocad 2015
* Drawings/layers arent locked

Jeff H:
Was there anymore information with error?
Maybe on locked layer?

nocent:
The layers arent locked, ive tried it on several drawings to try to weed out that dwg itself being the issue.
This is with using autocad 2015.

MexicanCustard:
Can you post the drawing your working in?

nocent:
I came through the issue (workaround?)!

The method doesnt work when passing in two arguments.  The fix was to fix the method signature to accept one argument, in my case an object that carried the handle and new value.

Phew!

Navigation

[0] Message Index

[#] Next page

Go to full version