Author Topic: Keywords  (Read 2849 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Keywords
« on: October 22, 2013, 02:52:18 AM »
AutoCAD 2009 SP3 x64 Enu
.Net 3.5 SP1

Hi. I need to get a selection, OR a keyword.

1. The keyword is  single and is used as default:

Quote
Command: dyn2stat
Add the dynamic block instances to the set or [Definitions] <Definitions>:

When I press the ENTER key, I do not get a my default keyword (as I have expected), but my command is completed. Why it happened?

2. If the keyword (or the ENTER key) was pressed, then I need to stop asking for selection. But selection is asking still after the keyword handling. How can I stop asking selection in the case when the keyword or the Enter was pressed?

Code - C#: [Select]
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Resources;
  6.  
  7. using cad = Autodesk.AutoCAD.ApplicationServices.Application;
  8. using App = Autodesk.AutoCAD.ApplicationServices;
  9. using Db = Autodesk.AutoCAD.DatabaseServices;
  10. using Ed = Autodesk.AutoCAD.EditorInput;
  11. using Rtm = Autodesk.AutoCAD.Runtime;
  12.  
  13. ...
  14.  
  15. App.Document doc = cad.DocumentManager.MdiActiveDocument;
  16. Ed.Editor ed = doc.Editor;
  17. Db.Database db = doc.Database;
  18. ResourceManager res = new ResourceManager(this.GetType());
  19.  
  20. Ed.PromptSelectionOptions pso = new Ed.PromptSelectionOptions();            
  21. pso.Keywords.Add(res.GetString("dialog_key"));
  22. pso.Keywords.Default = res.GetString("dialog_key");
  23. String keywords = pso.Keywords.GetDisplayString(false);
  24. pso.MessageForAdding = String.Format("{0} {1}", res.GetString("add_msg"), keywords);
  25. pso.MessageForRemoval = String.Format("{0} {1}", res.GetString("remove_msg"), keywords);
  26. pso.KeywordInput += pso_KeywordInput;
  27.  
  28. Db.TypedValue[] typedValues = new Db.TypedValue[] {
  29.     new Db.TypedValue((Int32)Db.DxfCode.Start, "INSERT")};
  30. Ed.SelectionFilter filter = new Ed.SelectionFilter(typedValues);
  31.  
  32. Ed.PromptSelectionResult result = ed.GetSelection(pso, filter);
  33.  
  34. ...
  35.  

Thank you.

n.yuan

  • Bull Frog
  • Posts: 348
Re: Keywords
« Reply #1 on: October 22, 2013, 12:04:16 PM »
In spite of the naming pattern of the PromptSelectionOptions class ("PromptxxxxOptions"), it is not derived from the same base class as all other "PromptxxxxOptions" class. You do not expect the same Keywords operation as other "PromptXXXXOptions" classes provide.

The sole purpose of this class, in conjunction with Editor.GetSelection() method, is for selecting entity, not for other type of input. It is either to be completed (hit Enter key) or to be cancelled (hit Esc key).  Its keywords are used for selecting something other than manually picked entities. You can see the code example coming with ObjectARX SDK for handling KeywordInput event of PromptSelectionOption class. YOu would notice the EventArgument in the event handler does not provide a way to cancel selecting process, rather the only action the event argument offers is to add entity to selectionset. This is the hint of the API designed gives: the keywords option in PromptSelectionOption is meant for selecting entities.

Basically, you cannot get out Editor.GetSelection() without hitting either Enter or ESC key. That means, you need to either use the combination of GetKeyword() and GetSelecction() to allow user to choose what he/she can go for next step (but once in the GetSelection(), hitting Enter or Esc is required anyway), or you can build your own selection method with GetEntity(), GetPoint(), and/or GetCorner()...these methods work with corresponding PromptxxxxOptions that provide keywords operation.
« Last Edit: October 22, 2013, 12:08:12 PM by n.yuan »

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Keywords
« Reply #2 on: October 22, 2013, 12:11:39 PM »
Thank you, I will change my code.

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Keywords
« Reply #3 on: October 23, 2013, 09:55:46 AM »
You can also check the PromptStatus returned.

result.Status == PromptStatus.Cancel = ESC
result.Status == PromptStatus.None = Enter
Revit 2019, AMEP 2019 64bit Win 10