Author Topic: Trouble with Palettes ...  (Read 10143 times)

0 Members and 1 Guest are viewing this topic.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Trouble with Palettes ...
« Reply #15 on: August 14, 2018, 09:22:05 PM »
I've been investigating a way to remove a palette from a PaletteSet but there doesn't appear to be any exposed methods.

I've tried a couple of different approaches and hit dead ends.


Attempt 1:
Subclass Palette and create a Dispose method
Unfortunately, Palette is marked as NotInheritable

Attempt 2:
Pass the handle of the Palette to DestroyWindow
Spy++ shows that the handle was disposed, but the PaletteSet still shows the palette as existing
Selecting the destroyed palette causes a fatal error

Attempt 3:
Pass WM_CLOSE to the palette I want to close
Palette disappears from Spy++ but is still on the screen
Selecting the palette causes a fatal error


I'm open for suggestions ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

n.yuan

  • Bull Frog
  • Posts: 348
Re: Trouble with Palettes ...
« Reply #16 on: August 15, 2018, 10:02:58 AM »
Yes, one should ALWAYS subclass PaletteSet, just as we do with System.Windows.Forms.Form: we always derive our form from Form, as long as you use AutoCAD 2009 or later (prior to Acad2009, PaletteSet is a sealed class, which cannot be subclassed). I saw your post earlier in Autodesk's .NET forum, referring to an old AU class material, which gave pretty good sample code of PaletteSet. But since it was for pre Acad2009, thus did not subclass PaletteSet, thus should be considered very out-of-date.

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Trouble with Palettes ...
« Reply #17 on: August 15, 2018, 10:37:38 AM »
In a paletteset you can activate a palette only by index ... if you don't know what that is (you can't really know that if your paletteset is created dynamically) then the best option is to activate the palette by name. I can do that now.

A PaletteSet is an IEnumerable, you can get a Palette by Name.
Code - C#: [Select]
  1. paletteSet.Cast<Palette>.FirstOrDefault(p => p.Name == "My Palette")
« Last Edit: August 15, 2018, 10:43:36 AM by MexicanCustard »
Revit 2019, AMEP 2019 64bit Win 10

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Trouble with Palettes ...
« Reply #18 on: August 15, 2018, 12:34:51 PM »
In a paletteset you can activate a palette only by index ... if you don't know what that is (you can't really know that if your paletteset is created dynamically) then the best option is to activate the palette by name. I can do that now.

A PaletteSet is an IEnumerable, you can get a Palette by Name.
Code - C#: [Select]
  1. paletteSet.Cast<Palette>.FirstOrDefault(p => p.Name == "My Palette")

... and that is going into my toolbox

and for whatever reason, I completely missed PaletteSet.Remove(n) ..

So I can remove transient palettes as needed ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Trouble with Palettes ...
« Reply #19 on: August 16, 2018, 12:08:20 PM »
I've run into another issue and it may require reassessment of assigning transient palettes to a PaletteSet, or perhaps a workaround to prevent the problem.

Because the app is pretty large, the tools, options and various other items are located on different palettes. Depending upon which area of the program they are utilizing at the moment, the set of palettes displayed and accessible at any given time may vary, as will the number of palettes in any given paletteset, which leads me to the problem.

Scenario:
User opens app for the first time and a standard paletteset is displayed with 4 palettes.
The user clicks a button or ribbon or changes a combobox value that displays a transient palette. However it is we got there a new transient palette is added to the paletteset (created only when needed and disposed after it loses focus)
Without closing the paletteset and without navigating away from the transient palette, the user closes AutoCAD.
The next time the user tries to open AutoCAD it crashes.

Cause:
When using a GUID to identify a paletteset (and thus allow AutoCAD to remember the last settings) upon restarting AutoCAD, an attempt is made to activate the now non-existant palette. Error handling does not catch the error.

