.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Hide Palette when no Drawings are open

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
Sgear
1530 Views, 14 Replies

Hide Palette when no Drawings are open

Hi

 

 

How can I hide Palette when no Drawings are open and show Paletta again when Drawings are open

 

14 REPLIES 14
Message 2 of 15
Keith.Brown
in reply to: Sgear

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

Message 3 of 15
_gile
in reply to: Sgear

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...



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 15
Sgear
in reply to: _gile

Thanks

Message 5 of 15
ActivistInvestor
in reply to: _gile


@_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.

Message 6 of 15
_gile
in reply to: ActivistInvestor

@ActivistInvestor

Once again, thank you very much for your wise advice.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 7 of 15
_gile
in reply to: _gile

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;
            };
        }
    }
}

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 8 of 15
ActivistInvestor
in reply to: _gile


@_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;
      }

 

 

Message 9 of 15
Sgear
in reply to: _gile

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

Message 10 of 15
_gile
in reply to: Sgear

You should add the AutoHidePaletteSet class as a new class to your project (it has nothing to do with Myplugin class which implements IExtensionApplication).

Then you should instantiate _ps as new AutoHidePaletteSet instead of Palette.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 11 of 15
Sgear
in reply to: _gile

Thanks _gile , ActivistInvestor,Keith.Brown for your help

 

 

 _ps = New AutoHidePaletteSet("PALETTESHOW", "PALETTESHOW", New Guid("{850aa970-3e9e-49bf-a58c-a30821f04256}"))
Message 12 of 15
Sgear
in reply to: ActivistInvestor

Hi

 

How do you use quitWillStart 

 

Regards

sgear

Message 13 of 15
kdub_nz
in reply to: Sgear

 

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

Message 14 of 15
ActivistInvestor
in reply to: Sgear


@Sgear wrote:

Hi

 

How do you use quitWillStart 

 

Regards

sgear


Autodesk.AutoCAD.ApplicationServices.Application.QuitWillStart += new EventHandler(myQuitWillStart);

void myQuitWillStart(object sender, EventArgs e)
{
   // TODO: Add code here to run when AutoCAD shuts down.
}
Message 15 of 15
Sgear
in reply to: Sgear

Thanks

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost