• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

AutoCAD.Net/C#.NetQQ群:193522571C#命令重写,重定义,Override,Overrule

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

解决方案:
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);
		}
	}
}

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
ArrayList集合--C#发布时间:2022-07-13
下一篇:
C#重载,重写,代理,枚举实例发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap