Author Topic: where is the point in polyline? (in c#)  (Read 3120 times)

0 Members and 1 Guest are viewing this topic.

itcad

  • Guest
where is the point in polyline? (in c#)
« on: June 23, 2007, 09:30:00 AM »

A point is in a polyline,and it is between two vertics.where is the two vertics?(c#)

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: where is the point in polyline? (in c#)
« Reply #1 on: June 23, 2007, 11:14:32 AM »
This should give you the idea.
Code: [Select]
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;

using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace GetVertices
{
    public class getvertices
    {
        [CommandMethod("GetVerts")]
        public void getVerts()
        {
            Document doc = acadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            PromptEntityResult res = ed.GetEntity("\nSelect Polyline: ");
            if (res.Status != PromptStatus.OK) return;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Curve oCrv = tr.GetObject(res.ObjectId, OpenMode.ForRead, false) as Curve;
                Point3d pt1 = oCrv.GetClosestPointTo(res.PickedPoint, false);
                double param_pt1 = oCrv.GetParameterAtPoint(pt1);
                double param1 = (double)Math.Floor(param_pt1);
                double param2 = param1 + 1;
                Point3d v1 = oCrv.GetPointAtParameter(param1);
                Point3d v2 = oCrv.GetPointAtParameter(param2);
                ed.WriteMessage("\nVert1=" + v1.ToString() + ", Vert2=" + v2.ToString());
            }
        }

    }
}

itcad

  • Guest
Re: where is the point in polyline? (in c#)
« Reply #2 on: June 23, 2007, 11:14:00 PM »
It's ok.
thanks.