public void DrawOnTop() { Transaction trans = _document.TransactionManager.TopTransaction; BlockTableRecord btr = _document.Database.GetModelSpace(false); DrawOrderTable drawOrder = trans.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite) as DrawOrderTable; ObjectIdCollection ids = new ObjectIdCollection(); ids.Add(BaseObject); drawOrder.MoveToTop(ids); }
///// <summary> ///// 设置动态块属性 ///// </summary> ///// <param name="br">要设置属性的动态块参照</param> ///// <param name="Properties">属性数组</param> //public static void SetDynamicValue(BlockReference br, Property[] properties) //{ // try // { // if (br.IsDynamicBlock) // { // foreach (DynamicBlockReferenceProperty dbrp in br.DynamicBlockReferencePropertyCollection) // { // for (int i = 0; i < properties.Length; i++) // { // if (dbrp.PropertyName == properties[i].PropertyName) // { // dbrp.Value = properties[i].Value; // } // } // } // } // } // catch // { } //} ///// <summary> ///// 动态块属性 ///// </summary> //public class Property //{ // private string propertyname; // private double value; // public string PropertyName // { // get { return propertyname; } // } // public double Value // { // get { return value; } // } // public Property(string PropertyName, double Value) // { // propertyname = PropertyName; // value = Value; // } //} /// <summary> /// 改变对象的绘图次序到顶层 /// </summary> /// <param name="ent"></param> /// <param name="db"></param> public static void MoveTop(this Entity ent, Database db) { using (Transaction tr = db.TransactionManager.StartTransaction()) { ObjectIdCollection idc = new ObjectIdCollection(); idc.Add(ent.ObjectId); BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite, false); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false); DrawOrderTable orderTable = tr.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite) as DrawOrderTable; orderTable.MoveToTop(idc); tr.Commit(); } }
/// <summary> /// /// </summary> /// <param name="ent"></param> /// <param name="db"></param> public bool MoveTop(bool istop) { DocumentLock doclock = null; try { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; doclock = doc.LockDocument(); Database db = HostApplicationServices.WorkingDatabase; using (Transaction tr = db.TransactionManager.StartTransaction()) { try { ObjectIdCollection idc = new ObjectIdCollection(); idc.Add(parEntityId); BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite, false); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false); DrawOrderTable orderTable = tr.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite) as DrawOrderTable; if (istop) { orderTable.MoveToTop(idc); } else { orderTable.MoveToBottom(idc); } } catch (Autodesk.AutoCAD.Runtime.Exception eex) { } catch (System.Exception ex) { } tr.Commit(); } } catch (Autodesk.AutoCAD.Runtime.Exception eex) { return(false); } catch (System.Exception ex) { return(false); } finally { doclock.Dispose(); } return(true); }
/// <summary> /// Sets the display order. /// </summary> /// <param name="transaction">The transaction.</param> /// <param name="oids">The object ids.</param> /// <param name="sendToTop">The draw order.</param> public static void SetDisplayOrder(Transaction transaction, ObjectIdCollection oids, bool sendToTop) { //_logger.Debug("Start SetDisplayOrder"); if (oids == null) { throw new NullReferenceException("oids is null"); } // verify the arguments // if (oids.Count == 0) { return; } // get the database from the the first objectId // Autodesk.AutoCAD.DatabaseServices.Database db = oids[0].Database; // create a transaction if needed // Transaction trans = null; if (transaction == null) { trans = db.TransactionManager.StartTransaction(); } else { trans = transaction; } // now get the draworder table and set accordingly // using (BlockTable blockTable = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead)) { using (BlockTableRecord btr = (BlockTableRecord)trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite)) { using (DrawOrderTable drawOrderTable = trans.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite) as DrawOrderTable) { if (drawOrderTable != null) { if (sendToTop) { drawOrderTable.MoveToTop(oids); } else { drawOrderTable.MoveToBottom(oids); } } } } } // cleanup transaction if needed // if (transaction == null) { trans.Commit(); trans.Dispose(); } //_logger.Debug("End SetDisplayOrder"); }