Author Topic: Saving and Restoring Palette Location  (Read 299 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1443
Saving and Restoring Palette Location
« on: February 07, 2024, 08:04:52 PM »
I have managed to figure out how to make a tool palette based off of a very old PDF from 2007, but I want the tool palette to save the location, size, etc. and restore it. The old document is in vb .net, which I have converted to C# for most, but for some reason the saving and restoring of the position of the palette doesn't seem to be working, here is the code I have for this:

Code - C#: [Select]
  1. using System;
  2. using System.Drawing;
  3. using Autodesk.AutoCAD.DatabaseServices;
  4. using Autodesk.AutoCAD.EditorInput;
  5. using Autodesk.AutoCAD.Runtime;
  6. using Autodesk.AutoCAD.Windows;
  7. using Microsoft.VisualBasic.CompilerServices;
  8. using Autodesk.AutoCAD.Geometry;
  9. using Autodesk.AutoCAD.ApplicationServices;
  10. using System.Windows.Media.Imaging;
  11. using BDuct_Global;
  12.  
  13.  
  14. namespace BDuct
  15. {
  16.     public class Commands : IExtensionApplication
  17.     {
  18.        
  19.         [CommandMethod("BDUCT_INSERT_BLOCK")]
  20.         public void BDuct_Insert_Block()
  21.         {
  22.             string BlockName = GlobalVariables.Duct_Shape + "_";            
  23.             switch (GlobalVariables.SelectedButton.Name)
  24.             {
  25.                 case "Duct_Main":
  26.                     BlockName = BlockName + "DUCT";
  27.                 break;
  28.                 default:
  29.                     break;
  30.  
  31.             }
  32.             AutoCADFunctions.InsertBlock(BlockName);
  33.         }
  34.  
  35.         [CommandMethod("BDuct")]
  36.         public void BDuct()
  37.         {
  38.             if (GlobalVariables.ps == null)
  39.             {
  40.                 GlobalVariables.ps = new PaletteSet("BDuct", new Guid("{ECBFEC73-9FE4-4aa2-8E4B-3068E94A2BFA}"));
  41.                 GlobalVariables.ps.Style = PaletteSetStyles.ShowPropertiesMenu | PaletteSetStyles.ShowAutoHideButton | PaletteSetStyles.ShowCloseButton;
  42.  
  43.                 // ps.Icon = GetEmbeddedIcon("Example1.gold_1_32.ico")
  44.  
  45.                 GlobalVariables.ps.MinimumSize = new Size(412, 629);
  46.                 var myPalette = GlobalVariables.MainWindow;
  47.                 myPalette.TableLayoutPanel1.BackColor = Color.FromArgb(59, 68, 83);
  48.                 myPalette.GroupBox1.BackColor = Color.FromArgb(59, 68, 83);
  49.                 myPalette.BackColor = Color.FromArgb(59, 68, 83);
  50.                 myPalette.Panel10.BackColor = Color.FromArgb(59, 68, 83);
  51.                 GlobalVariables.ps.Add("BDuct", myPalette);
  52.                 GlobalVariables.ps.KeepFocus = false;
  53.                 GlobalVariables.ps.Visible = true;
  54.                
  55.             }
  56.             else if (GlobalVariables.ps.Visible == false)
  57.             {
  58.                 GlobalVariables.ps.Visible = true;
  59.             }
  60.         }
  61.  
  62.         public void Initialize()
  63.         {
  64.             // Throw New NotImplementedException()
  65.         }
  66.  
  67.         public void Terminate()
  68.         {
  69.             // Throw New NotImplementedException()
  70.         }
  71.         private static void ps_Load(object sender, PalettePersistEventArgs e)
  72.         {
  73.             // demo loading user data
  74.             double a = Conversions.ToDouble(e.ConfigurationSection.ReadProperty("BDuct", 22.3d));
  75.         }
  76.         private static void ps_Save(object sender, PalettePersistEventArgs e)
  77.         {
  78.             // demo saving user data
  79.             e.ConfigurationSection.WriteProperty("BDuct", 32.3d);
  80.         }
  81.  
  82.        
  83.     }
  84. }

I would appreciate it if anyone has any ideas on this.

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Re: Saving and Restoring Palette Location
« Reply #1 on: February 07, 2024, 09:02:04 PM »
In the past I have used the application's Properties.Settings to save and recall this info, or you could save it somewhere in your app when you fire it up but that won't persist unless you write it out to file.

hth :)
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8728
  • AKA Daniel
Re: Saving and Restoring Palette Location
« Reply #2 on: February 07, 2024, 09:06:44 PM »
Aren’t palettes persisted somewhere in the user profile, under the Guid?

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Re: Saving and Restoring Palette Location
« Reply #3 on: February 07, 2024, 09:11:04 PM »
there's even a spot to save this info :)

"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Saving and Restoring Palette Location
« Reply #4 on: February 08, 2024, 02:16:04 AM »
In the first releases of AutoCAD .NET the PalettSet class was sealed. Nowadays it is a better practice to create a class that derives from PaletteSet to define the appearance and controls contained in the palette set. You can have a look at this example.
As said upper, if you make changes to the paletteSet display, you should change the GUID also.
Speaking English as a French Frog