//按图层列表顺序排序
//列表第一个为显示最顶层- public void SortDrawOrder(string[] layers)
- {
- SelectionObject selObj = new SelectionObject();
- Database db = AcadPropers.Database;
- DocumentLock docLock = AcadPropers.DocumentManager.MdiActiveDocument.LockDocument();
- using (Transaction tr = AcadPropers.Tm.StartTransaction())
- {
- BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite, false);
- BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
- //Get the DrawOrderTable
- DrawOrderTable orderTable = tr.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite) as DrawOrderTable;
- for (int i = layers.Length-1; i >=0; i--)
- {
- string lay = layers[i];
- TypedValue[] typedValue = new TypedValue[] { new TypedValue(8, lay) };
- SelectionFilter filter = new SelectionFilter(typedValue);
- ObjectId[] ids = selObj.ssGet(filter);//选择图层对象
- if(ids!=null)
- {
- ObjectIdCollection objectIdColl = new ObjectIdCollection(ids);
- orderTable.MoveToTop(objectIdColl);//设置选定对象置顶
- }
- }
- //刷新显示
- AcadPropers.Editor.Regen();
- tr.Commit();
- }
- docLock.Dispose();
- }
|