Author Topic: Fun : going Home ?  (Read 17897 times)

0 Members and 1 Guest are viewing this topic.

Draftek

  • Guest
Re: Fun : going Home ?
« Reply #15 on: December 15, 2005, 07:46:57 AM »
cool, thanks.

I will be using this in the future too.

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Fun : going Home ?
« Reply #16 on: December 15, 2005, 04:31:15 PM »
yes. !

It's declared as a string.
The error message mentions a 'bracketed keyword list'.

I'm guessing that it expects a 'special' formatting.

Thats the problem .. I'm guessing. !

Maybe the exception message is trying to say "Doesn't take bracketed keyword list" ??

From a logical point of view it couldn't take anything but a single string, how would it know where one keyword starts and the next and so on??
Also, from a design point of view it would be much clearer to the user and easier to declare it as taking a string[].
 I don't know ???
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Fun : going Home ?
« Reply #17 on: December 15, 2005, 05:16:04 PM »
I tried with a string. may have to be formatted or delimited in some way so that the parser can determine the keywords, though a space is a delimiter, yes.

I have passed the question on, so ....
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.

Glenn R

  • Guest
Re: Fun : going Home ?
« Reply #18 on: December 15, 2005, 07:28:10 PM »
Code: [Select]
[CommandMethod("Prompts")]
static public void test()
{
// Get a pointer to the editor...
Editor pEd = pAcadApp.DocumentManager.MdiActiveDocument.Editor;

// Set the prompt and keywords...
PromptKeywordOptions promptKwOpts = new PromptKeywordOptions("\nIs this what you want Kerry [Yes/No]", "Yes No");
// Set the default so the user can just hit 'ENTER'...
promptKwOpts.Keywords.Default = "Yes";

PromptResult promptRes = pEd.GetKeywords(promptKwOpts);

if (promptRes.Status == PromptStatus.Cancel)
return;

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

// It's OK, but which keyword did they use?
if (promptRes.Status == PromptStatus.OK)
{
switch(promptRes.StringResult)
{
case "Yes" :
pEd.WriteMessage("\nYou entered 'Yes', so I take it it is!");
break;
case "No" :
pEd.WriteMessage("\nYou entered 'No', so it isn't!");
break;
}
}

}

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Fun : going Home ?
« Reply #19 on: December 15, 2005, 07:58:38 PM »
This is embarrassing !

May have been the bourbon ...

 :oops:
I thought I tried exactly that ..
 :oops:

I'll have another look tonight, thanks Glenn

If that works, it may be fairly simple to pass a keyword string to a generic helper and build the prompt with the bracketed options.
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Fun : going Home ?
« Reply #20 on: December 15, 2005, 08:12:39 PM »
Thanks Sir  !!

Quote
Command: forMe
Is this what you want Kerry [Yes/No] <Yes>: yo
Invalid option keyword.
Is this what you want Kerry [Yes/No] <Yes>: y
Prompt result: (OK,Yes)
You entered 'Yes', so I take it it is!
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.

Glenn R

  • Guest
Re: Fun : going Home ?
« Reply #21 on: December 15, 2005, 08:17:40 PM »
Hehe...:-D... you're welcome.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Fun : going Home ?
« Reply #22 on: December 15, 2005, 08:26:22 PM »
Here's something comforting :
Note the additional   keywordOptions.Keywords.Add("Perhaps");

The Keyword is added automagically to the prompt as well .. How cool is that !

Code: [Select]
        public void Method003()
        {
            // Get a pointer to the editor...
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;

            // Set the prompt and keywords...
            PromptKeywordOptions keywordOptions = new PromptKeywordOptions(
                                          "\nIs this what you want Kerry [Yes/No]", "Yes No");
            // Set the default so the user can just hit 'ENTER'...

            keywordOptions.Keywords.Add("Perhaps");
            keywordOptions.Keywords.Default = "Yes";

            PromptResult promptRes = ed.GetKeywords(keywordOptions);

            if (promptRes.Status == PromptStatus.Cancel)
                return;

            ed.WriteMessage("\nPrompt result: {0}", promptRes.ToString());

            // It's OK, but which keyword did they use?
            if (promptRes.Status == PromptStatus.OK)
            {
                switch (promptRes.StringResult)
                {
                    case "Yes":
                        ed.WriteMessage("\nYou entered 'Yes', so I take it it is!");
                        break;
                    case "No":
                        ed.WriteMessage("\nYou entered 'No', so it isn't!");
                        break;
                }
            }

        }
« Last Edit: December 15, 2005, 08:31:35 PM by Kerry Brown »
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.

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Fun : going Home ?
« Reply #23 on: December 15, 2005, 08:30:00 PM »
Very cool.

Thanks again Glenn, it even looks easy now :)
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

Glenn R

  • Guest
Re: Fun : going Home ?
« Reply #24 on: December 15, 2005, 09:17:50 PM »
No worries lads.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Fun : going Home ?
« Reply #25 on: December 15, 2005, 11:05:49 PM »
A bit more investigation, so the future calls wont be Monkey see, Monkey do ..

The constructors for the Autodesk.AutoCAD.EditorInput.PromptKeywordOptions class are :
Quote
PromptKeywordOptions(
    System.String message)

