Please see the picture.
Closet point? No
Intersection point? No...
This point is a special point, just corner of the PolyLine.
I plan to only allow the user to select the red line, then the program loops through all polylines near the red line, and then find that point
Is there someone can help me ? very Thanks
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Ah, It’s right, find closet one from the intersection point collection, the one will be the point I want.
But I found a weird problem, Once I use IntersectWith method, it will find the intersection point with the company's 64 computer, but with my family 32 laptop will throw MissingMethodException.
How do I solve this problem?
Thanks
Ah, the exception I have solved, because I reference acdbmgd.dll and acmgd.dll from AutoCAD directly,
Now I reference AcMgd and AcDbMgd from ObjectARX_2010_Win_64_and_32Bit \inc-win32, then I can find the intersection with my family 32 laptop
Another way if your axis lines starts from circle center:
[CommandMethod("L22", CommandFlags.UsePickSet)] public static void TestCutAxisLines() { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = HostApplicationServices.WorkingDatabase; Editor ed = doc.Editor; Entity ent; try { PromptSelectionOptions pso = new PromptSelectionOptions(); pso.MessageForRemoval = "\nNot a line objects, exit."; pso.MessageForAdding = "\nSelect axis lines : "; pso.RejectObjectsOnLockedLayers = true; SelectionFilter lnFilter = new SelectionFilter(new TypedValue[] { new TypedValue(0, "line") }); PromptSelectionResult res = ed.GetSelection(pso, lnFilter); if (res.Status != PromptStatus.OK) return; SelectionSet sset = res.Value; if (sset.Count == 0) return; ed.WriteMessage("\nSelected objects:\t{0}\n", sset.Count); pso = new PromptSelectionOptions(); pso.MessageForRemoval = "\nNot a circle object, exit."; pso.MessageForAdding = "\nSelect a single circle : "; pso.RejectObjectsOnLockedLayers = false; pso.SinglePickInSpace = false;//might be true pso.PrepareOptionalDetails = true; SelectionFilter crFilter = new SelectionFilter(new TypedValue[] { new TypedValue(0, "circle") }); PromptSelectionResult cres = ed.GetSelection(pso, crFilter); if (cres.Status != PromptStatus.OK) return; ed.WriteMessage("\nSelected objects:\t{0}\n", cres.Value.Count); ObjectId scId = cres.Value.GetObjectIds()[0]; pso = new PromptSelectionOptions(); pso.MessageForRemoval = "\nNot a line objects, exit."; pso.MessageForAdding = "\nSelect vertical line : "; pso.RejectObjectsOnLockedLayers = true; pso.SingleOnly = true; pso.SinglePickInSpace = false;//might be true pso.PrepareOptionalDetails = true; res = ed.GetSelection(pso, lnFilter); if (res.Status != PromptStatus.OK) return; ObjectId lnId = res.Value.GetObjectIds()[0]; ed.WriteMessage("\nSelected objects:\t{0}\n", res.Value.Count); Vector3d vec = new Vector3d(); using (Transaction tr = doc.TransactionManager.StartTransaction()) { BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); Entity lnEnt = (Entity)tr.GetObject(lnId, OpenMode.ForRead); Line vline = new Line(); if (lnEnt is Line) { vline = lnEnt as Line; } Entity crEnt = (Entity)tr.GetObject(scId, OpenMode.ForRead); if (crEnt is Circle) { Circle scircle = crEnt as Circle; Point3d dim = vline.GetClosestPointTo(scircle.Center, false); vec = scircle.Center.GetVectorTo(dim); } foreach (SelectedObject sobj in sset) { if (!sobj.ObjectId.IsValid) continue; ent = (Entity)tr.GetObject(sobj.ObjectId, OpenMode.ForWrite); Line ln = new Line(); if (ent is Line) { ln = ent as Line; Point3d p1 = ln.StartPoint; Point3d p2 = ln.EndPoint; Point3dCollection pts = new Point3dCollection() { p1, p2 }; pso = new PromptSelectionOptions(); pso.RejectObjectsOnLockedLayers = false; crFilter = new SelectionFilter(new TypedValue[] { new TypedValue(0, "circle") }); cres = ed.SelectFence(pts, crFilter); if (cres.Status != PromptStatus.OK) return; SelectionSet single = cres.Value; if (single.Count == 0) return; Entity cent = (Entity)tr.GetObject(single.GetObjectIds()[0], OpenMode.ForRead); Circle circ = cent as Circle; Point3d cp = circ.Center; Point3d machpt = new Point3d(); machpt = p1.DistanceTo(cp) < 0.0001 ? p1 : p2; if (machpt.IsEqualTo(p1, new Tolerance(0.0001, 0.0001))) { ed.WriteMessage("\n\tPoint = P1"); machpt = machpt.Subtract(vec.MultiplyBy(-1)); ln.StartPoint = machpt; } else { ed.WriteMessage("\n\tPoint = P2"); machpt = machpt.Add(vec); ln.EndPoint = machpt; } // ln.RecordGraphicsModified(true);//optional // // do rest work with object here // } } tr.Commit(); } } catch (System.Exception ex) { ed.WriteMessage(ex.Message + "\n" + ex.StackTrace); } finally { // do nothing or display an ending message Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage ("\n\t---\tEnd of command L22 is reached. \t---\n"); } }
Oh, This problem has been solved, the approach I take is find the nearest point from the intersection collection, but still very grateful for your help
Maybe you can see my new topic about toolbar, I did not know how to solve that problem, little headache, please