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


    解决方案:
    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("
    不能删除!");
    	}
    }
    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("
    ** Cannot explode custom object ** ");
    				}
    
    				return;
    			}
    			else
    				base.Explode(e, objs);
    		}
    		catch (System.Exception ex)
    		{
    			ed.WriteMessage("
    error; SystemException: {0} ", ex.Message);
    		}
    	}
    }
  • 相关阅读:
    python进阶(1)--多进程与多线程概念
    mysql数据库(5)--表的相关操作
    mysql数据库(4)--表删除操作
    备注
    mysql数据库(3)--mysql的执行顺序
    mysql数据库(2)--窗口函数之序号函数
    Spring MVC 返回中文乱码
    郁闷,郁闷啊
    Struts2 下载文件
    js文件加载
  • 原文地址:https://www.cnblogs.com/swtool/p/14419817.html
Copyright © 2020-2023  润新知