Author Topic: Picking multiple points  (Read 2501 times)

0 Members and 1 Guest are viewing this topic.

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Picking multiple points
« on: June 05, 2006, 11:06:24 PM »
I'm probably missing something simple here but is there a way to trap the enter key in a while loop for picking points without resorting to trapping windows messages?? I've tried all sorts of combinations and PromptStatus results to no avail.

Here's some simple code to start with that seems like it should work:
Code: [Select]
[CommandMethod("POINTS")]
public static void GetPoints()
{
Editor ed =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;   
Point3dCollection coll = new Point3dCollection();
int count = 0;
bool picking = true;
while(picking)
{
PromptPointResult res = ed.GetPoint("\nSelect point:" + count);
if (res.Status == PromptStatus.Cancel)
{
return;//exit function all together!
}
if(res.Status != PromptStatus.OK)
{
picking = false;//anything to get out of here and keep my previous points!
}
else //all's still ok so add the point:
{
count++;
coll.Add(res.Value);//add point to collection
}
}


//Print out the points:
for(int i = 0;i < coll.Count;i++)
{
ed.WriteMessage("\nPoint {0} = {1}", i, coll[i].ToString());
}
}

tia,
Mick.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Glenn R

  • Guest
Re: Picking multiple points
« Reply #1 on: June 06, 2006, 12:13:04 AM »
Here's one way Mick:

Code: [Select]
[CommandMethod("MickyDpts")]
static public void MickyDptsCommand()
{
// Get a pointer to the current doument's editor...
Editor pEd = acadApp.DocumentManager.MdiActiveDocument.Editor;
// Init our point bucket...
Point3dCollection retPts = new Point3dCollection();
// Loop control...
bool keepPicking = true;

while (keepPicking) {
PromptPointOptions promptPtOptions = new PromptPointOptions("\nSpecify point [Enter to exit]", "Enter");
promptPtOptions.AllowNone = true;
promptPtOptions.Keywords.Default = "Enter";

PromptPointResult pointResult = pEd.GetPoint(promptPtOptions);

pEd.WriteMessage("\nPrompt result: {0}", pointResult.ToString());

switch (pointResult.Status) {
case PromptStatus.Cancel :
return;

case PromptStatus.OK :
retPts.Add(pointResult.Value);
break;

case PromptStatus.Keyword :
switch (pointResult.StringResult) {
case "Enter" :
keepPicking = false;
break;

default :
keepPicking = false;
break;
}
break;
}

}
}

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Re: Picking multiple points
« Reply #2 on: June 06, 2006, 12:26:00 AM »
And that way will do nicely thanks Glenn, so there's a bit of mojo happening behind the scenes with keywords and the enter/spacebar keys, cool.
Thanks Again,
Mick.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Glenn R

  • Guest
Re: Picking multiple points
« Reply #3 on: June 06, 2006, 12:31:45 AM »
No wuckers Mick. It was just a quickie to point you in the direction (pardon the pun) of PromptPointOptions.
Take one out for a spin and play with it.

Cheers,
Glenn.

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Re: Picking multiple points
« Reply #4 on: July 12, 2008, 08:51:04 PM »
heh, how the worm turns, I was porting some C# code to 2008 and wanted to make some changes to the user interaction and I was stuck again. I was using PPO's but lacked the keyword, did a quick search with "loop enter" and voila! first thread :)

I guess the memory does fade a bit after a couple of years (I'm sure it has nothing to do with any lifestyle vices though), thanks again Glenn!
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

sinc

  • Guest
Re: Picking multiple points
« Reply #5 on: July 13, 2008, 09:10:37 AM »
Note that there are other ways to do that.  You don't have to use an "Enter" keyword.

Another way would simply be to set "promptPtOptions.AllowNone = true", and then check the result for PromptStatus.None.  If the user simply hits return without entering any data, then the return result will be PromptStatus.None.  The key is that you must first set "AllowNone = true" in the PromptPointOptions.

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Re: Picking multiple points
« Reply #6 on: July 13, 2008, 06:51:34 PM »
Yeah, I pretty well tried them all but I was getting some unpredictable results (??), it would work ok for a few points and occasionally it would crash out, using the keyword has tightened it right up and I'm yet to have an error.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

sinc

  • Guest
Re: Picking multiple points
« Reply #7 on: July 14, 2008, 12:40:08 AM »
I have used PromptStatus.None extensively and have never noticed it to be flaky or in any way unreliable.  There was probably some issue with your code logic.

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Re: Picking multiple points
« Reply #8 on: July 14, 2008, 01:03:49 AM »
No doubt! :) I'll have to take another look though, I thought I tried them all (error, other etc)

The key word suits for other reasons as well though, I also have some other setttings/options so it's no biggy to use the enter as an out and it's more informative for the user to exit IMO.

I did find some issues with pother code but I've filled the gaps now (I hope) and it's running pretty slick.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien