- 积分
- 6501
- 明经币
- 个
- 注册时间
- 2013-1-30
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 张和平 于 2014-12-22 12:26 编辑
以下是自己写的一个文字样式替换函数,个人感觉存在以下几个问题:
1、有时候会不彻底,
2、有时候会埋下崩溃的隐患
3、有待精简
4、有待提高效率
希望各位前辈指教点评,希望说得越详细越好,我可以好好学学!
谢谢!- void CTextUtil::SetStyle(AcDbObjectId entId, AcDbObjectId styleId, std::vector<AcDbObjectId> escStyleIds)
- {
- AcDbText *pText = NULL; //单行文字
- AcDbMText *pMText = NULL; //多行文字
- AcDbDimension *pDim = NULL; //标注
- AcDbAttributeDefinition *pAtt = NULL; //属性
- AcDbBlockReference *pBlkRef = NULL; //块参照
- if (Acad::eOk == acdbOpenObject(pText, entId, AcDb::kForWrite))
- {
- if (escStyleIds.size() > 0)
- {
- for (int i = 0; i < escStyleIds.size(); i++)
- {
- if (pText->textStyle() == escStyleIds[i])
- {
- //acutPrintf(TEXT("\n*** 这个块外单行文字的文字样式在免替换列表中"));
- pText->close();
- return;
- }
- }
- }
- pText->setTextStyle(styleId);
- pText->close();
- //acutPrintf(TEXT("\n*** 块外单行文字OK"));
- }
- else if (Acad::eOk == acdbOpenObject(pMText, entId, AcDb::kForWrite))
- {
- if (escStyleIds.size() > 0)
- {
- for (int i = 0; i < escStyleIds.size(); i++)
- {
- if (pMText->textStyle() == escStyleIds[i])
- {
- //acutPrintf(TEXT("\n*** 这个块外多行文字的文字样式在免替换列表中"));
- pMText->close();
- return;
- }
- }
- }
- pMText->setTextStyle(styleId);
- pMText->close();
- //acutPrintf(TEXT("\n*** 块外多行文字OK"));
- }
- else if (Acad::eOk == acdbOpenObject(pDim, entId, AcDb::kForWrite))
- {
- if (escStyleIds.size() > 0)
- {
- for (int i = 0; i < escStyleIds.size(); i++)
- {
- if (pDim->dimtxsty() == escStyleIds[i])
- {
- //acutPrintf(TEXT("\n*** 这个块外标注的文字样式在免替换列表中"));
- pDim->close();
- return;
- }
- }
- }
- pDim->setDimtxsty(styleId);
- pDim->close();
- //acutPrintf(TEXT("\n*** 块外标注OK"));
- }
- else if (Acad::eOk == acdbOpenObject(pAtt, entId, AcDb::kForWrite))
- {
- if (escStyleIds.size() > 0)
- {
- for (int i = 0; i < escStyleIds.size(); i++)
- {
- if (pAtt->textStyle() == escStyleIds[i])
- {
- //acutPrintf(TEXT("\n*** 这个块外属性的文字样式在免替换列表中"));
- pAtt->close();
- return;
- }
- }
- }
- pAtt->setTextStyle(styleId);
- pAtt->close();
- //acutPrintf(TEXT("\n*** 块外属性OK"));
- }
- else if (Acad::eOk == acdbOpenObject(pBlkRef, entId, AcDb::kForRead))
- {
- //acutPrintf(TEXT("\n*** 找到一个块参照"));
- AcDbBlockTableRecord *pBlkTblRcd = NULL;
- if (Acad::eOk == acdbOpenObject(pBlkTblRcd, pBlkRef->blockTableRecord(), AcDb::kForRead))
- {
- if (pBlkTblRcd->hasAttributeDefinitions())
- {
- AcDbObjectIterator *pAttIt = NULL;
- pAttIt = pBlkRef->attributeIterator();
- for (pAttIt->start(); !pAttIt->done(); pAttIt->step())
- {
- AcDbAttribute *pAtt = NULL;
- if (pBlkRef->openAttribute(pAtt, pAttIt->objectId(), AcDb::kForWrite))
- {
- pAtt->setTextStyle(styleId);
- pAtt->close();
- }
- }
- }
- AcDbBlockTableRecordIterator *pIt = NULL;
- pBlkTblRcd->newIterator(pIt);
- for (pIt->start(); !pIt->done(); pIt->step())
- {
- AcDbObjectId subEntId = NULL;
- if (Acad::eOk == pIt->getEntityId(subEntId))
- {
- CTextUtil::SetStyle(subEntId, styleId, escStyleIds);
- }
- }
- pBlkTblRcd->close();
- }
- pBlkRef->close();
- }
- return;
- }
|
|