Change an Entity in an Extern DWG

Change an Entity in an Extern DWG

Anonymous
Not applicable
494 Views
2 Replies
Message 1 of 3

Change an Entity in an Extern DWG

Anonymous
Not applicable
Hi,
I want to change an Mtext in an extern DWG.
I Tried it with this code:

Database db = new Database(false, false);
db.ReadDwgFile("C:\\Zeichnung123.dwg", System.IO.FileShare.ReadWrite, true, "");

Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
Autodesk.AutoCAD.DatabaseServices.Transaction tr = tm.StartTransaction();

//texte.Contents = FormSprache.ShowDialog("");
//PromptPointOptions prPO = new PromptPointOptions("\nAn welche Stelle soll das Textfeld");

PromptStringOptions pso1 = new PromptStringOptions("Geben Sie die ObjectId ein:");

PromptResult presult = ed.GetString(pso1);
if (presult.Status == PromptStatus.OK)
{
String stringobjectid = presult.StringResult.ToString();

ObjectId test = new ObjectId(2130268248);
test.GetObject(OpenMode.ForWrite, false);
MText texte = (MText)tm.GetObject(test, OpenMode.ForWrite);
texte.Contents = "blablub";

tr.Commit();

MeineForms.MessageBox.Show(texte.ObjectId.ToString());


}

if i run the code then Autocad says that he not found the ObjectId.

But if i open the dwg and try the same on the activedocument database it is successfully.

I hope anybody can help me.

Maybe in you can answer me in german 🙂

Greetings Steffen
0 Likes
495 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
You need to read and study the ObjectARX documentation, because anyone that does that, should know and understand that an ObjectId is not a permanent reference that you can use across different AutoCAD sessions.

Try not to depend on folks here to teach you what you can easily learn by studying the docs and the samples.

The only permanent way to reference to an object in a drawing file, is by using its Handle.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:[email protected]...
Hi,
I want to change an Mtext in an extern DWG.
I Tried it with this code:

Database db = new Database(false, false);
db.ReadDwgFile("C:\\Zeichnung123.dwg", System.IO.FileShare.ReadWrite, true, "");

Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
Autodesk.AutoCAD.DatabaseServices.Transaction tr = tm.StartTransaction();

//texte.Contents = FormSprache.ShowDialog("");
//PromptPointOptions prPO = new PromptPointOptions("\nAn welche Stelle soll das Textfeld");

PromptStringOptions pso1 = new PromptStringOptions("Geben Sie die ObjectId ein:");

PromptResult presult = ed.GetString(pso1);
if (presult.Status == PromptStatus.OK)
{
String stringobjectid = presult.StringResult.ToString();

ObjectId test = new ObjectId(2130268248);
test.GetObject(OpenMode.ForWrite, false);
MText texte = (MText)tm.GetObject(test, OpenMode.ForWrite);
texte.Contents = "blablub";

tr.Commit();

MeineForms.MessageBox.Show(texte.ObjectId.ToString());


}

if i run the code then Autocad says that he not found the ObjectId.

But if i open the dwg and try the same on the activedocument database it is successfully.

I hope anybody can help me.

Maybe in you can answer me in german 🙂

Greetings Steffen
0 Likes
Message 3 of 3

Anonymous
Not applicable
Thank you Tony.
I got it with the Handle...
0 Likes