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.
[CommandMethod("TEST_0401")]
public void Select2dExtent()
{
var doc = AcadApp.DocumentManager.MdiActiveDocument;
var ed = doc.Editor;
Point3d bp = default, cp = default, minPt = default, maxPt = default;
PromptPointResult pointResult = default;
// Select BasePoint
PromptPointOptions promptPointOptions =
new PromptPointOptions
("Select BasePoint for Rectangle") {
AllowArbitraryInput = true,
AllowNone = false,
LimitsChecked = true
};
pointResult = ed.GetPoint(promptPointOptions);
if (pointResult.Status == PromptStatus.OK)
bp = pointResult.Value;
else
{
ed.WriteMessage("\n Invalid Base Point Selection.");
return;
}
// Select Opposite Corner
PromptCornerOptions cornerOptions =
new PromptCornerOptions
("Select opposite corner", bp
) {
AllowArbitraryInput = true,
AllowNone = false,
LimitsChecked = true,
UseDashedLine = true
};
pointResult = ed.GetCorner(cornerOptions);
if (pointResult.Status == PromptStatus.OK)
cp = pointResult.Value;
else
{
ed.WriteMessage("\n Invalid Corner Point Selection.");
return;
}
ed.WriteMessage($"\nbp: {bp} \ncp: {cp}");
Point3dCollection point3dCollection
= new Point3dCollection
{ bp,
cp
};
Extents3d extents
= new Extents3d
(); foreach (Point3d point in point3dCollection)
extents.AddPoint(point);
minPt = extents.MinPoint;
maxPt = extents.MaxPoint;
ed.WriteMessage(
$"\nminPt: {Convert2d(minPt)} " +
$"\nmaxPt: {Convert2d(maxPt)}");
}
public static Point2d Convert2d(Point3d pt)
{
return new Point2d
(pt
.X, pt
.Y); }
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)