编程语言
首页 > 编程语言> > AutoCAD.Net/C#.Net QQ群:193522571 AutoCAD中重写命令,在命令执行前进行拦截并进行处理

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,string,sPartType,Contains,命令,sh,brf,sCmdName,Net
来源: https://www.cnblogs.com/swtool/p/14472502.html