- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2014-6-7 03:36:45
|
显示全部楼层
[CommandMethod("loff")]
public static void testLayersOff()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
PromptEntityOptions opt = new PromptEntityOptions( "\nSelect an entity :");
PromptEntityResult res = ed.GetEntity(opt);
if (res.Status != PromptStatus.OK) return;
ObjectId entId= res.ObjectId;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Entity ent= tr.GetObject(entId, OpenMode.ForRead) as Entity;
if (ent==null) return;
string lname= ent.Layer;
using (LayerTable lt = db.LayerTableId.GetObject(OpenMode.ForRead, false) as LayerTable)
{
LayerTableRecord clayer = tr.GetObject(db.Clayer, OpenMode.ForRead) as LayerTableRecord; //current layer
if (lt[lname]==db.Clayer)
{
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Could not turn off the current layer.");
return;
}
LayerTableRecord ltr = tr.GetObject(lt[lname], OpenMode.ForWrite, false) as LayerTableRecord;
if ((!ltr.IsDependent) && ((!ltr.Name.Contains("*|*")) | (!ltr.Name.Contains("X*"))))
{
ltr.IsOff = true;
}
}
tr.Commit();
}
}
|
|