马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 csharp 于 2014-7-17 22:23 编辑
无需选择直接执行

- //所有 Hatch 置底
- [CommandMethod("test")]
- public void HatchMoveBottom()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Editor ed = doc.Editor;
- Database db = doc.Database;
- Transaction tr = doc.TransactionManager.StartTransaction();
- using (tr)
- {
- try
- {
- BlockTable bts = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
- bool hatinblk = false;
- foreach (ObjectId id in bts)
- {
- BlockTableRecord btr = (BlockTableRecord)tr.GetObject(id, OpenMode.ForRead);
- //含有Hatch的块定义内DrawOrder
- if (!btr.IsLayout && !btr.IsFromExternalReference)
- {
- ObjectIdCollection ids = new ObjectIdCollection();
- DrawOrderTable blkDor = (DrawOrderTable)tr.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite);
- foreach (ObjectId obj in btr)
- {
- Entity ent = (Entity)tr.GetObject(obj, OpenMode.ForRead);
- if (ent is Hatch)
- {
- ids.Add(obj);
- }
- }
- if (ids.Count > 0)
- {
- blkDor.MoveToBottom(ids);
- hatinblk = true;
- }
- }
- }
- //Datebase 内 DrawOrder
- BlockTableRecord acBtRecord = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
- var dor = (DrawOrderTable)tr.GetObject(acBtRecord.DrawOrderTableId, OpenMode.ForWrite);
- ObjectIdCollection hCollection = new ObjectIdCollection();
- foreach (ObjectId id in acBtRecord)
- {
- Entity ent = (Entity)id.GetObject(OpenMode.ForRead);
- if (ent is Hatch) hCollection.Add(id);
- }
- if (hCollection.Count > 0) dor.MoveToBottom(hCollection);
- if (hatinblk) ed.Regen();//块定义修改后要 Regen
- tr.Commit();
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
|