Author Topic: Combining a [Settings] Keyword with a .GetEntity call  (Read 1269 times)

0 Members and 1 Guest are viewing this topic.

ingenieur3d

  • Mosquito
  • Posts: 9
Combining a [Settings] Keyword with a .GetEntity call
« on: January 26, 2021, 10:01:05 AM »
Hi!

I am trying to make my command even better by allowing access to user settings, but once the Keyword is used and the settings are changed the code returns after the .GetEntity call. Is there any way to gracefully return to my initial .GetEntity block of code?

My prompt message would be "Select a line or a polyline or [Settings]: "

Any help appreciated!

Code - C#: [Select]
  1.     pEntOpts = new PromptEntityOptions(Environment.NewLine + "Select a line or a polyline or : ")
  2.     { AllowNone = true , AppendKeywordsToMessage = true };
  3.     pEntOpts.SetRejectMessage(Environment.NewLine + "Your selection must be a line or a polyline.");
  4.     pEntOpts.Keywords.Add("Settings");
  5.     ...
  6.     // Ask the user to .GetEntity.
  7.     pEntRes = acDoc.Editor.GetEntity(pEntOpts);
  8.  
  9.     if (pEntRes.Status == PromptStatus.Keyword)
  10.     {
  11.         // Change UserConfig
  12.         Interaction.UserConfig();
  13.  
  14.         // What should I do here to make my code reinitiate???
  15.                
  16.     }
  17.     else if (pEntRes.Status != PromptStatus.OK)
  18.     {
  19.         // User leaves instead...
  20.         return;
  21.     }
  22.  


Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Combining a [Settings] Keyword with a .GetEntity call
« Reply #1 on: January 26, 2021, 12:17:04 PM »
Here is one way:
Code - C#: [Select]
  1.             pEntRes = acDoc.Editor.GetEntity(pEntOpts);
  2.             do
  3.             {
  4.                 // Change UserConfig
  5.                 Interaction.UserConfig();
  6.             } while (pEntRes.Status == PromptStatus.Keyword);
  7.  
  8.             if (pEntRes.Status != PromptStatus.OK)
  9.             {
  10.                 // User leaves instead...
  11.                 return;
  12.             }
  13.  
  14.  

ingenieur3d

  • Mosquito
  • Posts: 9
Re: Combining a [Settings] Keyword with a .GetEntity call
« Reply #2 on: January 26, 2021, 01:52:00 PM »
Ah, thanks a lot! Less than one month of C# practice got me here.

The if(pEntRes.Status == PromptStatus.Keyword) is still needed of course, and the do goes on top.
(no need to check for the .StringResult as I have only one Keyword.)


Code - C#: [Select]
  1.     do
  2.     {
  3.         // Define the .GetEntity request.
  4.         pEntOpts = new PromptEntityOptions(Environment.NewLine + "Select a line or a polyline or : ")
  5.         { AllowObjectOnLockedLayer = true, AllowNone = true, AppendKeywordsToMessage = true };
  6.         pEntOpts.SetRejectMessage(Environment.NewLine + "Your selection must be a line or a polyline.");
  7.         pEntOpts.Keywords.Add("Settings");
  8.         ...
  9.  
  10.         // Ask the user to .GetEntity.
  11.         pEntRes = acDoc.Editor.GetEntity(pEntOpts);
  12.  
  13.         if (pEntRes.Status == PromptStatus.Keyword)
  14.         {
  15.             // Change UserConfig
  16.             Interaction.UserConfig();
  17.         }
  18.     } while (pEntRes.Status == PromptStatus.Keyword);
  19.  
« Last Edit: January 27, 2021, 02:49:34 AM by ingenieur3d »