Author Topic: Prompt for two points or simply enter  (Read 1768 times)

0 Members and 1 Guest are viewing this topic.

Bernd

  • Newt
  • Posts: 31
Prompt for two points or simply enter
« on: December 09, 2021, 07:55:27 AM »
Hi,
I thought it'd be totally trivial to ask a user for two points on screen or simply let her press [Enter] to select the visible area. But it seems it isn't. :-(
My purpose is to get the corners of an area for me to read elements out of some database. Simple enough - only that I was pretty annoyed to always have to pick two points when I actually almost always want to read elements in the currently displayed area.
I thought of something along the lines
Code - C#: [Select]
  1. var ppo = new EditorInput.PromptPointOptions("\nPlease enter first corner or [Enter] for visible screen");
  2. EditorInput.PromptPointResult ppr = editor.GetPoint(ppo);
  3. ...
  4.  
Editor.GetString() doesn't let me pick a point and Editor.GetPoint() doesn't let me hit Enter. So - is there a way to do this? I'm pretty sure there is so help would be really appreciated...

Thanks, Bernd

n.yuan

  • Bull Frog
  • Posts: 348
Re: Prompt for two points or simply enter
« Reply #1 on: December 09, 2021, 09:57:55 AM »
How does AutoCAD know that you want select entire visible area? It certainly does not know it just because your code prompts user to press "Enter".

So, you either let user to pick 2 points as the opposite corners of the desired area, or calculate the current view's 2 corners if user simply pressed "Enter". In the latter case, you need to set up PromptPointOptions to allow keyword and accept null input while calling Editor.GetPoint(). Something like:

Point3d corner1;
Point3d corner2;
var opt=new PromptCornerOptions("\nSelect first corner point of the area, or select entire view area:")
opt.Allownone=true;
opt.Keywords.Add("Entire");
opt.Keywords.Default="Entire";
...
var res=ed.GetCorner(opt);
if (res.Status==PromptStatus.Ok || res.Status==PromptStatus.Keyword)
{
    if (res.Status==PromptStatus.Ok)
    {
        corner1=res.Value;
        // Ask user to pick the other corner
    }
    else
    {
        // Now, you calculate the 2 corners of the current view
        GetCurrentViewCorners(out corner1, out corner2)
    }
}
else
{
   // return....
}

You can read this articles on how to easily calculate current view's size:

https://drive-cad-with-code.blogspot.com/2013/04/how-to-get-current-view-size.html

Bernd

  • Newt
  • Posts: 31
Re: Prompt for two points or simply enter
« Reply #2 on: December 09, 2021, 10:05:52 AM »
Thanks Norman,
I know that I have to calculate the extents myself of course - my problem was the combination of GetPoint() and GetString() which you showed how to cope with. :-)