ObjectARX 判断实体是否是在位编辑块对象简单例子

判断使用 acdbIsInLongTransaction 应该就可以。

ads_name ent;
    ads_point pt;
    if(RTNORM != acedEntSel(_T("\n选择对象: "),ent,pt)){
      return;
    }
    AcDbObjectId  objId;
    acdbGetObjectId(objId,ent);
    //直接判断
    //if(acdbIsInLongTransaction(objId))
    //判断并移除工作集
    if(isWorksetAndRemove(objId))
    {
      acutPrintf(_T("\n在长事务中"));
    }
    else
    {
      acutPrintf(_T("\n不在长事务中"));
    }

判断并移除对象函数,通过currentLongTransactionFor,可以实现获取长事务对象id,可以处理对象增加到工作集,移除等操作。

  //从工作集中移除
  static bool isWorksetAndRemove(AcDbObjectId objId){
    AcDbObjectId longtransId = acapLongTransactionManagerPtr()->currentLongTransactionFor(curDoc());
    if (AcDbObjectId::kNull != longtransId)
    {
      AcDbObjectPointer<AcDbLongTransaction> pLongTrans(longtransId,AcDb::kForRead);
      if(Acad::eOk != pLongTrans.openStatus()) return false;
      //判断是否在工作集
      if(pLongTrans->workSetHas(objId))
      {
        //升级打开
        pLongTrans->upgradeOpen();
        if(pLongTrans->isWriteEnabled())
        {
          //移除工作集
          pLongTrans->removeFromWorkSet(objId);
        }
        return true;
      }      
    }
    return false;
  }
posted @ 2024-08-01 21:57  edata  阅读(4)  评论(0编辑  收藏  举报