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

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Fun : going Home ?
« on: December 14, 2005, 10:54:40 PM »
Just playing around ...

Code: [Select]
#region System using declarations
using System;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;

using System.Text;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using System.ComponentModel;
using Microsoft.VisualBasic;
using System.Text.RegularExpressions;
#endregion

#region AutoCAD COM Interop using declarations
//// COM Interop References
//// AutoCAD 2006 Type Library
using Autodesk.AutoCAD.Interop;

//// AXDBLib AutoCAD/ObjectDBX Common 16.0 Type Library
using Autodesk.AutoCAD.Interop.Common;

#endregion

#region AutoCAD Managed Wrappers using declarations
//// Assembly acdbmgd .. ObjectDBX.NET Managed Wrapper
//// Assembly acmgd .. Autocad.NET Managed Wrapper
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Colors;
#endregion

#region Alias using declarations
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
#endregion

// codehimbelonga kwb : posted@TheSwamp 20051215

[assembly: ExtensionApplication(typeof(ClassLibrary20051215.StartApp))]
[assembly: CommandClass(typeof(ClassLibrary20051215.Commands))]

namespace ClassLibrary20051215
{
    #region CommandClass
    //-------------------------------------------------------------------------------
    public class
    Commands
    {
        [CommandMethod("myHelp", CommandFlags.Modal)]
        static public void
        TEMPLATEHelp()
        {
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;

            ed.WriteMessage("\n  Testing Assembly [kwb v:20051215]");
            ed.WriteMessage("\n  Commands : GoHome");
        }
        //----------------------------

        [CommandMethod("GoHome", CommandFlags.Modal)]
        public static void Command_GoHome()
        {
            Class1 tester = new Class1();
            tester.Method001();
        }
        //----------------------------
    }
    #endregion


    #region MainApp core
    //-------------------------------------------------------------------------------
    public class Class1
    {
        public void Method001()
        {
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
            DateTime dt = DateTime.Now;

            bool yesnoResult;

            PromptStatus promptStatus = LibTools.TellmeYesNo(string.Format(
                "\nIt's only {0}, are you sure you want to quit ?", dt.ToString("HH:mm")),
                false, out yesnoResult);
            if ((promptStatus != PromptStatus.OK) || (yesnoResult == false))
                MessageBox.Show("\n.. Well get back to work, slacker .. !", "I'm the boss of you, OK !");
            else
                MessageBox.Show("\ngoodbye, slacker .. ");
        }
    }
    #endregion


    #region LibraryTools
    //-------------------------------------------------------------------------------
    public class LibTools
    {
        public static PromptStatus
        TellmeYesNo(string message, bool useYesDefault, out bool yesnoResult)
        {
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;

            yesnoResult = false;

            string defaultAnswer = (useYesDefault) ? "Yes" : "No";
            PromptKeywordOptions keywordOptions = new PromptKeywordOptions(message);
            keywordOptions.Keywords.Add("Yes");
            keywordOptions.Keywords.Add("No");
            keywordOptions.Keywords.Default = defaultAnswer;

            PromptResult keywordResult = ed.GetKeywords(keywordOptions);
            if (keywordResult.Status == PromptStatus.OK)
            {
                if (keywordResult.StringResult == "Yes")
                    yesnoResult = true;
            }
            return keywordResult.Status;
        }
    }
    #endregion


    #region Public class StartApp
    //-------------------------------------------------------------------------------
    /// <summary>
    /// The entry point for AutoCAD.
    /// </summary>
    public class
    StartApp : IExtensionApplication
    {
        public void
        Initialize()
        {
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;

            Commands.TEMPLATEHelp();
            ed.WriteMessage("\n  Type 'myHelp' at the Command Line for assistance ...");
        }
        public void
        Terminate()
        {
            // Does Nothing ... can't unload NET assembly ...
        }
    }
    #endregion
}
« Last Edit: December 15, 2005, 12:33:29 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.

MickD

  • King Gator
  • Posts: 3665
  • (x-in)->[process]->(y-out) ... simples!
Re: Fun : going Home ?
« Reply #1 on: December 15, 2005, 12:06:57 AM »
heh, shouldn't they both say "...get back to work slacker!" :D
"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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Fun : going Home ?
« Reply #2 on: December 15, 2005, 12:25:01 AM »
.. or :-

"Sure, you can go home. Grab a couple of beers from the frig' to take with you."

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 #3 on: December 15, 2005, 01:17:39 AM »
We could add this in for you Mick .. !

Code: [Select]
        //--------------------------------------
        public void Method002()
        {
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
           
            bool yesnoResult;
           
            PromptStatus promptStatus = TellmePerhaps("\n Like a cold beer Mick ?",
                out yesnoResult);
            if ((promptStatus == PromptStatus.OK) && (yesnoResult == true))
                MessageBox.Show("\n.. Help Yourself to a couple .. !", "It's beer o'clock !");
            else
                MessageBox.Show("\n too bad, so sad .. ");

        }
        //--------------------------------------
        public static PromptStatus
        TellmePerhaps(string message, out bool yesnoResult)
        {
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
            yesnoResult = false;

            string[] options = { "Yes", "No", "Perhaps", "noSir" , "BloodyOathMate" };

            PromptResult keywordResult = ed.GetKeywords(message, options);
            if (keywordResult.Status == PromptStatus.OK)
            {
                if ((keywordResult.StringResult == "Yes")
                    || (keywordResult.StringResult == "BloodyOathMate"))
                    yesnoResult = true;
            }
            return keywordResult.Status;
        }

