|
acDocManager->lockDocument(acDocManager->curDocument());
ads_name ss, en;
if (acedSSGet(NULL, NULL, NULL, NULL, ss) != RTNORM)
{
return;
}
int colorindex;
acedSetColorDialog(colorindex, true, 1);
long len;
if (RTNORM == acedSSLength(ss, &len))
{
for (int i = 0; i < len; i++)
{
acedSSName(ss, i, en);
AcDbObjectId id;
acdbGetObjectId(id, en);
AcDbEntity *pEnt;
acdbOpenObject(pEnt, id, AcDb::kForWrite);
AcCmColor colors;
colors.setColorIndex(colorindex);
if (pEnt->isKindOf(AcDbBlockReference::desc()))
{
AcDbBlockReference *pBlk = AcDbBlockReference::cast(pEnt);
ChangeColor(pBlk, colors);
}
pEnt->setColor(colors);
pEnt->close();
}
}
acedSSFree(ss);
acDocManager->unlockDocument(acDocManager->curDocument());
static void ChangeColor(AcDbBlockReference *pBlk, AcCmColor col)
{
AcDbObjectId blkId = pBlk->blockTableRecord();
AcDbBlockTableRecord *pBlkRcd;
acdbOpenObject(pBlkRcd, blkId, AcDb::kForWrite);
AcDbBlockTableRecordIterator *pItr;
pBlkRcd->newIterator(pItr);
for (pItr->start(); !pItr->done(); pItr->step())
{
AcDbEntity *pEnt1;
pItr->getEntity(pEnt1, AcDb::kForWrite);
pEnt1->setColor(col);
if (pEnt1->isKindOf(AcDbBlockReference::desc()))
{
AcDbBlockReference *pBlk1 = AcDbBlockReference::cast(pEnt1);
ChangeColor(pBlk1, col);
}
pEnt1->close();
}
delete pItr;
pBlkRcd->close();
AcDbObjectIterator *attIt = pBlk->attributeIterator();
for (attIt->start(); !attIt->done(); attIt->step())
{
AcDbAttribute *pAtt = NULL;
AcDbObjectId attrObjId;
attrObjId = attIt->objectId();
Acad::ErrorStatus es = acdbOpenObject(pAtt, attrObjId, AcDb::kForWrite);
if (es == Acad::eOk)
{
pAtt->setColor(col);
pAtt->close();
}
}
delete attIt;
pBlk->setColorIndex(0);
} |
|