1 //改色 2 void cmdChangeColorX(bool bRand=true, CAXA::UInt16 color_Index = 10) 3 { 4 CDraft::ErrorStatus es; 5 CRxDbObjectId objID; 6 CRxDbEntity* pEntity=NULL; 7 crx_name en; 8 crx_point pt; 9 //拾取要改色的图元 10 while (crxedEntSel(_T("\n请选择要改色的图元:"), en, pt) == RTNORM) 11 { 12 if (bRand) color_Index = getRandColorIndex(); 13 es = crxdbGetObjectId(objID, en); 14 if (es != CDraft::eOk) return; 15 16 //objID转pEnt 17 es = crxdbOpenCRxDbEntity(pEntity, objID, CRxDb::kForWrite); 18 if (es != CDraft::eOk || pEntity == NULL) return; 19 20 if (pEntity->isKindOf(CRxDbBlockReference::desc())) //是块 21 { 22 CRxDbBlockTableRecord* pRecord; 23 CRxDbBlockTableRecordIterator* iter; 24 CRxDbObjectId id; 25 //pEnt转pBlkref 26 CRxDbBlockReference* pBlkRef = CRxDbBlockReference::cast(pEntity); 27 28 //pBlkref转blkTRid 29 CRxDbObjectId blockTableRecordId = pBlkRef->blockTableRecord(); 30 31 //blkTRid转到pRecord 32 es = crxdbOpenObject(pRecord, blockTableRecordId, CRxDb::kForWrite); 33 if (es != CDraft::eOk || pRecord == NULL) return; 34 35 //遍历要目标块中每一图元 36 pRecord->newIterator(iter); 37 for (iter->start(); !iter->done(); iter->step()) 38 { 39 es = iter->getEntityId(id); 40 if (es != CDraft::eOk || !id.isValid()) continue; 41 es = crxdbOpenCRxDbEntity(pEntity, id, CRxDb::kForWrite); 42 if (es != CDraft::eOk) continue; 43 //改块中实体颜色 44 pEntity->setColorIndex(color_Index); 45 } 46 delete iter; 47 pRecord->close(); 48 } 49 else //普通图元 50 { 51 pEntity->setColorIndex(color_Index); 52 } 53 crxedCommand(RTSTR, _T("rea"), RTNONE); //刷新,使更改立即生效。 54 } 55 pEntity->close(); 56 }
标签:pRecord,CDraft,VS2019,eOk,CAXA2023,iter,ObjectArx,es,pEntity From: https://www.cnblogs.com/birdflying/p/18104828