added: corrected the option of providing beverages if ESC was hit :-)
« Last Edit: December 15, 2005, 01:44:05 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.

MickD

  • King Gator
  • Posts: 3665
  • (x-in)->[process]->(y-out) ... simples!
Re: Fun : going Home ?
« Reply #4 on: December 15, 2005, 01:45:08 AM »
heh, you have 4 too many key words now Kerry...... I s'pose you could set the 5th as the default  :laugh:
"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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Fun : going Home ?
« Reply #5 on: December 15, 2005, 01:50:57 AM »
They should all be default YES , heh.

It's Difficult using a keyword list like this though, there are no PromptKeywordOptions as far as I can tell ; so no default CAN be set.
 
Options are :
Quote
GetKeywords
Autodesk.AutoCAD.EditorInput.PromptResult

GetKeywords(
   System.String message,
   System.String[] globalKeywords)
or
Quote
GetKeywords
Autodesk.AutoCAD.EditorInput.PromptResult

GetKeywords(
   Autodesk.AutoCAD.EditorInput.PromptKeywordOptions 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.

MickD

  • King Gator
  • Posts: 3665
  • (x-in)->[process]->(y-out) ... simples!
Re: Fun : going Home ?
« Reply #6 on: December 15, 2005, 01:59:25 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.
"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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Fun : going Home ?
« Reply #7 on: December 15, 2005, 02:07:03 AM »
I've done a little with that.

Have a look at Lab 02 Reworked  http://www.theswamp.org/forum/index.php?topic=7904.msg100396#msg100396

There's a couple of getxxx options there.

Code: [Select]
.....
case PromptStatus.Cancel:
...
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 #8 on: December 15, 2005, 02:29:19 AM »
While discussing Keywords ...
If ANYONE knows of a way to add Keywords from a list,
rather than one at a time in the PromptKeywordOptions Class,
I'd be happy to hear about it  :lol:

I've tried a few variations, but gave up.


eg: There must me a better way than this  .. I'd enjoy being corrected.
Code: [Select]
            PromptKeywordOptions keywordOptions = new PromptKeywordOptions(message);
            keywordOptions.Keywords.Add("Yes");
            keywordOptions.Keywords.Add("No");
            keywordOptions.Keywords.Add("Perhaps");
            keywordOptions.Keywords.Add("Absolutely");
            keywordOptions.Keywords.Add("Never");
            keywordOptions.Keywords.Add("Sometimes");
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 #9 on: December 15, 2005, 02:41:09 AM »
.. cont ..

Seems to not compile if the Options are :-
string[] options = { "Yes", "No", "Perhaps", "noSir" , "BloodyOathMate" };

and spit the dummy if a normal string ..  - --> System.ArgumentException: No bracketed keyword list

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 #10 on: December 15, 2005, 02:47:09 AM »
I just had another try ...
The answer may be in the Exception Message.

I wonder what this PromptOptions.SetMessageAndKeywords(String messageAndKeywords, String globalKeywords) is ? ?
Time to look at the Object Browser .. < tomorrow>

Quote
************** Exception Text **************
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: No bracketed keyword list
   at Autodesk.AutoCAD.EditorInput.PromptParser.Parse(String promptAndKeywords, String globalKeywords)
   at Autodesk.AutoCAD.EditorInput.PromptOptions.SetMessageAndKeywords(String messageAndKeywords, String globalKeywords)
   at Autodesk.AutoCAD.EditorInput.PromptKeywordOptions..ctor(String messageAndKeywords, String globalKeywords)
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: 3665
  • (x-in)->[process]->(y-out) ... simples!
Re: Fun : going Home ?
« Reply #11 on: December 15, 2005, 03:20:27 AM »
How about a 'for' loop

Just a sketch

for(int i = 0; i <= options.Length; i++)
{
      KeywordOptions.Keywords.Add(keywords;
}
"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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Fun : going Home ?
« Reply #12 on: December 15, 2005, 03:27:16 AM »
I'm sure something like that would work Mick.

I'd just particularly like to know why the overloaded PromptKeywordOptions constructor is failing.
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: 3665
  • (x-in)->[process]->(y-out) ... simples!
Re: Fun : going Home ?
« Reply #13 on: December 15, 2005, 04:36:40 AM »
I've never tried but if it expected an array wouldn't the constructor be -

(string messageAndKeywords, string [] globalKeywords)

??
"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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Fun : going Home ?
« Reply #14 on: December 15, 2005, 04:43:19 AM »
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. !
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.