Author Topic: Q for Properties.Settings.Default  (Read 3843 times)

0 Members and 1 Guest are viewing this topic.

pBe

  • Bull Frog
  • Posts: 402
Q for Properties.Settings.Default
« on: July 04, 2017, 09:38:07 AM »
I have a question about Settings Default. I used basically the same coding for two codes,. one for Autocad and one for desktop . The default settings on the Desktop version turns out OK but the version in Autocad behaves differently. The default value only applies when you close Autocad session and up again. Whilst the desktop version the default value applies instantly.

Please see attached files. It includes only the Autocad version.

Thanks in advance
pBe
« Last Edit: July 04, 2017, 11:18:21 PM by pBe »

Atook

  • Swamp Rat
  • Posts: 1027
  • AKA Tim
Re: Q for Properties.Settings.Default
« Reply #1 on: July 04, 2017, 03:34:04 PM »
Not sure I understand the question, maybe you can post some code?

n.yuan

  • Bull Frog
  • Posts: 348
Re: Q for Properties.Settings.Default
« Reply #2 on: July 04, 2017, 05:02:10 PM »
If you are talking about Properties.Settings.Default (in C#), which you added in the Settings of the project's properties window, then, yes, it behaves differently in EXE (desktop app) and in DLL.

The default values of settings you created in the project are embedded in the application (EXE or DLL) as resource data, and then

1. In EXE app, the settings eventually does into YourApp.exe.config, where you can manually change the settings values in *.exe.config file any time, and the EXE app will read the setting data from *.exe.config file, instead of using the embedded default value;

2. in DLL app, the DLL building/compiling will create a YourApp.DLL.Config file and save the settings (with default valuer in it). HOWEVER, the application that uses the DLL (AutoCAD, in this case) DOES not automatically go to this *.dll.config to load settings. Theoretically, after compiling the DLL, you are supposed to merge the settings in the *.dll.config into EXE app's aa.exe.config (in this case, acad.exe.config), and the *.dll.config file is not needed to be deployed with your app; Or you need to write code to explicitly let your DLL to load settings from the *.dll.config file. In your case, since you did not merge the settings in *.dll.config into acad.exe.config, nor you have code to specifically load the settings from *.dll.config, thus the DLL code will ALWAYS use the default values you entered in design stage, which is embedded with the DLL project.

pBe

  • Bull Frog
  • Posts: 402
Re: Q for Properties.Settings.Default
« Reply #3 on: July 04, 2017, 11:52:25 PM »
. maybe you can post some code?

I did post a code as an attachment. [ downloaded 0 times ] I will re-save and re-attach the source code.


The default values of settings you created in the project are embedded in the application (EXE or DLL) as resource data, and then

1. In EXE app, the settings eventually does.......
2. in DLL app, the DLL building/compiling will ......

That makes a lot of sense. I will write a code to let DLL load settings from  file config file.

Thank you n.yuan

pBe


pBe

  • Bull Frog
  • Posts: 402
Re: Q for Properties.Settings.Default
« Reply #5 on: July 05, 2017, 11:40:39 AM »
There are quite some discussions online you can find on this topic. Here are some of them:
.....
HTH

Thank for those little gems Norman.

I'm going to take a crack at this using Autocad system variable "USERS#" for now. Since I only needed to do that on the current opened drawing. I'll Let you know how it goes.

Code - C#: [Select]
  1.  
  2. string Curpath = AcAp.GetSystemVariable("USERS3").ToString();
  3. .... pass to form
  4. ThisForm dialog = new ThisForm(DSTFile, Curpath);
  5.  
  6. AcAp.SetSystemVariable("USERS3", product of doing something);
  7.  
  8.  

pBe

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Speaking English as a French Frog

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: Q for Properties.Settings.Default
« Reply #7 on: July 05, 2017, 12:09:37 PM »
Hi pBe,

Another suggestion is to use Dictionary which you can save more strings than system variables USERS*


gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Q for Properties.Settings.Default
« Reply #8 on: July 05, 2017, 12:41:52 PM »
As USERS1-5 sysvars are not saved, the simplest (and safest) equivalent would be using an instance field in the command class and passing it to an overloaded constructor of the form.

In TheForm class
Code - C#: [Select]
  1.         // constructor overload
  2.         public TheForm(string value)
  3.         {
  4.             InitializeComponent();
  5.  
  6.             switch (value)
  7.             {
  8.                 case "A.1":
  9.                     MFC_format.Checked = true; break;
  10.                 case "A.2":
  11.                     MF_format.Checked = true; break;
  12.                 case "A.3":
  13.                     MC_format.Checked = true; break;
  14.                 case "A.4":
  15.                     M_format.Checked = true; break;
  16.             }
  17.         }
  18.  
  19.         // public property
  20.         public string Format =>
  21.             TypeFF.Controls.OfType<RadioButton>().FirstOrDefault(r => r.Checked).Text;


In MyCommands class
Code - C#: [Select]
  1.         string format = "A.1"; // initial default value
  2.  
  3.         [CommandMethod("TestforCombobox")]
  4.         public void ShowForm2() // instance method (non static)
  5.         {
  6.             Document doc = AcAp.DocumentManager.MdiActiveDocument;
  7.             Editor ed = AcAp.DocumentManager.MdiActiveDocument.Editor;
  8.             Database db = doc.Database;
  9.  
  10.             Dictionary<string, int> data = new Dictionary<string, int>() {{ "TAG1", 0 }, { "TAG2", 2 }};
  11.  
  12.             using (TheForm dialog = new TheForm(format)) // pass the current format value to the form
  13.             {
  14.                 DialogResult MyTestForAttributes = AcAp.ShowModalDialog(dialog);
  15.                 if (MyTestForAttributes == DialogResult.OK)
  16.                 {
  17.                     format = dialog.Format; // update the format value from the form
  18.                     MessageBox.Show("OK");
  19.                 }
  20.             } // Using TheForm
  21.         }
Speaking English as a French Frog

pBe

  • Bull Frog
  • Posts: 402
Re: Q for Properties.Settings.Default
« Reply #9 on: July 05, 2017, 12:48:56 PM »
About storing per document data, you can see these threads:...

Thank you Gile. Surely i will make time to read this. I will give this a go.

Another suggestion is to use Dictionary which you can save more strings than system variables USERS*

Hello there Tharwat,

Although I only need the value during the current session, it would be nice to retrieve value when i open the file again and I realized just now that USERS# are not saved when you close the drawing session.

Does declaring  a Dictionary public make it available even after I close  Autocad much like the way Properties.Settings.Default works on desktop app wherein the only time it reverts to it default value at design stage is when i restart the PC?

Oops, did not see you post there Gile.

As USERS1-5 sysvars are not saved, the simplest (and safest) equivalent would be using an instance field in the command class and passing it to an overloaded constructor of the form.

In TheForm class
Code - C#: [Select]
  1.         // constructor overload
  2. ........
  3.         // public property
  4.         public string Format =>
  5.             TypeFF.Controls.OfType<RadioButton>().FirstOrDefault(r => r.Checked).Text;


In MyCommands class
Code - C#: [Select]
  1.         string format = "A.1"; // initial default value
  2. ......
  3.         }


I will try this in a few.

GREAT job Gile, It works. *thumbsup*

Thanks
« Last Edit: July 05, 2017, 01:40:02 PM by pBe »