|
[code]https://blog.csdn.net/mary288267/article/details/128804910?spm=1001.2014.3001.5502[/code]//删掉多行文本中表征颜色的格式代码
void RemoveMTextColorField(AcDbMText* pMText)
{
if (!pMText)
return;
TCHAR* psz = pMText->contents();
CString sMText = psz;
delete psz;
if (sMText.GetLength() < 5)
return;
for (int iBegin = 0; iBegin < sMText.GetLength() - 1; iBegin++)
{
//CAD多行文字每个文字都可以拥有格式代码,需要删掉表征颜色的格式代码
if (_T('\\') == sMText[iBegin])
{
if (_T('c') == tolower(sMText[iBegin + 1])) //这是表征颜色的格式代码
{
int iEnd;
for (iEnd = iBegin + 2; iEnd < sMText.GetLength(); iEnd++)
if (_T(';') == sMText[iEnd])
break;
if (iEnd < sMText.GetLength())
{
sMText.Delete(iBegin, iEnd + 1 - iBegin);
iBegin--;
}
else
break;
}
else //排除多行文字字符'\'或者其他以\开头的格式代码
iBegin++;
}
}
pMText->setContents(sMText);
}
void CmdChangeMTextColor(void)
{
Acad::ErrorStatus es;
ads_name ename;
ads_point pt;
if (acedEntSel(_T("\nSelect a MText: "), ename, pt) != RTNORM) return;
AcDbObjectId id = AcDbObjectId::kNull;
acdbGetObjectId(id, ename);
if (id == AcDbObjectId::kNull) return;
AcDbObjectPointer<AcDbMText> pObj(id, AcDb::kForWrite);
if ((es = pObj.openStatus()) != Acad::eOk)
{
if (es == Acad::eNotThatKindOfClass)
{
acutPrintf(_T("\nSelect a MText."));
}
else {
acutPrintf(_T("\nError when opening the entity."));
}
return;
}
int iInput;
if (RTNORM == acedGetInt(_T("\n请输入颜色索引号:"), &iInput))
{
AcDbMText *pMText = AcDbMText::cast(pObj.object());
RemoveMTextColorField(pMText);
pMText->setColorIndex(iInput);
}
} |
|