Author Topic: 2d or 3d Extents Selection  (Read 1536 times)

0 Members and 1 Guest are viewing this topic.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2122
  • class keyThumper<T>:ILazy<T>
2d or 3d Extents Selection
« on: March 31, 2023, 09:26:32 PM »
I threw this together as Proof of Concept for a question elsewhere.
The goal was to select an area to print that wasn't dependant on selection order.

I used Point3d throughout and converted to Point2d at the end, with the idea of also using the core code for 3D space.
I imagine it could be a support method and return a bool for success and out either the Extents3d or the min,max points as a tuple.
A little raw, but could be built on.

Code - C#: [Select]
  1. [CommandMethod("TEST_0401")]
  2. public void Select2dExtent()
  3. {
  4.    var doc = AcadApp.DocumentManager.MdiActiveDocument;
  5.    var ed = doc.Editor;
  6.  
  7.    Point3d bp = default, cp = default, minPt = default, maxPt = default;
  8.    PromptPointResult pointResult = default;
  9.  
  10.    // Select BasePoint
  11.    PromptPointOptions promptPointOptions =
  12.       new PromptPointOptions("Select BasePoint for Rectangle")
  13.       {
  14.          AllowArbitraryInput = true,
  15.          AllowNone = false,
  16.          LimitsChecked = true
  17.       };
  18.    pointResult = ed.GetPoint(promptPointOptions);
  19.  
  20.    if (pointResult.Status == PromptStatus.OK)
  21.       bp = pointResult.Value;
  22.    else
  23.    {
  24.       ed.WriteMessage("\n Invalid Base Point Selection.");
  25.       return;
  26.    }
  27.    // Select Opposite Corner
  28.  
  29.    PromptCornerOptions cornerOptions =
  30.       new PromptCornerOptions("Select opposite corner", bp)
  31.       {
  32.          AllowArbitraryInput = true,
  33.          AllowNone = false,
  34.          LimitsChecked = true,
  35.          UseDashedLine = true
  36.       };
  37.    pointResult = ed.GetCorner(cornerOptions);
  38.    if (pointResult.Status == PromptStatus.OK)
  39.       cp = pointResult.Value;
  40.    else
  41.    {
  42.       ed.WriteMessage("\n Invalid Corner Point Selection.");
  43.       return;
  44.    }
  45.  
  46.    ed.WriteMessage($"\nbp: {bp} \ncp: {cp}");
  47.  
  48.    Point3dCollection point3dCollection = new Point3dCollection
  49.    {  bp,
  50.       cp
  51.    };
  52.  
  53.    Extents3d extents = new Extents3d();
  54.    foreach (Point3d point in point3dCollection)
  55.       extents.AddPoint(point);
  56.    minPt = extents.MinPoint;
  57.    maxPt = extents.MaxPoint;
  58.  
  59.    ed.WriteMessage(
  60.       $"\nminPt: {Convert2d(minPt)} " +
  61.       $"\nmaxPt: {Convert2d(maxPt)}");
  62. }
  63.  
  64. public static Point2d Convert2d(Point3d pt)
  65. {
  66.    return new Point2d(pt.X, pt.Y);
  67. }
  68.  


Quote
Command: PSPACE
Command: TEST_0401
Select BasePoint for Rectangle: Select opposite corner:
bp: (65.657928507552,49.0238115360263,0)
cp: (120.84076437841,102.427805337222,0)
minPt: (65.657928507552,49.0238115360263)
maxPt: (120.84076437841,102.427805337222)
Command: TEST_0401
Select BasePoint for Rectangle: Select opposite corner:
bp: (124.336509462923,154.833593887077,0)
cp: (46.6810247156286,61.5013804661373,0)
minPt: (46.6810247156286,61.5013804661373)
maxPt: (124.336509462923,154.833593887077)


Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.