解决方案:
public class ObjectRule : ObjectOverrule
{
public override void Erase(DBObject dbObject, bool erasing)
{
base.Erase(dbObject, erasing);
//定义数据库
Database db = HostApplicationServices.WorkingDatabase;
//获取当前文件
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
//获取当前命令行对象
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage("\n不能删除!");
}
}
public partial class Commands : IExtensionApplication
{
private static ObjectRule objectRule;
public void Initialize()
{
if (objectRule == null)
{
objectRule = new PvTools.ObjectRule();
Overrule.AddOverrule(RXObject.GetClass(typeof(BlockReference)), objectRule, false);
objectRule.SetXDataFilter("BOM");//过滤
}
}
public void Terminate()
{
throw new NotImplementedException();
}
}
下面这个是网上找到的参考资料
public class ExplodeOverrule : TransformOverrule
{
private static DocumentCollection acDocs = acApp.DocumentManager;
public override void Explode(Entity e, DBObjectCollection objs)
{
Document doc = acDocs.MdiActiveDocument;
Editor ed = doc.Editor;
try
{
ResultBuffer rb = e.GetXDataForApplication(Overrule.GetClass);
if (rb != null)
{
Database db = doc.Database;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt =
(BlockTable)tr.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr =
(BlockTableRecord)tr.GetObject(bt[e.BlockName],
OpenMode.ForWrite);
Entity ent = e.Clone() as Entity;
btr.AppendEntity(ent);
tr.AddNewlyCreatedDBObject(ent, true);
tr.Commit();
ed.WriteMessage("\n** Cannot explode custom object ** ");
}
return;
}
else
base.Explode(e, objs);
}
catch (System.Exception ex)
{
ed.WriteMessage("\nerror; SystemException: {0} ", ex.Message);
}
}
}
|
请发表评论