using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(WipeoutToBottom.MyCommands))]
namespace WipeoutToBottom
{
public class MyCommands
{
[CommandMethod("WipeoutToBottom")]
public void WipeoutToBottomHandler()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null) return;
Editor ed = doc.Editor;
Database db = doc.Database;
PromptEntityOptions prOpt =
new PromptEntityOptions("Выберите вставку блока: ");
prOpt.SetRejectMessage("Это не блок!");
prOpt.AddAllowedClass(typeof(BlockReference), true);
PromptEntityResult prRes = ed.GetEntity(prOpt);
if (prRes.Status != PromptStatus.OK)
return;
using (Transaction tr = doc.TransactionManager.StartTransaction())
{
BlockReference br = (BlockReference) tr.GetObject(prRes.ObjectId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(br.BlockTableRecord, OpenMode.ForRead);
ObjectIdCollection idsWipeout = new ObjectIdCollection();
foreach (ObjectId id in btr) {
if (id.ObjectClass.IsDerivedFrom(RXClass.GetClass(typeof(Wipeout)))) {
idsWipeout.Add(id);
}
}
if (idsWipeout.Count > 0) {
DrawOrderTable dot = (DrawOrderTable)tr.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite);
dot.MoveToBottom(idsWipeout);
}
tr.Commit();
}
ed.Regen();
}
}
}