Author Topic: Get Curve Length  (Read 630 times)

0 Members and 1 Guest are viewing this topic.

Offline fixo

  • Full Member
  • ***
  • Posts: 135
  • Karma: +4/-0
  • Gender: Male
    • prefered language: C
    • Prog expertise: Good
    • View Profile
Get Curve Length
« on: January 03, 2013, 09:17:45 AM »
 
Code: [Select]
       [CommandMethod("getCurveLength", "cul", CommandFlags.Modal | CommandFlags.UsePickSet)]
        public void CurveLength()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            Transaction tr = doc.TransactionManager.StartTransaction();
            double startParam, endParam, length;
            using (tr)
            {

                PromptEntityOptions peo = new PromptEntityOptions("\nSelect Curve >>");
                peo.SetRejectMessage("\nSelect Curve only >>");
                peo.AddAllowedClass(typeof(Curve), false);
                PromptEntityResult res;
                res = ed.GetEntity(peo);
                if (res.Status != PromptStatus.OK)
                    return;
                Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
                if (ent == null)
                    return;
                Curve curve = (Curve)ent as Curve;
                if (curve != null)
                {
                    startParam = curve.StartParam;

                    endParam = curve.EndParam;

                    length = curve.GetDistanceAtParameter(endParam) - curve.GetDistanceAtParameter(startParam);

                    ed.WriteMessage("\nLength = {0:f3}\n", length);

                }//end getentity

                tr.Commit();
            }//end using transaction
        }