// and

PromptKeywordOptions(
    System.String messageAndKeywords,
    System.String globalKeywords)

The error exception message   ---> System.ArgumentException: No bracketed keyword list
referred to the format of the messageAndKeywords string, not the globalKeywords string as I assumed < yep, THAT word again >

SO :

This works
Code: [Select]
keywordOptions = new PromptKeywordOptions("\n Choose dude [Yes/No]", "Yes No");
This spits the dummy at run time
Code: [Select]
keywordOptions = new PromptKeywordOptions("\n Choose dude", "Yes No");
Hope that assists anyone following the breadcrumbs. :-)
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Fun : going Home ?
« Reply #26 on: December 16, 2005, 06:06:51 AM »
I'm just about to venture into keywords so this topic will come in handy.

Have you tried to handle an 'esc' from the user yet (in mid command that is), I've noticed using Prompts and ed.get##### etc. that when you escape it goes on to the next prompt instead of exiting the function. I haven't had time to explore this as yet but it's worth discussion when using/getting user input.

Something like this to assert a valid Result prior to testing the value of the Result seems to work as a generic procedure ..
Code: [Select]
            //-----------------------------------------------------------------
            PromptKeywordOptions keywordOptions = new PromptKeywordOptions("messageAndKeywords", "globalKeywords");
            PromptResult promptResult = ed.GetKeywords(keywordOptions);
            switch (promptResult.Status)
            {
                case PromptStatus.Cancel:
                    ed.WriteMessage("\nUser cancelled.");
                    return;
                    break;
                case PromptStatus.Error:
                    ed.WriteMessage("\nUser input error.");
                    return;
                    break;
                case PromptStatus.OK:
                    break;
            }
            //-----------------------------------------------------------------
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Fun : going Home ?
« Reply #27 on: December 16, 2005, 08:19:50 AM »
Just 'cause I needed to know, I ran a reflector over the PromptKeywordOptions constructor in the Autodesk.AutoCAD.EditorInput namespace of ACMGD.DLL.

.. in case anyone is interested, the Parse method was throwing the exception
'cause it failed this :
Quote
int num3 = promptAndKeywords.LastIndexOf("[");
 int num5 = promptAndKeywords.LastIndexOf("]");
 if ((num3 < 0) || (num5 <= (num3 + 1)))
{ Spit the DUMMY HERE

With the current absence of explicit documentation, deciphering the conditionals is the only way I can see to ensure the formatting is correct.

Code: [Select]
protected internal PromptOptions(string messageAndKeywords, string globalKeywords)
{
      this.CommonInit(null);
      this.SetMessageAndKeywords(messageAndKeywords, globalKeywords);
}
Code: [Select]
public void SetMessageAndKeywords(string messageAndKeywords, string globalKeywords)
{
      this.throwIfReadOnly();
      PromptParser parser1 = new PromptParser();
      parser1.Parse(messageAndKeywords, globalKeywords);
      this.m_message = parser1.Prompt;
      this.m_keywords = parser1.Keywords;
}
Code: [Select]
internal unsafe void Parse(string promptAndKeywords, string globalKeywords)
{
      int num3 = promptAndKeywords.LastIndexOf("[");
      int num5 = promptAndKeywords.LastIndexOf("]");
      if ((num3 < 0) || (num5 <= (num3 + 1)))
      {
            throw new ArgumentException(new string((sbyte*) &??_C@_0BK@PDCKAIIB@No?5bracketed?5keyword?5list?$AA@));
      }
      if (num3 > 0)
      {
            this.m_prompt = promptAndKeywords.Substring(0, num3).TrimEnd(null);
      }
      else
      {
            this.m_prompt = "";
      }
      int num6 = promptAndKeywords.Length - num5;
      if ((num6 > 0) && (promptAndKeywords.Substring(num5 + 1, num6 - 1).TrimEnd(null).Length > 0))
      {
            throw new ArgumentException("Invalid text trailing the bracketed keywords");
      }
      string[] textArray1 = promptAndKeywords.Substring(num3 + 1, (num5 - num3) - 1).Split("/".ToCharArray());
      string[] textArray3 = new string[textArray1.Length];
      int num2 = textArray1.Length;
      if (num2 <= 0)
      {
            throw new ArgumentException("Bracketed keyword list is empty");
      }
      int num4 = 0;
      if (0 < num2)
      {
            do
            {
                  textArray3[num4] = PromptParser.ParseLocalKeyword(textArray1[num4]);
                  num4++;
            }
            while (num4 < num2);
      }
      string[] textArray2 = PromptParser.SplitByWhitespace(globalKeywords);
      if (num2 != textArray2.Length)
      {
            throw new ArgumentException("Mismatched number of global and local keywords");
      }
      this.m_keywords = new KeywordCollection();
      int num1 = 0;
      if (0 < num2)
      {
            do
            {
                  this.m_keywords.Add(textArray2[num1], textArray3[num1], textArray1[num1]);
                  num1++;
            }
            while (num1 < num2);
      }
}
« Last Edit: December 16, 2005, 08:32:13 AM by Kerry Brown »
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.