- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
public static ErrorStatus fixoGetEntity(Transaction tr, Editor ed, RXClass rx, string msg, out ObjectId id)
{
ErrorStatus es;
Entity ent;
id = ObjectId.Null;
PromptEntityOptions peo = new PromptEntityOptions(msg);
peo.SetRejectMessage("\nYou're missing, try again >>");
peo.AddAllowedClass(typeof(Entity), false);
PromptEntityResult res;
res = ed.GetEntity(peo);
if (res.Status != PromptStatus.OK)
es = ErrorStatus.PointNotOnEntity;
id = res.ObjectId;
if (id == ObjectId.Null)
es = ErrorStatus.NullObjectId;
ent = tr.GetObject(id, OpenMode.ForRead, false) as Entity;
if (ent.GetRXClass() != rx)
{
ed.WriteMessage("\n{0}Must be a \"{0}\" type of only!",rx.DxfName);
es = ErrorStatus.NotThatKindOfClass;
}
if (ent == null)
es = ErrorStatus.NotAnEntity;
else es = ErrorStatus.OK;
return es;
}
// Use function above this way
[CommandMethod("tef")]
public static void testSelectFunction()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
ObjectId id = ObjectId.Null;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
if (fixoGetEntity(tr, ed, RXClass.GetClass(typeof(MText)), "\nSelect MTEXT to edit", out id) == ErrorStatus.OK)
{
ed.WriteMessage("\nObjectId: {0}\n", id);
ed.WriteMessage("\nEntity Name: {0}\n", id.ObjectClass.DxfName);
// get entity by direct cast
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite);
ent.ColorIndex = 121;// do whatever you need with entity here
tr.Commit();
}
}
} |
|