TA的每日心情![](source/plugin/dsu_paulsign/img/emot/kx.gif) | 开心 2024-8-31 15:58 |
---|
签到天数: 89 天 [LV.6]常住居民II
管理员
- 积分
- 3366
|
- int drawPolyline()
- {
- Acad::ErrorStatus es = Acad::eOk;
- AcGePoint3dArray vertexArray;
- int iErrSta = 0, i = 0;
- while (1)
- {
- //由于是多边形,即最终要封闭,所以就不需要提示用户来封闭它,如果
- //多边形变成了多义线,只需要这个判断,即加入acedInitGet,即关键字进行判断
- AcGePoint3d tempPt = AcGePoint3d::kOrigin;
- if ( 0 == i)
- iErrSta = acedGetPoint(NULL, _T("/n指定下一点:"), asDblArray(tempPt));
- else
- iErrSta = acedGetPoint(asDblArray(vertexArray.at(i-1)),_T("/n指定下一点:"), asDblArray(tempPt));
- if (RTNORM == iErrSta)
- vertexArray.append(tempPt);
- else
- break;
- if (i>0)
- {
- //模拟橡皮筋效果,如果生成数组直线或者圆弧,加入到模型,最后删除效果更好
- acedGrDraw(asDblArray(vertexArray.at(i-1)),asDblArray(tempPt),256,0);
- }
- i ++;
- }
- if (vertexArray.length() < 2)
- return 1;
- //加入到模型空间中
- AcDbBlockTable* pTable = NULL;
- if (Acad::eOk != acdbHostApplicationServices() ->workingDatabase()->getBlockTable(pTable, AcDb::kForRead))
- return 2;
- AcDbBlockTableRecord* pBlockTableReocrd;
- if (Acad::eOk != pTable ->getAt(ACDB_MODEL_SPACE, pBlockTableReocrd, AcDb::kForWrite))
- {
- pTable ->close();
- return 3;
- }
- pTable ->close();
- AcDbPolyline* pPolyline = new AcDbPolyline(vertexArray.length());
- for (int i = 0; i < vertexArray.length(); i ++)
- {
- pPolyline ->addVertexAt(i, vertexArray[i].convert2d(AcGePlane::kXYPlane));
- }
- pPolyline ->setClosed(Adesk::kTrue);
- AcDbObjectId polylineId;
- pBlockTableReocrd ->appendAcDbEntity(polylineId, pPolyline);
- //获取多边形的面积
- double dArea = 0.0;
- pPolyline ->getArea(dArea);
- pPolyline ->close();
- pBlockTableReocrd ->close();
- acutPrintf("/n多边形的面积为:%lf",dArea);
- return 0;
- }
复制代码 |
|