- 积分
- 526
- 明经币
- 个
- 注册时间
- 2006-10-27
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
目的:选择一个entity,当这个entity是Mtext的时候,改变Mtext的内容
加载,运行,提示这里不对--btr.AppendEntity(ent);
代码如下:
[CommandMethod("selectent")]
public void secectent()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed=doc.Editor;
PromptEntityOptions opts = new PromptEntityOptions("\nPlease select a Mtext");
opts.AllowNone = true;
PromptEntityResult res = ed.GetEntity(opts);
if (res.Status == PromptStatus.OK)
{
changes(res.ObjectId);
}
}
public void changes(ObjectId id)
{
BlockTableRecord btr;
BlockTable bt;
Database db = HostApplicationServices.WorkingDatabase;
Transaction tran;
tran = db.TransactionManager.StartTransaction();
Entity ent = (Entity)tran.GetObject(id, OpenMode.ForWrite);
bt = (BlockTable)tran.GetObject(db.BlockTableId, OpenMode.ForRead);
btr = (BlockTableRecord)tran.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
if (ent.GetType() == typeof(MText))
{
MText mt = new MText();
mt = (MText)ent;
mt.Contents = "AAAAA";
}
btr.AppendEntity(ent);
tran.AddNewlyCreatedDBObject(ent, true);
tran.Commit();
tran.Dispose();
}
|
|