TheSwamp

Code Red => .NET => Topic started by: GUIDO ROOMS on June 16, 2012, 04:38:06 AM

Title: PromptStringOptions and Keywords
Post by: GUIDO ROOMS on June 16, 2012, 04:38:06 AM
Hi,

When I look up PromptStringOptions in the ObjectArx documentation, the only properties(methods) that are shown are AllowSpaces, DefaultValue and UseDefaultValue. Properties and methods having to do with keywords are not shown.

This seems reasonable, since Editor.GetString does not work with keywords (this is not mentioned in the help file, however).

When I look up PromptStringOptions in the VS Object Browser, it also shows methods and properties for manipulating keywords.

My question: why aren't these (inherited) methods and properties hidden/removed  in class PromptStringOptions?
Where can I find out which inherited fields can/cannot be used in a given class?

Hoping this is not too dumb a question...
Title: Re: PromptStringOptions and Keywords
Post by: Kerry on June 16, 2012, 05:25:17 AM

Quote
My question: why aren't these (inherited) methods and properties hidden/removed  in class PromptStringOptions?
The nature  and advantage of inheritance and using base class is that method definitions don't need to be duplicated ... If they're defined in the base class then they are usable from the child class.

Quote
Where can I find out which inherited fields can/cannot be used in a given class?

I'm not aware of any documentation that covers the full inheritance tree.
Viewing the class and each of it's base classes if how I investigate what is available.

see <Drive>:\ObjectARX 2013\samples\dotNet\Prompts.cs for some samples of prompts.
I'm sure the topic has been discussed here a few times .

Regards
kdub
Title: Re: PromptStringOptions and Keywords
Post by: fixo on June 16, 2012, 06:55:10 AM
Just compare both methods and see the difference:
Code: [Select]
        [CommandMethod("prs")]
        public static void testPrompts()
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            PromptStringOptions pso = new PromptStringOptions("\nEnter a string or choose from list [Alpha/Bravo/Charlie/Delta]: ");
            pso.DefaultValue = "Alpha";
            pso.UseDefaultValue = true;
            pso.AppendKeywordsToMessage = true;
            PromptResult pr = ed.GetString(pso);
            ed.WriteMessage("\nChoosen: {0}",pr.StringResult);

            PromptKeywordOptions pko = new PromptKeywordOptions("\nEnter a string or choose from list [Alpha/Bravo/Charlie/Delta]: ",
                "Alpha Bravo Charlie Delta");
            pko.Keywords.Default = "Alpha";
            PromptResult res = ed.GetKeywords(pko);
            ed.WriteMessage("\nChoosen: {0}",res.StringResult);


        }
Title: Re: PromptStringOptions and Keywords
Post by: GUIDO ROOMS on June 16, 2012, 10:38:05 AM
Thanks for the replies.
Title: Re: PromptStringOptions and Keywords
Post by: BlackBox on June 16, 2012, 12:41:18 PM
FWIW - I ran into this recently:

Just as an update, I've taken Jeff's code (thanks again!) and slightly revised the CommandMethod to suite our use, and I am posting it here in the event that others may be interested.

In short, I revised the Prompt*Options to allow me to incorporate a Keyword (our company name), which allows the user to simply Enter, rather than manually typing out the company name each-and-every-time a change is made.

Also, a special thanks to Hallex (aka Oleg), for his suggestion of using *.Keywords.AllowArbitraryInput = true; as a work around to allowing 'string' input, and Keyword options in this post (http://forums.autodesk.com/t5/NET/GetString-with-Keywords-FATAL-ERROR/td-p/3373735).

Here's the code, note the 'companyName' variable at the top of the Class... Simply change this value to your company name and recompile:

Code - C#: [Select]
  1.         [CommandMethod("StylesCreatedBy")]
  2.         public static void StylesCreatedBy()
  3.         {
  4.             //
  5.             // Company name as string, to be used as default prompt option
  6.             //
  7.             String companyName = "SomeCompany"; //<-- Your company name goes here
  8.             //
  9.             Document acDoc = Application.DocumentManager.MdiActiveDocument;
  10.             CivilDocument civDoc = CivilApplication.ActiveDocument;
  11.  
  12.             PromptKeywordOptions myOpts = new PromptKeywordOptions("");
  13.             myOpts.Message = "\nEnter new value for 'Created By' in all styles or: ";
  14.  
  15.             // Define the valid keywords, specify default as 'companyName',
  16.             // and allow arbitrary input (spaces not accepted)
  17.             myOpts.Keywords.Add(companyName);
  18.             myOpts.Keywords.Default = companyName;
  19.             myOpts.AllowArbitraryInput = true;
  20.            
  21.             PromptResult myRes = acDoc.Editor.GetKeywords(myOpts);
  22.  
  23.             if (myRes.Status != PromptStatus.OK)
  24.                 return;
  25.             using (tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
  26.             {
  27.                 creator = myRes.StringResult;
  28.                 ListRoot(civDoc.Styles);
  29.                 tr.Commit();
  30.             }
  31.         }
  32.  

Cheers! :beer:

** Edit - Separately, I'd just like to point out how disappointed I am that .NET does not have an equivalent for:

Code: [Select]
_$ (setq var (getstring T "\nEnter a string or [Small/Medium/Large] <Large>: "))
"Something Else"
_$

... The idea of disallowing Keyword entry with GetString() Method is idiotic.

/vent