void getRegionAreaProp()
{
ads_name eNam;
ads_point pt;
AcDbObjectId eId;
if (acedEntSel(L"\nSelect an region: ", eNam, pt) != RTNORM)
{
acutPrintf(L"\nNothing selected.");
return;
}
acdbGetObjectId(eId, eNam);
AcDbEntity* pEnt = NULL;
if(acdbOpenAcDbEntity(pEnt, eId, AcDb::kForRead) != Acad::eOk)
{
acutPrintf(L"\nError open entity.");
return;
}
AcDbRegion* pReg = AcDbRegion::cast(pEnt);
if(!pReg)
{
pEnt->close();
return;
}
double perimeter, area, momInertia[2],
prodInertia, prinMoments[2],
radiiGyration[2];
AcGePoint2d centroid, extentsLow, extentsHigh;
AcGeVector2d prinAxes[2];
AcGePoint3d origin;
AcGeVector3d xAxis;
AcGeVector3d yAxis;
// initialize the three arguments
AcGePlane plane;
pReg->getPlane(plane);
plane.getCoordSystem(origin, xAxis, yAxis);
Acad::ErrorStatus es = pReg->getAreaProp(
// these (3) are the input parameters
origin, xAxis, yAxis,
perimeter,
area,
centroid,
momInertia,
prodInertia,
prinMoments,
prinAxes,
radiiGyration,
extentsLow,
extentsHigh);
assert(es == Acad::eOk);
// you can determine what to do exactly with the results
// here I just print a message
acutPrintf(L"\nSucceded in getting an region's area prop.");
pReg->close();
}
RegionProp
最新推荐文章于 2024-08-12 16:55:46 发布
该代码段展示了如何在AutoCAD中使用API获取一个区域对象的面积属性,包括周长、面积、质心、惯性矩等信息。首先选择一个区域,然后打开并转换为AcDbRegion对象,调用getAreaProp方法计算相关属性。
摘要由CSDN通过智能技术生成