Posts: 165
Registered: ‎07-20-2011
Message 11 of 13 (118 Views)

Re: Key Point

12-27-2013 12:46 PM in reply to: HelloWorlddd
solved it ?
Posts: 165
Registered: ‎07-20-2011
Message 12 of 13 (111 Views)

Re: Key Point

12-27-2013 03:40 PM in reply to: SENL1362

This may get  you on track


using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;

namespace line2Circle
    public class Class1
        public void LineTwoCircle()
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            using (Transaction tr = db.TransactionManager.StartTransaction())
                BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                PromptEntityOptions promptForLine = new PromptEntityOptions("\nSelect the Line:");
                promptForLine.SetRejectMessage("Lines only");
                promptForLine.AddAllowedClass(typeof(Line), true);
                PromptEntityResult getLineRes = ed.GetEntity(promptForLine);
                if (getLineRes.Status != PromptStatus.OK)

                Line ln = (Line)tr.GetObject(getLineRes.ObjectId, OpenMode.ForRead);
                ed.WriteMessage("\nLine: {0}..{1}", ln.StartPoint, ln.EndPoint);

                PromptEntityOptions promptForCircle = new PromptEntityOptions("\nSelect a Circle:");
                promptForLine.SetRejectMessage("Circles only");
                promptForLine.AddAllowedClass(typeof(Circle), true);
                PromptEntityResult getCircleRes = ed.GetEntity(promptForCircle);
                if (getCircleRes.Status != PromptStatus.OK)
                Circle cir = (Circle)tr.GetObject(getCircleRes.ObjectId, OpenMode.ForRead);
                ed.WriteMessage("\nCircle: {0},{1}", cir.Center,cir.Radius);

                Circle tmpCircle = new Circle(cir.Center, new Vector3d(0,0,1),cir.Radius + 1);
                tr.AddNewlyCreatedDBObject(tmpCircle, true);
                Point3dCollection interSections = new Point3dCollection();
                ln.IntersectWith(tmpCircle, Intersect.ExtendThis, interSections, 0, 0);
                if (interSections.Count < 0)
                    ed.WriteMessage("\nFault: Line does not intersect with this circle");
                    for (int i = 0; i < interSections.Count; i++)
                        ed.WriteMessage("\nIntersection[{0}={1}", i, interSections[i]);

                    if (ln.StartPoint.DistanceTo(interSections[0]) < ln.EndPoint.DistanceTo(interSections[0]))
                    Point3d peNew = interSections[0];

                    if (ln.StartPoint.DistanceTo(peNew) > ln.StartPoint.DistanceTo(interSections[1]))
                        peNew = interSections[1];

                    //Next lines modify the source line.
                    //ln.EndPoint = peNew;
                    //for debug mode w'll create a new (Temporary) line
                    Line tmpLn = new Line(ln.StartPoint, peNew);
                    tr.AddNewlyCreatedDBObject(tmpLn, true);
                //double dX = ln.EndPoint.X - ln.StartPoint.X;
                //double dY = ln.EndPoint.Y - ln.StartPoint.Y;
                //Point3d ps = cir.Center;
                //double xPe=cir.Center.X-dY;
                //double yPe=cir.Center.Y+dX;
                //Point3d pe = new Point3d(xPe, yPe, cir.Center.Z);
                //Line lnPp = new Line(ps, pe);
                //tr.AddNewlyCreatedDBObject(lnPp, true);

                //Point3dCollection interSections = new Point3dCollection();
                //ln.IntersectWith(lnPp, Intersect.ExtendBoth, interSections, 0,0);
                //ed.WriteMessage("\n Intersection={0}", interSections[0]);
                //lnPp.EndPoint = interSections[0];
                //if (lnPp.Length > cir.Radius)
                //    ed.WriteMessage("\nNo intersection with the Circle");
                //else if  (lnPp.Length < cir.Radius)
                //    ed.WriteMessage("\nTwo intersection with the Circle");
                //    ed.WriteMessage("\nOne exact intersection with the Circle");





Valued Contributor
Posts: 87
Registered: ‎05-03-2013
Message 13 of 13 (95 Views)

Re: Key Point

12-28-2013 09:22 AM in reply to: SENL1362

   Yes, I solved it by this Message from this Form as you said:
   Measure perpendicular distance between 2 polylines

   Very thanks

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community