- UID
- 15750
- 积分
- 69
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-11-17
- 最后登录
- 1970-1-1
|
发表于 2006-4-28 12:45:40
|
显示全部楼层
Spline (AcDbSpline) entities in AutoCAD are NURBS curves. You need to extract
the NURBS data from a given spline entity in order build a Ge model of it as
shown in the following example. This example builds a AcGeNurbeCurve2d of a
spline entity, with little modifications to this, you could also build a
AcGeNurbCurve3d .
<code_begin>ads_name ent;ads_point pt;if (acedEntSel("Select an entity: ", ent, pt) != RTNORM){ acedAlert("Error selecting entity!"); return;}AcDbEntity *pEnt;AcDbObjectId objId;if (acdbGetObjectId(objId, ent) != Acad::eOk){ acedAlert("Error getting the ObjectId!"); return;}if (acdbOpenAcDbEntity(pEnt, objId, AcDb::kForRead) != Acad::eOk){ acedAlert("Error opening the entity for Read!"); delete pEnt; return;}int deg;Adesk::Boolean rational;Adesk::Boolean closed;Adesk::Boolean periodic;AcGePoint3dArray cPoints;AcGeDoubleArray knots;AcGeDoubleArray weights;double controlPtTol;double knotTol;AcGePoint3d c3Pt;AcGePoint2d c2Pt;AcDbSpline *pSpline=AcDbSpline::cast(pEnt);if (pSpline != NULL){//The following extracts the NURBS data from the given Spline.pSpline->getNurbsData(deg, rational, closed, periodic, cPoints, knots, weights,controlPtTol, knotTol);int cnt=cPoints.length();AcGePoint2dArray ncPts;AcGeDoubleArray nweights;nweights.setLogicalLength(cnt);ncPts.setLogicalLength(cnt);for (int i=0; i<=cnt-1; i++){ pSpline->getControlPointAt(i , c3Pt); c2Pt[0]=c3Pt[0]; c2Pt[1]=c3Pt[1]; ncPts.setAt(i , c2Pt); if (weights.length() == 0) { nweights.setAt(i , 1.0); } else { nweights.setAt(i , weights.at(i)); }}AcGeKnotVector knotvec(knots, knotTol);AcGeNurbCurve2d *pNurbcurve=new AcGeNurbCurve2d(deg, knotvec, ncPts, nweights,periodic);pSpline->close();}else{ acedAlert("This is not a Spline entity: "); pEnt->close();}<code_end> |
|