- UID
- 1
- 积分
- 16111
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-3
- 最后登录
- 1970-1-1
|
发表于 2002-5-23 07:23:19
|
显示全部楼层
下面是ObjectArx获得AcDb2dPolyline和AcDbPolyline型心的代码:
- [FONT=courier new]
- void getPolycentroid()
- {
-
- ads_name eName;
- ads_point pt;
-
- if (RTNORM != acedEntSel("\n选择一个封闭的polyline:",eName,pt))
- {
- acutPrintf("\nFailed to select entity");
- return;
- }
-
-
-
- AcDbObjectId objId = NULL;
- Acad::ErrorStatus es;
-
- es = acdbGetObjectId (objId , eName);
- if (Acad::eOk != es)
- {
- acutPrintf("\nFailed to get object Id");
- return;
- }
- //如果实体不是REGION,那么转换成REGION
-
- AcDbVoidPtrArray curves;
- AcDbVoidPtrArray regions;
- AcDbEntity *pEnt = NULL;
-
- es =acdbOpenAcDbEntity(pEnt,objId,AcDb::kForRead,Adesk::kFalse);
- if(Acad::eOk != es)
- {
- acutPrintf("\nFailed to open entity for write");
- return;
- }
-
- //测试实体是AcDbPolyline还是AcDb2dPolyline)
-
- if (! pEnt->isKindOf(AcDb2dPolyline::desc()) &&
- !pEnt->isKindOf(AcDbPolyline::desc()))
- {
-
- acutPrintf("\nEntity selected is not a polyline");
- pEnt->close();
- return;
- }
-
- if ( pEnt->isKindOf(AcDb2dPolyline::desc()) &&
- !((AcDb2dPolyline*)pEnt)->isClosed())
- {
-
- acutPrintf("\nPolyline is not closed");
- pEnt->close();
- return;
- }
-
- if ( pEnt->isKindOf(AcDbPolyline::desc()) &&
- !((AcDbPolyline*)pEnt)->isClosed())
- {
-
- acutPrintf("\nPolyline is not closed");
- pEnt->close();
- return;
- }
- curves.append(pEnt);
- pEnt->close();
-
- AcDbRegion* pReg;
- es=AcDbRegion::createFromCurves(curves,regions);
-
- pReg = AcDbRegion::cast((AcRxObject*)regions[0]);
-
- AcGePoint3d origin;
- AcGeVector3d xAxis;
- AcGeVector3d yAxis;
-
- AcGePlane plane;
- pReg->getPlane(plane);
- plane.getCoordSystem(origin, xAxis, yAxis);
-
- double perimeter;
- double area;
- AcGePoint2d centroid;
- double momInertia[2];
- double prodInertia;
- double prinMoments[2];
- AcGeVector2d prinAxes[2];
- double radiiGyration[2];
- AcGePoint2d extentsLow;
- AcGePoint2d extentsHigh;
- pReg->getAreaProp(origin,
- xAxis,
- yAxis,
- perimeter,
- area,
- centroid,
- momInertia,
- prodInertia,
- prinMoments,
- prinAxes,
- radiiGyration,
- extentsLow,
- extentsHigh) ;
-
- AcGeVector3d normal;
- pReg->getNormal(normal);
- pReg->close();
- AcGeMatrix3d mat;
-
- mat.setCoordSystem(origin,xAxis,yAxis,normal);
-
- //put point at centriod
- AcGePoint3d cpt(centroid[0],centroid[1],0.0);
-
- cpt.transformBy(mat);
- resbuf pdm,pds;
- pdm.restype = RTSHORT;
- pdm.resval.rint = 34;
- acedSetVar("PDMODE",&pdm);
- pds.restype = RTSHORT;
- pds.resval.rint = -5;
- acedSetVar("PDSIZE",&pds);
- acedCommand(RTSTR,"POINT",RT3DPOINT,asDblArray(cpt),0);
- acutPrintf("Centroid=%f,%f",cpt[0],cpt[1]);
-
- }
- [/FONT]
复制代码 |
|