|
void CreateRectangle()//创建矩形命令
{
ads_point startpoint;
int nReturn;
acedInitGet(NULL, _T("R"));
nReturn = acedGetPoint(NULL, _RXST("指定起点:"), startpoint);
if (nReturn == RTNORM)
{
ads_point endpoint;
nReturn = acedGetPoint(startpoint, _RXST("\n指定对角点:"), endpoint);
//根据对角点找出四个角的顶点
ads_real x1 = startpoint[X];
ads_real x2 = endpoint[X];
ads_real y1 = startpoint[Y];
ads_real y2 = endpoint[Y];
AcGePoint2d ptLeftBottom(min(x1, x2), min(y1, y2));
AcGePoint2d ptRightBottom(max(x1, x2), min(y1, y2));
AcGePoint2d ptRightTop(max(x1, x2), max(y1, y2));
AcGePoint2d ptLeftTop(min(x1, x2), max(y1, y2));
AcGePoint2dArray points;
points.append(ptLeftBottom);
points.append(ptRightBottom);
points.append(ptRightTop);
points.append(ptLeftTop);
int numVerts = points.length();
AcDbPolyline *pPline = new AcDbPolyline(numVerts);
for (int i = 0; i < points.length(); i++)
{
pPline->addVertexAt(i, points.at(i));
}
pPline->setClosed(true);
HysuEditor::PostToModelSpace(pPline);
acutPrintf(_RXST("\n创建矩形完成."));
}
else
{
acutPrintf(_RXST("\n获取点失败."));
acutPrintf(_RXST("\n创建矩形失败."));
}
} |
|