找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 131|回复: 0

修改颜色

[复制链接]

1

主题

0

回帖

37

积分

管理员

积分
37
发表于 2024-5-2 22:34:40 | 显示全部楼层 |阅读模式
  1. acDocManager->lockDocument(acDocManager->curDocument());
  2. ads采用name ss, en;
  3. if (acedSSGet(NULL, NULL, NULL, NULL, ss) != RTNORM)
  4. {
  5.     return;
  6. }
  7. int colorindex;
  8. acedSetColorDialog(colorindex, true, 1);
  9. long len;
  10. if (RTNORM == acedSSLength(ss, &len))
  11. {
  12.     for (int i = 0; i < len; i++)
  13.     {
  14.         acedSSName(ss, i, en);
  15.         AcDbObjectId id;
  16.         acdbGetObjectId(id, en);
  17.         AcDbEntity *pEnt;
  18.         acdbOpenObject(pEnt, id, AcDb::kForWrite);
  19.         AcCmColor colors;
  20.         colors.setColorIndex(colorindex);
  21.         if (pEnt->isKindOf(AcDbBlockReference::desc()))
  22.         {
  23.             AcDbBlockReference *pBlk = AcDbBlockReference::cast(pEnt);
  24.             ChangeColor(pBlk, colors);
  25.         }
  26.         pEnt->setColor(colors);
  27.         pEnt->close();
  28.     }
  29. }
  30. acedSSFree(ss);
  31. acDocManager->unlockDocument(acDocManager->curDocument());
  32. static void ChangeColor(AcDbBlockReference *pBlk, AcCmColor col)
  33. {
  34.     AcDbObjectId blkId = pBlk->blockTableRecord();
  35.     AcDbBlockTableRecord *pBlkRcd;
  36.     acdbOpenObject(pBlkRcd, blkId, AcDb::kForWrite);
  37.     AcDbBlockTableRecordIterator *pItr;
  38.     pBlkRcd->newIterator(pItr);
  39.     for (pItr->start(); !pItr->done(); pItr->step())
  40.     {
  41.         AcDbEntity *pEnt1;
  42.         pItr->getEntity(pEnt1, AcDb::kForWrite);
  43.         pEnt1->setColor(col);
  44.         if (pEnt1->isKindOf(AcDbBlockReference::desc()))
  45.         {
  46.             AcDbBlockReference *pBlk1 = AcDbBlockReference::cast(pEnt1);
  47.             ChangeColor(pBlk1, col);
  48.         }
  49.         pEnt1->close();
  50.     }
  51.     delete pItr;
  52.     pBlkRcd->close();
  53.     AcDbObjectIterator *attIt = pBlk->attributeIterator();
  54.     for (attIt->start(); !attIt->done(); attIt->step())
  55.     {
  56.         AcDbAttribute *pAtt = NULL;
  57.         AcDbObjectId attrObjId;
  58.         attrObjId = attIt->objectId();
  59.         Acad::ErrorStatus es = acdbOpenObject(pAtt, attrObjId, AcDb::kForWrite);
  60.         if (es == Acad::eOk)
  61.         {
  62.             pAtt->setColor(col);
  63.             pAtt->close();
  64.         }
  65.     }
  66.     delete attIt;
  67.     pBlk->setColorIndex(0);
  68. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|膜结构网

GMT+8, 2025-1-4 12:56 , Processed in 0.137838 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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