Author Topic: How to get the entities which intersect a specific entity  (Read 4757 times)

0 Members and 1 Guest are viewing this topic.

teslaxx

  • Guest
How to get the entities which intersect a specific entity
« on: December 20, 2010, 09:14:02 AM »
My situation: I have a block which is formed from lots of lines, arcs and polylines and every lines, arcs and polylines is intersected by at least one leader (line with arrow) .
In the same time, every leader is connected to a text entity (which I want to modify).

How can I get the text, based on the intersections. I looked over the AutoCAD .NET Developer's Guide, but I din't find anything. Probably I need a method which returns a list with all the entities whichintersect the selected object. Any solutions?

P.S. I have another question: how can I get the closest entity from a specific point or from a specific entity?
« Last Edit: December 20, 2010, 09:24:45 AM by teslaxx »

Jeff H

  • Needs a day job
  • Posts: 6150
Re: How to get the entities which intersect a specific entity
« Reply #1 on: December 23, 2010, 11:55:44 PM »
It seems like Kerry has helped someone else out on how to find the closest entitiy to a point.
If I find the thread I will post it.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to get the entities which intersect a specific entity
« Reply #2 on: December 24, 2010, 03:14:51 AM »
I don't recall doing one Jeff ..

So cobbled this together for fun.
It's a little vulgar but does the job.


filters can be added.

Perhaps a SelectCrossingPolygon would be better for a more circular selection

but it doesn't have a forceSubEntitySelection option

ie: public PromptSelectionResult SelectCrossingWindow(Point3d pt1, Point3d pt2, SelectionFilter filter, bool forceSubEntitySelection);


added: I work in metric so I've used 1 and -1 for the growth vectors ... fine tune o suit :)

Code - C#: [Select]
  1.  
  2. // (C) CodeHimBelonga kdub@theSwamp 2010
  3. //
  4. using System;
  5. using System.Windows.Forms;
  6. using Autodesk.AutoCAD.ApplicationServices;
  7. using Autodesk.AutoCAD.DatabaseServices;
  8. using Autodesk.AutoCAD.EditorInput;
  9. using Autodesk.AutoCAD.Geometry;
  10. using Autodesk.AutoCAD.Runtime;
  11. using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
  12.  
  13. [assembly: CommandClass(typeof(kdub_Testing.SelectNearPoint))]
  14.  
  15. namespace kdub_Testing
  16. {
  17.     public class SelectNearPoint
  18.     {
  19.         /// <summary>
  20.         ///
  21.         /// </summary>
  22.         [CommandMethod("sel5")]
  23.         public void
  24.             Select05()
  25.         {
  26.             Point3d pointToTry = new Point3d(0.0, 0.0, 0.0);
  27.             ObjectIdCollection stuff;
  28.  
  29.             stuff = SelectSomewhereNearPoint(pointToTry);
  30.  
  31.             if(stuff.Count >= 1) {
  32.                 string desc = (stuff.Count == 1) ? "  thingy." : "  thingies.";
  33.                 System.Windows.Forms.MessageBox.Show("we collected  " + stuff.Count.ToString() + desc,
  34.                                 "Wheeeeeee",
  35.                                 MessageBoxButtons.OK,
  36.                                 MessageBoxIcon.Information
  37.                                 );
  38.             } else {
  39.                 System.Windows.Forms.MessageBox.Show("You Made Boo-Boo Selection",
  40.                         "Oooooops",
  41.                         MessageBoxButtons.OK,
  42.                         MessageBoxIcon.Hand
  43.                         );
  44.             }
  45.         }
  46.         /// <summary>
  47.         ///
  48.         /// </summary>
  49.         /// <param name="point"></param>
  50.         /// <returns></returns>
  51.         public static
  52.             ObjectIdCollection SelectSomewhereNearPoint(Point3d point)
  53.         {
  54.             Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
  55.             Point3d ll = point;
  56.             Point3d ur = point;
  57.             Vector3d minus = new Vector3d(-1, -1, 0);
  58.             Vector3d plus = new Vector3d(1, 1, 0);
  59.             PromptSelectionResult result;
  60.             result = ed.SelectCrossingWindow(ll, ur);
  61.             while(result.Status != PromptStatus.OK) {
  62.                 ll = ll.Add(minus);
  63.                 ur = ur.Add(plus);
  64.                 result = ed.SelectCrossingWindow(ll, ur);
  65.             }
  66.             return new ObjectIdCollection(result.Value.GetObjectIds());
  67.         }
  68.     }
  69. }
  70.  
  71.  
« Last Edit: February 19, 2014, 12:56:54 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.