| float Draw2dPLArea(){
 AcGePoint2dArray points;
 AcGePoint3d myptCurrent;
 ads_point pt,ptStart;
 AcGePoint3d pthigh;
 int i=0;
 double area=0;
 ads_point ptPrevious, ptCurrent; // 前一个参考点,当前拾取的点
 int index = 2; // 当前输入点的次数
 AcDbObjectId polyId; // 多段线的ID
 int ptnum=0;
 
 int rc; // 返回值
 ACHAR kword[20]; // 关键字
 acedInitGet(RSG_NONULL,_T("C"));
  //提示用户选择想要勾画的工程面积点if (acedGetPoint(NULL, _T("\n输入第一点:"),ptStart) != RTNORM)
 return 0;
 acdbPointSet(ptStart, ptPrevious);
 
 while (acedGetPoint(ptPrevious,_T("\n输入下一点:"), ptCurrent) ==RTNORM)
 {
   if (index==2){
 
 // 创建多段线
 AcGePoint2d ptGe1, ptGe2; // 两个节点
 ptGe1[X] = ptPrevious[X];
 ptGe1[Y] = ptPrevious[Y];
 ptGe2[X] = ptCurrent[X];
 ptGe2[Y] = ptCurrent[Y];
    points.insertAt(0,ptGe1);points.insertAt(1,ptGe2);
    /*pPoly->addVertexAt(0, ptGe1);pPoly->addVertexAt(1, ptGe2);*/
 
 
 }
 else if (index>2)
 {
 // 修改多段线,添加最后一个顶点
 
 AcGePoint2d ptGe; // 增加的节点
 ptGe[X] = ptCurrent[X];
 ptGe[Y] = ptCurrent[Y];
 /*pPoly->addVertexAt(index - 1, ptGe);*/
 points.insertAt(index-1,ptGe);
   }index++;
   acdbPointSet(ptCurrent, ptPrevious);  }
 //add points into AcDbLine
 int vexnum=points.length();
 AcDbPolyline *pPoly=new AcDbPolyline(vexnum);
 for(i=0;i<vexnum;i++)
 {
 pPoly->addVertexAt(i,points.at(i));
 }
 
  pPoly->getArea(area);  pPoly->close();  return area;}
 高手帮看看行么?总觉得有些地方不妥。小妹谢谢了! |