下面的例子在当前空间中遍历,并改变直线和圆的颜色,注意Cad版本2009及以上
相关的讨论帖
-
- [CommandMethod("t8")]
- public static void Test8()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
- var dict =
- from ObjectId id in btr
- group id by id.ObjectClass.DxfName;
- foreach (var ids in dict)
- {
- switch (ids.Key)
- {
- case "LINE":
- foreach (var id in ids)
- {
- Entity ent = id.GetObject(OpenMode.ForWrite) as Entity;
- ent.ColorIndex = 1;
- }
- break;
- case "CIRCLE":
- foreach (var id in ids)
- {
- Entity ent = id.GetObject(OpenMode.ForWrite) as Entity;
- ent.ColorIndex = 3;
- }
- break;
- }
- }
- tr.Commit();
- }
- }
本帖以下内容被隐藏保护;需要你回复后,才能看到! 游客,如果您要查看本帖隐藏内容请 回复 |