Recovery Fix:
One of the following:
Find the user profile in %userprofile%\AppData\Roaming\Autodesk\ .... and edit the XML to either remove the paletteset or change the active palette value to an index that exists i.e. 0
OR
Delete the user profile

I've tried catching the Finalize event for the paletteset and forcing the active palette value to 0 but apparently the settings are saved before palette is disposed so ...

Aside from not having transient palettes anyone have a good idea to solve this issue? Surely I can't be the only person who has had this issue before.

Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Atook

  • Swamp Rat
  • Posts: 1029
  • AKA Tim
Re: Trouble with Palettes ...
« Reply #20 on: August 16, 2018, 01:40:10 PM »
Keith, I have to say, my first thought was, if it's transient, maybe it should be a form.

Then I looked at my own code, and I have a transient-ish palette (brought up via command from another palette). It lives in it's own paletteset as it's larger than the other palettes I show, and is meant to go away when the user is done with it. Not sure if I have the same issue as you, but haven't run into it yet.

Can you create the palette, and set the control.visible property to false instead of disposing it? (and disable the logic in it based on it's visibility)

Another option might be tapping into the App.BeginQuit() event, and closing your transient palette there.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Trouble with Palettes ...
« Reply #21 on: August 16, 2018, 04:30:03 PM »
Like I said, I am beginning to rethink it ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Trouble with Palettes ...
« Reply #22 on: August 17, 2018, 07:22:30 AM »
Keith, I have to say, my first thought was, if it's transient, maybe it should be a form.

Agreed. Palettes are best for static use. Letting the user show and hide them as needed.  If I had nested windows I wouldn't try and put them in a palette.  Can the transient data just be shown/hidden in the parent control?  I have some palettes where depending on the users choices additional data is shown on the same control.
Revit 2019, AMEP 2019 64bit Win 10

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Trouble with Palettes ...
« Reply #23 on: August 17, 2018, 07:23:40 AM »
Or can you just swap out the control on the same palette and let the user navigate back and forth?
Revit 2019, AMEP 2019 64bit Win 10

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Trouble with Palettes ...
« Reply #24 on: August 17, 2018, 07:58:11 AM »
For now I'm going to leave the palette and reconfigure one other. I'll eventually work it out, it's just not today.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Trouble with Palettes ...
« Reply #25 on: August 17, 2018, 08:03:01 AM »
I still have some sizing issues though. The tabs don't show the first time it's called until, a)the palette is rolled up and expanded or b) the palette is resized larger that the minimum size.

And the palette does not adhere to minimum size when docked. It can be resized smaller than the minimum size.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Trouble with Palettes ...
« Reply #26 on: August 17, 2018, 11:03:42 AM »
Is it possible to utilize the same type control for displaying/editing data as AutoCAD uses for their palettes? I am thinking the one like on the Modify palette with various minimizable/maximizable sections that list the editable values and have controls for changing said values.

Spy++ lists it as a subclassed ListView and I see there is an ExListView control listed, but so far I have been unable to instantiate it.


*edited to correct class name
« Last Edit: August 17, 2018, 11:15:51 AM by Keith™ »
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Trouble with Palettes ...
« Reply #27 on: August 21, 2018, 07:49:05 AM »
I still have some sizing issues though. The tabs don't show the first time it's called until, a)the palette is rolled up and expanded or b) the palette is resized larger that the minimum size.

And the palette does not adhere to minimum size when docked. It can be resized smaller than the minimum size.

This is why I wrap the WPF Control inside an ElementHost.
Revit 2019, AMEP 2019 64bit Win 10

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Trouble with Palettes ...
« Reply #28 on: August 21, 2018, 08:15:17 AM »
Care to share an example?
With this method can I use an existing control and just wrap the control in my subclass pallet set?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Trouble with Palettes ...
« Reply #29 on: August 21, 2018, 10:43:45 AM »
Check out my first post in this thread.
Revit 2019, AMEP 2019 64bit Win 10