Author Topic: Add bulged segment (create jumpover)  (Read 1063 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
Add bulged segment (create jumpover)
« on: May 20, 2012, 11:36:29 AM »
 
Code: [Select]
       public static void Jumper()   
    {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Matrix3d ucs = ed.CurrentUserCoordinateSystem;
            Database db = doc.Database;
            PromptEntityResult res = ed.GetEntity(new PromptEntityOptions("Select polyline : "));
            if (res.Status != PromptStatus.OK) return;
            ObjectId id = res.ObjectId;
            Point3d pp = res.PickedPoint;
            // Set break gap
            double gap = 3.0;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = (BlockTable)db.BlockTableId.GetObject(OpenMode.ForRead);
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                Entity ent = tr.GetObject(id, OpenMode.ForWrite) as Entity;
                Polyline poly = ent as Polyline;
                if (poly == null) return;
                pp = poly.GetClosestPointTo(pp, false).TransformBy(ucs);
                double par = poly.GetParameterAtPoint(pp);
                double dist = poly.GetDistAtPoint(pp);
                int idx = (int)par;           
                Point3d p1 = poly.GetPointAtDist(dist - gap/2).TransformBy(ucs);
                Point3d p2 = poly.GetPointAtDist(dist + gap/2).TransformBy(ucs);
                poly.AddVertexAt(idx+1, new Point2d(p1.X, p1.Y), 1, 0, 0);
                poly.AddVertexAt(idx+2, new Point2d(p2.X, p2.Y), 0, 0, 0);           
                tr.Commit();
            }
        }

~'J'~