|
[code]获取块中文字
CString Dialog::GetTextForBlock(AcDbBlockReference *pRef, AcGePoint3d pickPoint)
{
AcDbEntity *pEnt;
CString str=_T("");
AcDbVoidPtrArray ptarr = NULL;
Acad::ErrorStatus es=pRef->explode(ptarr);
int iLen = ptarr.length();
for (int i = 0; i < iLen;i++)
{
pEnt = static_cast<AcDbEntity*>(ptarr[i]);
AcDbExtents ext;
pEnt->getGeomExtents(ext);
auto minPt = AcadUtils::ConvertTo2D(ext.minPoint());
auto maxPt = AcadUtils::ConvertTo2D(ext.maxPoint());
AcGePoint2dArray pts;
pts.append(minPt);
pts.append(AcGePoint2d(minPt.x, maxPt.y));
pts.append(maxPt);
pts.append(AcGePoint2d(maxPt.x, minPt.y));
if (XFuntion().PtInRegionInXYPlate(pickPoint, pts) && XFuntion().PtInRegionInXYPlate(pickPoint, pts))//命中了包围框
{
if (pEnt->isKindOf(AcDbText::desc()))
{
AcDbText *pText = NULL;
pText = AcDbText::cast(pEnt);
str = pText->textString();
pText->close();
return str;
}
if (pEnt->isKindOf(AcDbMText::desc()))
{
AcDbMText *pmText = NULL;
pmText = AcDbMText::cast(pEnt);
str = pmText->contents();
pmText->close();
return str;
}
if (pEnt->isKindOf(AcDbBlockReference::desc()))
{
AcDbBlockReference *pRef = AcDbBlockReference::cast(pEnt);
str=GetTextForBlock(pRef, pickPoint);
pRef->close();
}
}
pEnt->close();
}
return str;
}[/code] |
|