设为首页收藏本站

中国膜结构网

 找回密码
 立即注册
膜结构车棚
膜结构车棚膜结构资质国产膜材 膜结构网中国膜结构协会
查看: 371|回复: 1

删除块定义以及删除块参照

[复制链接]
  • TA的每日心情
    开心
    2020-11-25 09:13
  • 签到天数: 1345 天

    连续签到: 13 天

    [LV.10]以坛为家III

    发表于 2020-6-11 17:55 | 显示全部楼层 |阅读模式
    void CTest5::deleteAcDbBlockReference(CString& strBlockName)
    {

    // 获得当前图形数据库的块表
    AcDbBlockTable *pBlkTbl;
    acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl, AcDb::kForWrite);

    // 创建新的块表记录
    AcDbBlockTableRecord *pBlkTblRcd = NULL;
    pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, kForRead);
    pBlkTbl->close();

    AcDbBlockTableRecordIterator *pIte = NULL;

    Acad::ErrorStatus es;
    es = pBlkTblRcd->newIterator(pIte);
    AcDbEntity *pEnt = NULL;
    for (pIte->start(); !pIte->done(); pIte->step())
    {
    pIte->getEntity(pEnt, AcDb::kForWrite);
    if (pEnt->isKindOf(AcDbBlockReference::desc()))
    {

    AcDbBlockReference *pdBlkRec = AcDbBlockReference::cast(pEnt);
    AcDbObjectId id = pdBlkRec->blockTableRecord();

    AcDbBlockTableRecord *acdbBTR = NULL;
    if (acdbOpenObject(acdbBTR, id, AcDb::kForRead) != eOk)
    {
    if (pdBlkRec)
    pdBlkRec->close();
    continue;
    }
    ACHAR* blockname;
    acdbBTR->getName(blockname);
    if (strBlockName.Compare(blockname) == 0)
    pEnt->erase();

    if (acdbBTR)
    acdbBTR->close();
    if (pdBlkRec)
    pdBlkRec->close();
    }

    if (pEnt)
    pEnt->close();
    }
    delete pIte;
    pBlkTblRcd->close();

    }

    void CTest5::deleteAcDbBlockTableRecord(CString& strBlockName)
    {
    //获取当前图形数据库
    AcDbBlockTable* pBlkTbl = NULL;
    acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl, AcDb::kForWrite);
    //查询块是否已存在
    if (!pBlkTbl->has(strBlockName))
    return;
    //获取块的插入点
    AcGePoint3d ptInsert(0, 0, 0);
    //获取块表记录
    AcDbObjectId blkDefId;
    pBlkTbl->getAt(strBlockName, blkDefId);
    pBlkTbl->close();
    AcDbBlockTableRecord *pDBlkRe = NULL;
    if (acdbOpenObject(pDBlkRe, blkDefId, AcDb::kForWrite) != eOk)
    return;
    ACHAR *name;
    pDBlkRe->getName(name);
    if (strBlockName.Compare(name) == 0)
    pDBlkRe->erase();
    if (pDBlkRe)
    pDBlkRe->close();
    }



    test:

    TCHAR str[255];
    acedGetString(0, _T("块定义名称:"), str);

    CString name = str;
    CTest5::deleteAcDbBlockReference(name);
    CTest5::deleteAcDbBlockTableRecord(name);
    http://www.mjgw.org/ 专业从事膜结构设计、制作加工、施工安装的膜结构咨询服务,能够为客户提供专业的膜结构整体解决方案。做中国最好的膜结构综合服务平台。欢迎大家联系QQ:463017170.
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2020-11-25 09:13
  • 签到天数: 1345 天

    连续签到: 13 天

    [LV.10]以坛为家III

     楼主| 发表于 2020-6-11 17:55 | 显示全部楼层
    删除块定义以及指定的块中块(结合上一章)

    void CTest5::deleteAcDbBlockReference(CString& strBlockName)
    {

    // 获得当前图形数据库的块表
    AcDbBlockTable *pBlkTbl;
    acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl, AcDb::kForWrite);

    // 创建新的块表记录
    AcDbBlockTableRecord *pBlkTblRcd = NULL;
    pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, kForRead);
    pBlkTbl->close();

    AcDbBlockTableRecordIterator *pIte = NULL;

    Acad::ErrorStatus es;
    es = pBlkTblRcd->newIterator(pIte);
    AcDbEntity *pEnt = NULL;
    for (pIte->start(); !pIte->done(); pIte->step())
    {
    pIte->getEntity(pEnt, AcDb::kForWrite);
    if (pEnt->isKindOf(AcDbBlockReference::desc()))
    {

    AcDbBlockReference *pdBlkRec = AcDbBlockReference::cast(pEnt);
    AcDbObjectId id = pdBlkRec->blockTableRecord();

    AcDbBlockTableRecord *acdbBTR = NULL;
    if (acdbOpenObject(acdbBTR, id, AcDb::kForRead) != eOk)
    {
    if (pdBlkRec)
    pdBlkRec->close();
    continue;
    }
    ACHAR* blockname;
    acdbBTR->getName(blockname);
    if (strBlockName.Compare(blockname) == 0)
    pEnt->erase();
    else
    {
    //cycleProcessing(pEnt, strBlockName);
    _cycleProcessing(pEnt, strBlockName);
    }
    if (acdbBTR)
    acdbBTR->close();
    if (pdBlkRec)
    pdBlkRec->close();
    }

    if (pEnt)
    pEnt->close();
    }
    delete pIte;
    pBlkTblRcd->close();

    }

    void CTest5::deleteAcDbBlockTableRecord(CString& strBlockName)
    {
    //获取当前图形数据库
    AcDbBlockTable* pBlkTbl = NULL;
    acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl, AcDb::kForWrite);
    //查询块是否已存在
    if (!pBlkTbl->has(strBlockName))
    return;
    //获取块的插入点
    AcGePoint3d ptInsert(0, 0, 0);
    //获取块表记录
    AcDbObjectId blkDefId;
    pBlkTbl->getAt(strBlockName, blkDefId);
    pBlkTbl->close();
    AcDbBlockTableRecord *pDBlkRe = NULL;
    if (acdbOpenObject(pDBlkRe, blkDefId, AcDb::kForWrite) != eOk)
    return;
    ACHAR *name;
    pDBlkRe->getName(name);
    if (strBlockName.Compare(name) == 0)
    pDBlkRe->erase();
    if (pDBlkRe)
    pDBlkRe->close();
    }

    void CTest5::cycleProcessing(AcDbEntity *pEnt, CString& deletBlockName)
    {
    AcDbVoidPtrArray pExps;
    AcDbEntity *pExpEnt = NULL;

    if (pEnt->explode(pExps) == Acad::eOk)
    {
    for (int i = 0; i < pExps.length(); i++)
    {
    pExpEnt = (AcDbEntity*)pExps[i];
    if (pExpEnt->isKindOf(AcDbBlockReference::desc()))
    {
    AcDbBlockReference *pdBlkRec = AcDbBlockReference::cast(pExpEnt);
    AcDbObjectId id = pdBlkRec->blockTableRecord();

    AcDbBlockTableRecord *acdbBTR = NULL;
    if (acdbOpenObject(acdbBTR, id, AcDb::kForRead) != eOk)
    {
    if (pdBlkRec)
    pdBlkRec->close();
    continue;
    }
    ACHAR* blockname;
    acdbBTR->getName(blockname);

    if (deletBlockName.Compare(blockname) == 0)
    {
    pExpEnt->erase();
    }
    else
    {
    cycleProcessing(pExpEnt, deletBlockName);

    }

    if (acdbBTR)
    acdbBTR->close();
    if (pdBlkRec)
    pdBlkRec->close();
    }

    if(pExpEnt)
    pExpEnt->close();
    }
    }
    }

    void CTest5::_cycleProcessing(AcDbEntity *pEnt, CString& deletBlockName)
    {
    if (pEnt->isKindOf(AcDbBlockReference::desc()))
    {
    AcDbBlockReference *pBlkRef = AcDbBlockReference::cast(pEnt);
    AcGeMatrix3d mat = pBlkRef->blockTransform();

    AcDbBlockTableRecordPointer BlkTBRec_Ptr(pBlkRef->blockTableRecord(), AcDb::kForRead);
    if (Acad::eOk == BlkTBRec_Ptr.openStatus())
    {
    AcDbBlockTableRecordIterator *pIt = NULL;
    BlkTBRec_Ptr->newIterator(pIt);
    for (pIt->start(); !pIt->done(); pIt->step())
    {
    AcDbEntity *pEntItem = NULL;
    pIt->getEntity(pEntItem, AcDb::kForWrite);
    if (pEntItem->isKindOf(AcDbBlockReference::desc()))
    {
    AcDbBlockReference *pdBlkRecf = AcDbBlockReference::cast(pEntItem);
    AcDbObjectId id = pdBlkRecf->blockTableRecord();

    AcDbBlockTableRecord *acdbBTR = NULL;
    if (acdbOpenObject(acdbBTR, id, AcDb::kForRead) != eOk)
    {
    if (pdBlkRecf)
    pdBlkRecf->close();
    if (pEntItem)
    pEntItem->close();
    continue;
    }
    ACHAR* blockname;
    acdbBTR->getName(blockname);

    if (deletBlockName.Compare(blockname) == 0)
    {
    pEntItem->erase();
    }
    else
    {
    _cycleProcessing(pEntItem, deletBlockName);
    }

    if (acdbBTR)
    acdbBTR->close();
    if (pdBlkRecf)
    pdBlkRecf->close();
    }

    if (pEntItem)
    pEntItem->close();
    }
    delete pIt;
    }
    }

    if (pEnt)
    pEnt->close();
    }

    void CTest5::Start()
    {
    /*AcDbObjectIdArray entIds;
    if (!CTest5:romptSelectEnts(_T("请选择实体"), AcDbEntity::desc(), entIds))
    return;

    if (entIds.length() <= 0)
    return;*/

    TCHAR str[255];
    acedGetString(0, _T("块定义名称:"), str);

    CString name = str;
    CTest5::deleteAcDbBlockReference(name);
    CTest5::deleteAcDbBlockTableRecord(name);
    }
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    关闭

    推荐膜材品牌上一条 /5 下一条

    进口膜材 国产膜材 pvdf膜材ptfe膜材ETFE膜材
    最好的膜结构公司 一级膜结构资质 膜结构一级资质
    膜结构设计-膜结构十大品牌-etfe设计-充气膜结构
    诺科膜结构
    遨都膜结构设计
    中国膜结构网
    中国空间膜结构协会

    QQ|申请友链|Archiver|手机版|中国膜结构论坛

    GMT+8, 2020-11-26 00:13 , Processed in 0.299441 second(s), 26 queries .

    Powered by 中国膜结构网->膜材采购->膜结构设计->膜结构安装->膜结构维修

    © 2014-2020 膜结构协会->进口膜材->国产膜材->PVDF膜材->PTFE膜材->ETFE膜材.

    快速回复 返回顶部 返回列表