文本加减乘除
acDocManager->lockDocument(acDocManager->curDocument());TCHAR szKword;
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("%* %"), 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("%* %"), 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("%* %"), 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("%* %"), 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());
页:
[1]