Author Topic: Need help with a window command in C#  (Read 1944 times)

0 Members and 1 Guest are viewing this topic.

Nomad

  • Mosquito
  • Posts: 4
Need help with a window command in C#
« on: July 06, 2022, 01:41:24 PM »
I have created a plugin written in C# that runs in Autocad. The plugin opens a window and allows the user to select several options to restore default settings for the sheet. When I run a command that requires additional user input beyond the button on the window, a blank white box pops up called "Hidden Window" and disappears after the command runs. How do I stop this from happening. Any help would be greatly appreciated.

This is the initialization command for the window.

Code - C#: [Select]
  1. public class Initialize
  2.     {
  3.         [CommandMethod("Defaults")]
  4.  
  5.         public static void window()
  6.         {
  7.             GUI window = new GUI();  //initializes window
  8.             window.ShowDialog();
  9.            
  10.         }  
  11.     }
 

This is the command for the additional user input.

Code - C#: [Select]
  1. public static void UpdateLayer()
  2.         {
  3.             Document acDoc = Application.DocumentManager.MdiActiveDocument;  //AutoCAD document name in program space
  4.             Database acCurDb = acDoc.Database;  //AutoCAD database name in program space
  5.             Editor ed = acDoc.Editor;  //AutoCAD document editor
  6.  
  7.             PromptDistanceOptions prompt = new PromptDistanceOptions("");
  8.             prompt.Message = "\nWould you like to add missing layers?";
  9.             prompt.Keywords.Add("Yes");
  10.             prompt.Keywords.Add("No");
  11.             PromptDoubleResult result = acDoc.Editor.GetDistance(prompt);
  12.  
  13.             //Updates the missing engineering layers in the autocad drawing
  14.             if (result.StringResult == "Yes")
  15.             {
  16.                 Globals.NoCreate(1);
  17.             }
  18.             //runs the first command so the description can correctly update
  19.             else if (result.StringResult == "No")
  20.             {
  21.                 Globals.NoCreate(0);
  22.             }
  23.  
  24.             EngineeringLayersDatabase.UpdateLayer();
  25.         }



edit kdub: added code=csharp
« Last Edit: July 06, 2022, 05:47:59 PM by kdub »

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2124
  • class keyThumper<T>:ILazy<T>
Re: Need help with a window command in C#
« Reply #1 on: July 07, 2022, 08:55:09 PM »
Hi Nomad

I can't visualise the issue you have.

I'm wondering why you are using the Editor.GetDistance() method ??

Perhaps Editor.GetKeyword() would be more suitable.
 . . or code a YesNo MessageBox for yourself

Something like : https://www.c-sharpcorner.com/UploadFile/mahesh/understanding-message-box-in-windows-forms-using-C-Sharp/
or :
https://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-6C52F8BC-B107-4EE4-BA25-5B74900B271A
https://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-F432E285-8B94-4ACD-A186-89E1218DEC07
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: Need help with a window command in C#
« Reply #2 on: July 08, 2022, 08:08:40 AM »
Hi,

Did you try using Application.ShowModalDialog?
AutoCAD keeps a reference to the window as to hook into its events

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2124
  • class keyThumper<T>:ILazy<T>
Re: Need help with a window command in C#
« Reply #3 on: July 08, 2022, 09:48:18 PM »
Hi,

Did you try using Application.ShowModalDialog?
AutoCAD keeps a reference to the window as to hook into its events

Hi Daniel,
I s'pose it also depends if the Button_Click event closes the Form prior to calling UpdateLayer()
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.