woolsock Posted June 9, 2015 Posted June 9, 2015 Hi folks My target was to do a little routine that creates layouts for the views and sets page setups for these layouts. Name of the page setup is asked from the user before making the layouts and I try to use PromptKeywordOptions so that user can only select existing page setups. And here comes the problem. If there is underscore (_) or more in the page setup's name and I type that name, I get error "Invalid option keyword." in the command line. When I messed with page setup manager and tried to rename setups with special characters, I got the following message: "The following characters are not supported: \ / ? " : ; * | , = `". but there are no mention about the underscore. How do I select the name with underscore or do I have to replace all underscores from my page setup names? Here is the routine for selecting page setup: using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using System; using System.Collections.Generic; namespace CAD { public class PageSetupSelector { Document doc; [CommandMethod("SelectPageSetup")] public void SelectPageSetup() { doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; using (Transaction trans = db.TransactionManager.StartTransaction()) { DBDictionary pageSetups = (DBDictionary)trans.GetObject(db.PlotSettingsDictionaryId, OpenMode.ForRead); List<string> setupNames = new List<string>(); doc.Editor.WriteMessage("\nPage setups:"); foreach (DBDictionaryEntry entry in pageSetups) { doc.Editor.WriteMessage("\n {0}", entry.Key); setupNames.Add(entry.Key); } if (pageSetups.Count > 0) { string question = "\nSelect pagesetup: "; string answer = AskKeywordFromUser(question, setupNames.ToArray(), setupNames[0]); doc.Editor.WriteMessage("\nSelected setup: {0} ", answer); } trans.Abort(); } } protected string AskKeywordFromUser(string question, string[] words, string defaultWord) { PromptKeywordOptions pko = new PromptKeywordOptions(""); pko.Message = question; pko.AllowNone = false; foreach (string word in words) { pko.Keywords.Add(word); } pko.Keywords.Default = defaultWord; PromptResult pr = doc.Editor.GetKeywords(pko); if (pr.Status != PromptStatus.OK) { return String.Empty; } return pr.StringResult; } } } And here is the output from the command line: Page setups: test-A3 test_A3 Select pagesetup [test-A3/test_A3] <test-A3>: test_A3 Invalid option keyword. Select pagesetup [test-A3/test_A3] <test-A3>: "test_A3" Invalid option keyword. Select pagesetup [test-A3/test_A3] <test-A3>: 'test_A3' Invalid option keyword. Select pagesetup [test-A3/test_A3] <test-A3>: Selected setup: test-A3 Quote
woolsock Posted June 10, 2015 Author Posted June 10, 2015 I found the solution from other site http://forums.autodesk.com/t5/net/getstring-with-keywords-fatal-error/td-p/3373735 Solution was to set PromptKeywordOptions.AllowArbitraryInput to true. protected string AskKeywordFromUser(string question, string[] words, string defaultWord) { PromptKeywordOptions pko = new PromptKeywordOptions(""); pko.Message = question; pko.AllowNone = false; foreach (string word in words) { pko.Keywords.Add(word); } pko.Keywords.Default = defaultWord; [color=red]pko.AllowArbitraryInput = true;[/color] PromptResult pr = doc.Editor.GetKeywords(pko); if (pr.Status != PromptStatus.OK) { return String.Empty; } return pr.StringResult; } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.