- 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 type of \"{0}\" only!", rx.DxfName);
es = ErrorStatus.NotThatKindOfClass;
}
if (ent == null)
es = ErrorStatus.NotAnEntity;
else es = ErrorStatus.OK;
return es;
}
[CommandMethod("BM")]
static public void test_setBackgroundFill_MText()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = HostApplicationServices.WorkingDatabase;
ObjectId id = ObjectId.Null;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
if (fixoGetEntity(tr, ed, RXClass.GetClass(typeof(MText)), "\nPlease pick an MText entity: ", out id) == ErrorStatus.OK)
{
BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
// get entity by direct cast
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead);
if (id.ObjectClass.DxfName == "MTEXT")
{
MText mtx = ent as MText;
mtx.UpgradeOpen();
Autodesk.AutoCAD.Colors.Color color;
if (mtx.BackgroundFill )
{
mtx.UseBackgroundColor= false;
mtx.BackgroundFill=false;
}
else
{
mtx.BackgroundFill=true;
color = Color.FromColorIndex(ColorMethod.ByAci, (int)1);
mtx.BackgroundFillColor = color;
mtx.UseBackgroundColor=false;
}
mtx.RecordGraphicsModified(true);
}
}
tr.Commit();
}
}
|
|