|
- bool IsThisDynamicBlockByXData(AcDbBlockReference *pBlockReference) {
- AcDbObjectId idDynBTR; // We are looking for this: The named dynamic "root block".
- AcDbObjectId idBTR = pBlockReference->blockTableRecord();
- AcDbBlockTableRecord *pBTR;
- Acad::ErrorStatus es;
- es = acdbOpenObject(pBTR, idBTR, AcDb::kForRead);
- if (!es) {
- if (pBTR->isAnonymous()) {
- resbuf *rbx = pBTR->xData(L"AcDbBlockRepBTag");
- if (rbx) {
- //The resbuf list looks like this:
- //1001, "AcDbBlockRepBTag", kDxfRegAppName
- //1070, 1 kDxfXdInteger16
- //1005, <Handle of the dynamic root block>, kDxfXdHandle
- //walk to kDxfXdHandle
- for (resbuf *r = rbx; r; r = r->rbnext) {
- if (r->restype == AcDb::kDxfXdHandle) {
- AcDbDatabase *pDb = pBlockReference->database();
- AcDbHandle handle(r->resval.rstring);
- es = pDb->getAcDbObjectId(idDynBTR, false, handle);
- if (!es)
- break; // success!
- }
- }
- acutRelRb(rbx);
- }
- }
- else
- idDynBTR = idBTR; // If it isn't anonymous, it must be the dynamic block itself
- }
- bool bIsDynamic = false;
- if (!es && !idDynBTR.isNull()) {
- AcDbDynBlockTableRecord testDynBtr(idDynBTR);
- if (bIsDynamic = testDynBtr.isDynamicBlock()) {
- // verify that idBTR is an anonymous block from idDynBTR
- AcDbObjectIdArray anonymousIds;
- es = testDynBtr.getAnonymousBlockIds(anonymousIds);
- if (!anonymousIds.contains(idBTR)) {
- acutPrintf(L"\nVerificatio FAILED!");
- bIsDynamic = false;
- }
- }
- if (bIsDynamic) {
- es = acdbOpenObject(pBTR, idDynBTR, AcDb::kForRead);
- if (!es) {
- const ACHAR *pBlockName = nullptr;
- pBTR->getName(pBlockName);
- acutPrintf(L"\nDynamic BREF to block '%s'.", pBlockName);
- pBTR->close();
- }
- }
- }
- return bIsDynamic;
- }
复制代码 |
|