//0,不显示属性,1,显示属性,2,显示属性默认值 void CZhfPalette::FilterDb(AcDbDatabase* pDb, int iFilterMode) { if (iFilterMode==1) { return ; } Acad::ErrorStatus es ; AcDbBlockTable* pBT = NULL ; pDb->getBlockTable(pBT, AcDb::kForRead); AcDbBlockTableRecord* pBTR = NULL; es = pBT->getAt(ACDB_MODEL_SPACE, pBTR, AcDb::kForWrite); pBT->close(); AcDbBlockTableRecordIterator* pIT; es = pBTR->newIterator(pIT) ; for (; !pIT->done(); pIT->step()) { AcDbEntity* pEnt = NULL ; if (Acad::eOk==pIT->getEntity(pEnt, AcDb::kForWrite)) { if (pEnt->isKindOf(AcDbAttributeDefinition::desc())) { AcDbAttributeDefinition *pAttDef = AcDbAttributeDefinition::cast(pEnt); if (iFilterMode==0) { pEnt->erase() ; } else if (iFilterMode>1) { if (pAttDef != NULL && !pAttDef->isConstant()) { // We have a non-constant attribute definition, // so build an attribute entity. CString strShowVal ; if (iFilterMode==2) { strShowVal = pAttDef->textString() ; } else if (iFilterMode==3) { strShowVal = pAttDef->prompt() ; //显示中文为乱码 } pAttDef->setTag(strShowVal) ; } } } pEnt->close() ; } } delete pIT; pBTR->close(); }
Acad::ErrorStatus ArxDbgUtils::defineNewBlock(LPCTSTR blkName, AcDbBlockTableRecord*& newBlkRec, AcDbObjectId& newBlkRecId, AcDbDatabase* db) { ASSERT(db != NULL); AcDbBlockTable* blkTbl; Acad::ErrorStatus es = db->getSymbolTable(blkTbl, AcDb::kForWrite); if (es != Acad::eOk) return es; // if this block already exists, erase its contents first if (blkTbl->getAt(blkName, newBlkRec, AcDb::kForWrite) == Acad::eOk) { newBlkRecId = newBlkRec->objectId(); AcDbBlockTableRecordIterator* iter; es = newBlkRec->newIterator(iter); if (es != Acad::eOk) { ArxDbgUtils::rxErrorMsg(es); newBlkRec->close(); } else { AcDbEntity* ent; for (; !iter->done(); iter->step()) { if (iter->getEntity(ent, AcDb::kForWrite) == Acad::eOk) { ent->erase(); ent->close(); } } delete iter; } } else { // create a new block table record and add it to the block table newBlkRec = new AcDbBlockTableRecord; newBlkRec->setPathName(AcadString::nullStr); // constructor doesn't do it properly es = newBlkRec->setName(blkName); if (es == Acad::eOk) es = blkTbl->add(newBlkRecId, newBlkRec); if (es != Acad::eOk) { ArxDbgUtils::rxErrorMsg(es); delete newBlkRec; } } blkTbl->close(); // doesn't need to be open anymore return es; }