zoukankan      html  css  js  c++  java
  • 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);
    		}
    	}
    }
  • 相关阅读:
    两条斜线
    Cantor表
    城市网络
    一起来数二叉树吧
    牛客网音乐研究(枚举)
    删括号
    合并回文子串
    寻找道路
    EXTJS 4.0.2 XML数据
    extjs4.0.2a gridpanel看不到横向滚动条的一种原因
  • 原文地址:https://www.cnblogs.com/swtool/p/14419817.html
Copyright © 2011-2022 走看看