- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[CommandMethod("WorkWithLockedLayers","wlock", CommandFlags.UsePickSet | CommandFlags.Redraw)]
public void testWorkOnLockedLayers()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
bool fine = true;
ObjectIdCollection locked = new ObjectIdCollection();
try
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
foreach (ObjectId ltId in lt)
{
if (ltId.IsValid && ltId.IsResident && !ltId.IsErased) // just drawing layers were allowed
{
LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(ltId, OpenMode.ForRead);
if (ltr.IsLocked)
{
locked.Add(ltId);
ltr.UpgradeOpen();
ltr.IsLocked = false;
ltr.DowngradeOpen();// optional
}
}
}
//
// Here you begin to work with objects and not worry that they are in the locked layers
// e.g. itrerate through selection etc. (poor code commented)
//SelectionSet ss = ed.SelectAll().Value;
//foreach (ObjectId id in ss.GetObjectIds())
//{
// Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite);
// ent.ColorIndex = 121;
//}
//
foreach (ObjectId ltId in lt)
{
LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(ltId, OpenMode.ForWrite);
ltr.IsLocked = true;
}
tr.Commit();
}
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
fine = false;
ed.WriteMessage(ex.ToString());
}
finally
{
if (!fine)
doc.SendStringToExecute("_layerp", true, false, false);
}
} |
|