.NET

Reply
Valued Contributor
HelloWorlddd
Posts: 87
Registered: ‎05-03-2013
Message 1 of 8 (333 Views)
Accepted Solution

How to get this point

333 Views, 7 Replies
12-29-2013 08:13 PM

Please see the picture.

 

ThisPoint.PNG

 

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

Hi,

 

If I don't misunderstand, in the Point3dCollection filled with the IntersectWith() method, look for the closest closest to the line EndPoint one.

*Expert Elite*
_gile
Posts: 2,133
Registered: ‎04-29-2006
Message 2 of 8 (297 Views)

Re : How to get this point

12-29-2013 11:33 PM in reply to: HelloWorlddd

Hi,

 

If I don't misunderstand, in the Point3dCollection filled with the IntersectWith() method, look for the closest closest to the line EndPoint one.

Gilles Chanteau
Valued Contributor
HelloWorlddd
Posts: 87
Registered: ‎05-03-2013
Message 3 of 8 (283 Views)

Re : How to get this point

12-30-2013 01:35 AM in reply to: _gile

   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

Valued Contributor
HelloWorlddd
Posts: 87
Registered: ‎05-03-2013
Message 4 of 8 (278 Views)

Re : How to get this point

12-30-2013 01:59 AM in reply to: HelloWorlddd

   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

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 5 of 8 (223 Views)

Re : How to get this point

12-31-2013 12:28 AM in reply to: HelloWorlddd

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");
                }
            }

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Contributor
HelloWorlddd
Posts: 87
Registered: ‎05-03-2013
Message 6 of 8 (204 Views)

Re : How to get this point

12-31-2013 03:44 AM in reply to: Hallex

   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

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 7 of 8 (198 Views)

Re : How to get this point

12-31-2013 06:53 AM in reply to: HelloWorlddd
Good for you,
Cheers
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Contributor
HelloWorlddd
Posts: 87
Registered: ‎05-03-2013
Message 8 of 8 (196 Views)

Re : How to get this point

12-31-2013 07:00 AM in reply to: Hallex

Maybe you can see my new topic about toolbar, I did not know how to solve that problem, little headache, please :smileyembarrassed:  

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.