AutoCAD.Net/C#.Net QQ群:193522571 AutoCAD中重写命令,在命令执行前进行拦截并进行处理

private static void CurrentDocument_CommandWillStart(object sender, CommandEventArgs e)
{
string sCmdName = e.GlobalCommandName.ToUpper();
if (sCmdName.Contains("REFEDIT") || sCmdName.Contains("BEDIT"))
{

  }
}
	private static void DocumentManager_DocumentLockModeChanged(object sender, DocumentLockModeChangedEventArgs e)
	{
  //定义数据库
  Database db = HostApplicationServices.WorkingDatabase;

  string sCmdName = e.GlobalCommandName.ToUpper();
  if (e.CurrentMode== DocumentLockMode.Write && (sCmdName.Contains("REFEDIT") || sCmdName.Contains("BEDIT")))
  {
    SelectHelper sh = new SelectHelper();
    using (Transaction trans = db.TransactionManager.StartTransaction())
    {
      sh.GetEntity("\n请点选一个块参照…", "INSERT");
      if (sh.Status == PromptStatus.OK)
      {
        try
        {
          BlockReference brf = (BlockReference)trans.GetObject(sh.ResultObjectId, OpenMode.ForRead);
          string sPartType = brf.GetXdataPartType();
          if (!string.IsNullOrEmpty(sPartType))
          {
            PvEntityEdit(brf, sPartType);
            e.Veto();
          }
        }
        catch
        {
          e.Veto();
        }
      }
      else
      {
        e.Veto();
      }
      trans.Commit();
    }
		}
	}

AutoCAD.Net/C#.Net QQ群:193522571 AutoCAD中重写命令,在命令执行前进行拦截并进行处理

上一篇:C# Elasticsearch帮助类


下一篇:nuxt api缓存,组件缓存,页面缓存