马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 csharp 于 2014-7-2 18:19 编辑
在Help中
[return: MarshalAs(UnmanagedType.U1)]
public virtual bool OnSegmentAt(
int index,
Point2d pt2d,
double value
);
int index
| Input index (0 based) of the vertex
| Point2d pt2d
| Input point (in polyline OCS coords) to check at vertex index
| double value
| Output parameter of at vertex index
|
这个 value 说明是 output parameter ,在 ARX Help 也是这样的,
virtual Adesk::Boolean onSegAt(
unsigned int index,
const AcGePoint2d& pt2d,
double& param) const;
Parameters
| Description
| unsigned int index
| Input index (0 based) of the vertex
| const AcGePoint2d& pt2d
| Input point (in polyline OCS coords) to check at vertex index
| double& param
| Output parameter of at vertex index
|
这是http://adndevblog.typepad.com/autocad/2012/06/use-getclosestpointto-and-onsegat-to-locate-a-polyline-vertex-near-a-point.html
一个例子
static void TEST_PointOnPoly(void)
{
ads_name ename; ads_point pt, ptWcs; AcDbObjectId Id;
if(acedEntSel(_T("Select Pline: "), ename,pt)!=RTNORM) return;
// Convert to WCS incase selection was made // while in a UCS. acdbUcs2Wcs(pt, ptWcs, Adesk::kFalse); acdbGetObjectId(Id,ename); AcDbEntity* pEnt; acdbOpenObject(pEnt,Id,AcDb::kForRead,false);
AcDbPolyline* pLine=NULL; pLine=AcDbPolyline::cast(pEnt);
if(!pLine) { acutPrintf(_T ("Selected Entity not a Polyline")); pEnt->close(); return; }
AcGePoint3d clickpt; // This will convert the pick point to a // point on the polyline pLine->getClosestPointTo(asPnt3d(ptWcs), clickpt); // Convert to 2d point, needed below... AcGePoint2d clickpt2d(clickpt.x, clickpt.y);
for(unsigned int c=0; pLine->numVerts() > c ; c++) { double segParam; // This is the test filter here...it uses the // nifty API onSegAt if(pLine->onSegAt(c, clickpt2d, segParam)) { acutPrintf(_T("Selected Segment: %d \n"),c+1); break; } } pLine->close(); }
在 Net 中测试这个 OnSegmentAt 怎么都没有 output , 自己就写了一个, 可以用来测试自交点所在的实际参数(xdrx_polyline_onsegat)
// based on article by Wayne Brill
// http://adndevblog.typepad.com/autocad/2012/06/use-getclosestpointto-and-onsegat-to-locate-a-polyline-vertex-near-a-point.html
[CommandMethod("oseg")]
public static void TEST_PointOnPoly()
{
Database db = Application.DocumentManager.MdiActiveDocument.Database;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
CoordinateSystem3d cs = ed.CurrentUserCoordinateSystem.CoordinateSystem3d;
Plane plan = new Plane(Point3d.Origin, cs.Zaxis);
Application.SetSystemVariable("osmode", 512);
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
|