|
acDocManager->lockDocument(acDocManager->curDocument());
TCHAR szKword[132];
acedInitGet(NULL, _T("A B C D"));
int nReturn = acedGetKword(_T("\n输入选项[加(A)/减(B)/乘(C)/除(D)]:"), szKword);
if (nReturn == RTNORM || nReturn == RTKWORD)
{
std::vector<AcRxClass*> descs;
descs.push_back(AcDbText::desc());
descs.push_back(AcDbMText::desc());
AcDbEntity *pEnt = NULL;
AcGePoint3d pickPoint;
if (CSelectUtil::PromptSelectEntity(_T("\n请点选首个文本数字作为开头:"), descs, pEnt, pickPoint))
{
CString strName;
if (pEnt->isKindOf(AcDbText::desc()))
{
AcDbText *pText = AcDbText::cast(pEnt);
strName = pText->textString();
// 截取字符串中的纯数字
sscanf(strName, _T("%*[A-Z,:] %[0-9,.]"), strName);
}
else
{
AcDbMText *pMText = AcDbMText::cast(pEnt);
TCHAR *chaName;
chaName = pMText->contents();
CString strName(chaName);
int n = strName.ReverseFind(';');
strName = strName.Right(strName.GetLength() - n - 1);
sscanf(strName, _T("%*[A-Z,:] %[0-9,.]"), strName);
acutDelString(chaName);
}
double firstNum = CConvertUtil::ToDouble(strName);
AcDbObjectIdArray entIds;
if (CSelectUtil::PromptSelectEnts(_T("\n选择其它文本数字<可单选或多选>:"), descs, entIds))
{
for (int i = 0; i < entIds.length(); i++)
{
AcDbEntity *pNEnt = NULL;
if (acdbOpenObject(pNEnt, entIds<i>, AcDb::kForRead) == Acad::eOk)
{
if (pNEnt->isKindOf(AcDbText::desc()))
{
AcDbText *pText = AcDbText::cast(pNEnt);
strName = pText->textString();
sscanf(strName, _T("%*[A-Z,:] %[0-9,.]"), strName);
}
else
{
AcDbMText *pMText = AcDbMText::cast(pNEnt);
TCHAR *chaName;
chaName = pMText->contents();
CString strName(chaName);
int n = strName.ReverseFind(';');
strName = strName.Right(strName.GetLength() - n - 1);
sscanf(strName, _T("%*[A-Z,:] %[0-9,.]"), strName);
acutDelString(chaName);
}
}
double secondNum = CConvertUtil::ToDouble(strName);
if (_tcscmp(szKword, _T("A")) == 0)
{
firstNum = firstNum + secondNum;
}
else if (_tcscmp(szKword, _T("B")) == 0)
{
firstNum = firstNum - secondNum;
}
else if (_tcscmp(szKword, _T("C")) == 0)
{
firstNum = firstNum * secondNum;
}
else
{
firstNum = firstNum / secondNum;
}
pNEnt->close();
}
CString firstStr = CConvertUtil::ToString(firstNum, 3);
ads_point adsPoint;
if (acedGetPoint(NULL, _T("拾取标注点:"), adsPoint) == RTNORM)
{
AcGePoint3d pt = asPnt3d(adsPoint);
AcDbText *pText = new AcDbText(pt, firstStr, AcDbObjectId::kNull, 10, 0);
pText->setColorIndex(1);
CDwgDatabaseUtil::PostToModelSpace(pText);
}
pEnt->close();
}
}
}
acDocManager->unlockDocument(acDocManager->curDocument()); |
|