Hi
How can I hide Palette when no Drawings are open and show Paletta again when Drawings are open
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Solved by Keith.Brown. Go to Solution.
Below is a link to a EnhancedPaletteSet class that I wrote that Gile perfected that is inherited from PaletteSet and will do this for you automatically. Instead of creating a PaletteSet, create an EnhancedPaletteSet (or whatever you name it) and it will automatically close when there are no documents open and reappear when you open a document.
https://www.theswamp.org/index.php?topic=46316.msg550104#msg550104
Hi,
You can use instances of AutoHidePaletteSet instead of PaletteSet.
using Autodesk.AutoCAD.ApplicationServices; using System; namespace Autodesk.AutoCAD.Windows { public class AutoHidePaletteSet : PaletteSet { bool wasVisible; public AutoHidePaletteSet(string name) : this(name, name, Guid.NewGuid()) { } public AutoHidePaletteSet(string name, Guid toolID) : this(name, name, toolID) { } public AutoHidePaletteSet(string name, string cmd, Guid toolID) : base(name, cmd, toolID) { var docs = Application.DocumentManager; docs.DocumentActivated += (s, e) => this.Visible = e.Document == null ? false : wasVisible; docs.DocumentCreated += (s, e) => this.Visible = wasVisible; docs.DocumentToBeDeactivated += (s, e) => wasVisible = this.Visible; docs.DocumentToBeDestroyed += (s, e) => { wasVisible = this.Visible; if (docs.Count == 1) this.Visible = false; }; } } }
@Keith.Brown was faster...
@_gile wrote:Hi,
You can use instances of AutoHidePaletteSet instead of PaletteSet.
using Autodesk.AutoCAD.ApplicationServices; using System; namespace Autodesk.AutoCAD.Windows { public class AutoHidePaletteSet : PaletteSet { bool wasVisible; public AutoHidePaletteSet(string name) : this(name, name, Guid.NewGuid()) { } public AutoHidePaletteSet(string name, Guid toolID) : this(name, name, toolID) { } public AutoHidePaletteSet(string name, string cmd, Guid toolID) : base(name, cmd, toolID) { var docs = Application.DocumentManager; docs.DocumentActivated += (s, e) => this.Visible = e.Document == null ? false : wasVisible; docs.DocumentCreated += (s, e) => this.Visible = wasVisible; docs.DocumentToBeDeactivated += (s, e) => wasVisible = this.Visible; docs.DocumentToBeDestroyed += (s, e) => { wasVisible = this.Visible; if (docs.Count == 1) this.Visible = false; }; } } }
@Keith.Brown was faster...
Hi @_gile, you might want to take a look at the docs for Guid.NewGuid().
With that in your code, a new entry with a different GUID will be created in Profile.aws every time an instance of your AutoHidePaletteSet class is created, and those entries will never be used, because NewGuid() generates a new, unique GUID every time its called.
The GUID passed to the PaletteSet's constructor has to be the same GUID every time its called, or there is no point to passing a GUID, other than to flood Profile.aws with a massive number of 'garbage' entries. If you don't want AutoCAD to persist the PaletteSet in Profile.aws, you have to call the constructor that doesn't take a GUID.
Once again, thank you very much for your wise advice.
According to @ActivistInvestor advice, here's a new impementation passing the buck to the base class.
using Autodesk.AutoCAD.ApplicationServices; using System; namespace Autodesk.AutoCAD.Windows { public class AutoHidePaletteSet : PaletteSet { private bool wasVisible; public AutoHidePaletteSet(string name) : base(name) { Initialize(); } public AutoHidePaletteSet(string name, Guid toolID) : base(name, toolID) { Initialize(); } public AutoHidePaletteSet(string name, string cmd, Guid toolID) : base(name, cmd, toolID) { Initialize(); } void Initialize() { var docs = Application.DocumentManager; docs.DocumentActivated += (s, e) => this.Visible = e.Document == null ? false : wasVisible; docs.DocumentCreated += (s, e) => this.Visible = wasVisible; docs.DocumentToBeDeactivated += (s, e) => wasVisible = this.Visible; docs.DocumentToBeDestroyed += (s, e) => { wasVisible = this.Visible; if (docs.Count == 1) this.Visible = false; }; } } }
@_gile wrote:According to @ActivistInvestor advice, here's a new impementation passing the buck to the base class.
Great. You might also want to add a handler for Application.QuitWillStart, along with a private field telling you that the PalletSet was hidden because there's no open documents. Why: if the user has the PaletteSet visible and then closes all open documents, and then quits AutoCAD, the PalletSet should be automatically shown the next time AutoCAD is started.
Here's the handler from my own implementation. The hiddenInZeroDocState field is true only if the PaletteSet is hidden because there are no open documents:
/// <summary> /// If the PaletteSet's VisibleInZeroDocState property is /// false, show the PaletteSet so that AutoCAD remembers /// that it was visible when it closed. Without doing this, /// if the user quits AutoCAD while no documents are open /// the PaletteSet will not be automatically shown on the /// next restart. /// </summary> void quitWillStart(object sender, EventArgs e) { if(!this.Visible && hiddenInZeroDocState) this.Visible = true; }
Hi
I tray to convert this sample into VB.NET see Attachments
when I am finish to use NETLOAD I can no see the command to run the Palette
Thanks _gile , ActivistInvestor,Keith.Brown for your help
_ps = New AutoHidePaletteSet("PALETTESHOW", "PALETTESHOW", New Guid("{850aa970-3e9e-49bf-a58c-a30821f04256}"))
Here is an example from Norman Yuan,
http://drive-cad-with-code.blogspot.com.au/2011/10/about-terminate-method-of.html
Everything will work just as you expect it to, unless your expectations are incorrect.
class keyThumper<T> : Lazy<T>; another Swamper