Hide and Show the Property Palette

Hide and Show the Property Palette

Keith.Brown
Advisor Advisor
2,815 Views
24 Replies
Message 1 of 25

Hide and Show the Property Palette

Keith.Brown
Advisor
Advisor

Is there anyway in the AutoCAD API to 

1. Determine if the property palette is open, closed, or hidden?

2. Close the property palette.

3. Open the property palette.

0 Likes
Accepted solutions (1)
2,816 Views
24 Replies
Replies (24)
Message 2 of 25

SENL1362
Advisor
Advisor

ON: Properties

OFF: PropertiesClose

IsShown or IsHidden : ?enumerate Windows?

 

0 Likes
Message 3 of 25

Keith.Brown
Advisor
Advisor

I am not sure how that helps me?  It does not do #1 which is most important to restore the UI to its original condition and it is not .Net API.  It is just a couple of commands to close the property palette and then to open it disregarding if it the property palette was already open or not.

Basically what I need the .NET for is I am processing script files which is started from a process on a palette.  Each script file creates a single drawing and there can be multiple drawings.  Each script file contains hundreds of custom commands.  These custom commands will create and process an entity and then select then entity for further processing by other commands.  This causes the property palette to refresh itself which increases the processing time by at least 1000%.  I have included the 2 commands HIDEPALETTES and SHOWPALETTES at the beginning and end of each script and this works well if I use the AutoCAD Scripting Engine.  i.e. run the scripts normally thru AutoCAD.   I coded my own scripting engine and it works well except when it comes to those two commands.  I am not sure how to code them in .Net or if it is even possible.  I am also not able to send them to the command line and get them to work properly as everything is started from a palette button.  The commands wait until the end of all the other commands being processed from the script file to run.  These are the only two commands which I currently do not handle thru my own .net code.

0 Likes
Message 4 of 25

SENL1362
Advisor
Advisor

You can't call PropertiesClose before running you're script(s)?
Might be complicated but you may also have a look into the %appdata%\...\Profile.aws
You can find any Named ToolPalette(inclusive you're own ToolPalettes) status in there.
So if you could alter these files before starting AutoCAD then...

 

 

..\Profile.aws
//Close Properties Panel and Close AutoCAD, want a few seconds
..Name="Properties" Style="46" Opacity="100" RolloverOpacity="100" Visible="0"

//Show Properties Panel and Close AutoCAD, want a few seconds
..Name="Properties" Style="46" Opacity="100" RolloverOpacity="100" Visible="1"

 

0 Likes
Message 5 of 25

Keith.Brown
Advisor
Advisor

@SENL1362 wrote:

You can't call PropertiesClose before running you're script(s)?


I cannot get it to work.  I would love someone to show me how at the press of a button on a palette, you get the command "HIDEPALETTES" or "PROPERTYCLOSE" command to run and then run a bunch of other code and then run the command "SHOWPALETTES" or "PROPERTIES" after all other code has ran.  No matter what I try, the first command runs after all of my .net code has ran and then the second command runs.

I am sure it has to do with Application context vs command context and how the commands run synchronously vs asynchronously.   I have yet to find a solid example from someone that has done it.  It might/probably be possible but I am unable to get it to work.

0 Likes
Message 6 of 25

ActivistInvestor
Mentor
Mentor

Can't tell you much without knowing what your code does and how it runs. What starts it? Does it run in the document context or the application context?

0 Likes
Message 7 of 25

Keith.Brown
Advisor
Advisor

My original question did not require any code.  My guess is that you cannot directly inspect the property palettes state or open/close it from .NET or at least no one has shared how to do it yet.

My code is running in the Application/Session context and is activated from a palette button that reads some information from the palette and then reads a .scr file using a filestream.  It parses each line and based on the first word in the line will call a specific class.  For the word "HIDEPALETTES" this is my class.

 

namespace Worx.Diagrams.Scripting.Commands
{
    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    using Autodesk.AutoCAD.ApplicationServices;
    using Worx.Tools;

    /// <summary>
    /// Class HidePalettesScriptCommand.
    /// Implements the <see cref="Worx.Diagrams.Scripting.Commands.IScriptCommand" />
    /// </summary>
    /// <seealso cref="Worx.Diagrams.Scripting.Commands.IScriptCommand" />
    internal class HidePalettesScriptCommand : IScriptCommand
    {
        #region Public Properties

        /// <summary>
        /// Gets the name of the command.
        /// </summary>
        /// <value>The name of the command.</value>
        public string CommandName => ScriptCommandConstants.HidePalettes;

        #endregion Public Properties

        #region Public Methods

        /// <summary>
        /// Executes the specified script command.
        /// </summary>
        /// <param name="parameters">The parameters required for the command execution.</param>
        /// <param name="lineNumber">The line number in the script where the command is located.</param>
        /// <returns>A tuple where the first item indicates if the command execution was successful, the second item indicates if the script should terminate, and the third item may contain additional information or an error message.</returns>
        public (bool successful, bool terminate, string message) Execute(IList<string> parameters, int lineNumber)
        {
            try
            {
                this.HidePalettes();
                return (true, false, $"{this.CommandName} executed successful.");
            }
            catch (Exception e)
            {
                return (false, false, $"Failed to execute the {this.CommandName} command.  Error: {e.Message}");
            }
        }

        #endregion Public Methods

        #region Private Methods

        /// <summary>
        /// Hides the palettes.
        /// </summary>
        private async void HidePalettes()
        {
            await Application.DocumentManager.ExecuteInCommandContextAsync( async (obj) =>
            {
                await Active.Editor.CommandAsync(this.CommandName);
            }, null);
        }

        #endregion Private Methods
    }
}

 


I admit I am not strong on this part of the api and have tried many iterations of the above code and have not had success.

Using the AutoCAD scripting engine, i just start a new session of autocad and pass in the script and the drawing to run the script on as startup parameters for each script/drawing combo.  That works great on a large list of drawings but I would prefer to use my own scripting engine and get this working if I can.  I can always add a popup to inform the user to close the property palette if it is open or hidden but I would prefer to fix it automatically.

Removing the async gives me the same result.  That is just the last iteration that I tried.

0 Likes
Message 8 of 25

ActivistInvestor
Mentor
Mentor

ExecuteInCommandContextAsync() causes the code in the delegate you pass it to execute as if it were executing in the handler of a modal command, where it's possible to call Editor.Command().  Have you tried using that rather than CommandAsync() ?

 

A last resort if all else fails, is to add a handler to the Idle event when the script starts, and from the handler, check a flag that's set when the script completes, and if the flag is set, then just issue the command to show/hide the properties palette (and remove the handler for the Idle event).

0 Likes
Message 9 of 25

ActivistInvestor
Mentor
Mentor
Accepted solution

Insofar as accessing the Properties Palette, see if this works:

 

using Autodesk.AutoCAD.Internal.PropertyInspector;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace Autodesk.AutoCAD.ActivistInvestor
{
   public static class PropertyInspector
   {
      static IAcPpPaletteSet paletteSet = null;

      public static IAcPpPaletteSet PaletteSet
      {
         get
         {
            if(paletteSet == null)
               paletteSet = (IAcPpPaletteSet)new AcPpPaletteSetClass();
            return paletteSet;
         }
      }

      public static bool Visible
      {
         get
         {
            return PaletteSet.Visibility;
         }
         set
         {
            if(value ^ PaletteSet.Visibility)
               PaletteSet.Visibility = value;
         }
      }

      public static PropertyInspectorEventManager EventManager
      {
         get
         {
            return PropertyInspectorEventManager.Instance();
         }
      }
   }

}

[ComImport]
[Guid("A20A927F-5508-4624-9157-FD5CBE5B2D64")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IAcPpPalette
{
   [DispId(1)]
   string Name
   {
      [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
      [return: MarshalAs(UnmanagedType.BStr)]
      get;
      [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
      [param: In]
      [param: MarshalAs(UnmanagedType.BStr)]
      set;
   }
}


[ComImport]
[Guid("0CC0CED7-7D69-490B-A84B-A7500674A29C")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]

public interface IAcPpPaletteSet
{
   [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
   void AddPalette([In][MarshalAs(UnmanagedType.Interface)] IAcPpPalette pPalette);

   [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
   void DeletePalette([In][MarshalAs(UnmanagedType.Interface)] IAcPpPalette pPalette);

   [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
   void InsertPalette([In] int index, [In][MarshalAs(UnmanagedType.Interface)] IAcPpPalette pPalette);

   [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
   [return: MarshalAs(UnmanagedType.Interface)]
   IAcPpPalette GetPalette([In] int index);

   [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
   [return: MarshalAs(UnmanagedType.Interface)]
   IAcPpPalette GetPaletteByName([In][MarshalAs(UnmanagedType.BStr)] string paletteName);

   [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
   void ActivatePalette([In][MarshalAs(UnmanagedType.Interface)] IAcPpPalette pPalette);

   [DispId(7)]
   int PaletteCount
   {
      [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
      get;
   }

   [DispId(8)]
   bool Visibility
   {
      [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
      get;
      [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
      [param: In]
      set;
   }

   [DispId(9)]
   int CurrentIndex
   {
      [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
      get;
   }

   [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
   void GetDockingState(out int nDockPos, out int left, out int top, out int width, out int height);

   [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
   void SetDockingState([In] int nDockPos, [In] int left, [In] int top, [In] int width, [In] int height);

   [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
   void GetFloatingRect(out int left, out int top, out int width, out int height);

   [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
   void GetDockingRect(out int nDockPos, out int left, out int top, out int width, out int height);
}


[ComImport]
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces("Autodesk.AutoCAD.PropertyPalette.IAcPpPaletteSetEvents\0")]
[Guid("2FAA8BEA-AB1B-479A-97B2-6E7AAB38750E")]
[TypeLibType(TypeLibTypeFlags.FCanCreate)]
public class AcPpPaletteSetClass
{
}

 

Message 10 of 25

norman.yuan
Mentor
Mentor

@Keith.Brown 

It seems to me, you just want to make sure the Props window is closed prior to the processing's beginning, and really not care much to re-open the Props window, if it was open before the processing begins. In this case, you can use CommandEnded event handler to handle "PROPERTIESCLOSE" command to actually kick off the processing.

 

I quickly put together some code to demo what I mean:

 

1. A WinForm user control, used as Palette in the PalettSet, which only has a button in it. It code behind as following

 

using System;
using System.Windows.Forms;

namespace PaletteSetWithCommandHandling
{
    public partial class PaletteView : UserControl
    {
        public PaletteView()
        {
            InitializeComponent();

            DwgProcessTool.ProcessStarted += () => { DoWorkButton.Enabled = false; };
            DwgProcessTool.ProcessEnded += () => { DoWorkButton.Enabled = true; };
        }

        public static Action DoWorkButtonClick;

        private void DoWorkButton_Click(object sender, EventArgs e)
        {
            DoWorkButtonClick?.Invoke();
        }
    } 
}

 

2. The PaletteSet:

 

using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.ApplicationServices;
using CadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using System;

namespace PaletteSetWithCommandHandling
{
    public class MyPaletteSet : PaletteSet
    {
        public static bool DwgProcessingStarted = false;
        public const string PROCESSING_TRIGGER_COMMAD = "PROPERTIESCLOSE";

        private Document _currentDwg = null;

        private readonly PaletteView _palette;
        public MyPaletteSet() :
            base("","", new Guid("A775612C-B26A-4B91-8483-A4ED2B69B7E4"))
        {
            this.Style = PaletteSetStyles.ShowCloseButton | 
                PaletteSetStyles.ShowAutoHideButton | 
                PaletteSetStyles.UsePaletteNameAsTitleForSingle;

            _palette = new PaletteView();
            Add("DWG Processing", _palette);

            PaletteView.DoWorkButtonClick += StartDwgProcessing;
        }

        private void StartDwgProcessing()
        {
            var dwg = CadApp.DocumentManager.MdiActiveDocument;

            DwgProcessingStarted = true;
            dwg.CommandEnded += Dwg_CommandEnded;

            dwg.SendStringToExecute($"{PROCESSING_TRIGGER_COMMAD}\n", true, false, false);
        }

        private void Dwg_CommandEnded(object sender, CommandEventArgs e)
        {
            if (e.GlobalCommandName.ToUpper() == PROCESSING_TRIGGER_COMMAD && DwgProcessingStarted)
            {
                var dwg = CadApp.DocumentManager.MdiActiveDocument; 
                dwg.CommandEnded -= Dwg_CommandEnded;

                _currentDwg = dwg;
                CadApp.MainWindow.Focus();

                DwgProcessTool.ProcessEnded += ProcessEnded;
                var tool = new DwgProcessTool();
                tool.ProcessDrawings();
            }
        }
        
        private void ProcessEnded()
        {
            CadApp.Idle += CadApp_Idle;
        }

        private void CadApp_Idle(object sender, EventArgs e)
        {
            if (DwgProcessingStarted)
            {
                DwgProcessingStarted = false;
                CadApp.Idle -= CadApp_Idle;

                // Do something that is necessary after the processing if needed
                // for example, update the PaletteSet UI components

                CadApp.DocumentManager.MdiActiveDocument = _currentDwg;
                this.Focus();
            }
            
        }
    }
}

 

3. The drawing processing tool. For the sake of simplicity, it only loop through each opened drawing, set it as MdiActiveDocument (that is why you want to prevent Props window from being kept open, right?) retrieve layer's count in the drawing"

 

using Autodesk.AutoCAD.ApplicationServices;
using CadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using System;
using System.Linq;
using Autodesk.AutoCAD.DatabaseServices;
using System.Windows.Forms;

namespace PaletteSetWithCommandHandling
{
    public class DwgProcessTool
    {
        public static Action ProcessStarted;
        public static Action ProcessEnded;

        public void ProcessDrawings()
        {
            ProcessStarted?.Invoke();

            foreach (Document dwg in CadApp.DocumentManager)
            {
                CadApp.DocumentManager.MdiActiveDocument = dwg;
                ProcessDrawing(dwg);
            }

            MessageBox.Show($"Drawings processed: {CadApp.DocumentManager.Count}");

            ProcessEnded?.Invoke();
        }

        private void ProcessDrawing(Document dwg)
        {
            using (dwg.LockDocument())
            {
                using (var tran = dwg.TransactionManager.StartTransaction())
                {
                    var lt = (LayerTable)tran.GetObject(dwg.Database.LayerTableId, OpenMode.ForRead);
                    var count=lt.Cast<ObjectId>().Count();
                    var msg=$"Drawing Name: {dwg.Name}\nLayer Count: {count}";
                    MessageBox.Show(msg);
                    tran.Commit();
                }
            }
        }
    }
}

 

4. Finally the commandmethod showing the PaletteSet:

 

using Autodesk.AutoCAD.Runtime;

[assembly: CommandClass(typeof(PaletteSetWithCommandHandling.MyCommands))]

namespace PaletteSetWithCommandHandling
{
    public class MyCommands 
    {
        private static MyPaletteSet _processingUI = null;

        [CommandMethod("ShowTool", CommandFlags.Session)]
        public static void RunMyCommand()
        {
            if (_processingUI == null)
            {
                _processingUI = new MyPaletteSet();
            }
            _processingUI.Visible = true;
        }
    }
}

 

Here is the video clip showing how it works:

 

As you can see, clicking the button on the PaletteSet send command "PROPERTIESCLOSE" to command line (regardless the Props window being open or not. And when the "PROPERTIESCLOSE" command ends, the processing gets started. You would notices there are 2 static Actions (events) - ProcessStarted/Ended can be hooked to the UI to disable/enable the button; and the processing is done in the ApplicationContext (thus the locking document). 

 

Edit: in the video, I forgot leave the Props window open prior to clicking the button. But it surely close the Props window, if it is open.

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 11 of 25

ActivistInvestor
Mentor
Mentor

@Keith.Brown wrote:

Is there anyway in the AutoCAD API to 

1. Determine if the property palette is open, closed, or hidden?

2. Close the property palette.

3. Open the property palette.


...................

I am not sure how that helps me?  It does not do #1 which is most important to restore the UI to its original condition and it is not .Net API.  It is just a couple of commands to close the property palette and then to open it disregarding if it the property palette was already open or not.


 

You can use the OPMSTATE system variable to find out if the properties palette is visible, hidden, or collapsed.

 

The complication in your case, has to do with when the properties pallet is docked. In that case, hiding it will change the size of the drawing view window. When the size of the drawing View Window changes, any running commands or scripts are cancelled.

 

Try starting the LINE command, draw a few segments, and at a prompt for the next point, manually resize the AutoCAD main window. What happens?

 

So, regardless of how you hide the Properties Palette, any running script will be stopped. You have to handle the hiding/showing of the Properties Palette as a separate process, and then kick off your script file after hiding it. Showing it afterwards will lead to the same problem as well (if the Properties Palette is docked). As I mentioned previously, you can use the Application.Idle event to deal with this problem, without having to jump through all sorts of hoops and/or write and debug 5 pages of code.

0 Likes
Message 12 of 25

ActivistInvestor
Mentor
Mentor

@norman.yuan wrote:

 

It seems to me, you just want to make sure the Props window is closed prior to the processing's beginning, and really not care much to re-open the Props window, if it was open before the processing begins. 

The OP said he needs to hide the properties palette before his scripting runs and restore it to its previous state after the scripting is finished.

0 Likes
Message 13 of 25

norman.yuan
Mentor
Mentor

If the Props window needs to be restored, then, save the OPMSTATE sys variable value, simply call SendStringToExecute("Props\n"...) in the Cad_Idle event handler of my code, which is executed at the end of the processing, base on saved OPMSTATE value.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 14 of 25

ActivistInvestor
Mentor
Mentor

The OP is trying to hide the properties palette when his script contains a command to do that (and show it when the same script includes a command to do that). So, the hiding and showing of the properties palette are just commands that can appear in his script file, rather than something he wants to do before/after processing the script file.

 


@norman.yuan wrote:

If the Props window needs to be restored, then, save the OPMSTATE sys variable value, simply call SendStringToExecute("Props\n"...) in the Cad_Idle event handler of my code, which is executed at the end of the processing, base on saved OPMSTATE value.

 


 

0 Likes
Message 15 of 25

ActivistInvestor
Mentor
Mentor

@Keith.Brown wrote:

My original question did not require any code.  My guess is that you cannot directly inspect the property palettes state or open/close it from .NET or at least no one has shared how to do it yet.

My code is running in the Application/Session context and is activated from a palette button that reads some information from the palette and then reads a .scr file using a filestream.  It parses each line and based on the first word in the line will call a specific class.  For the word "HIDEPALETTES" this is my class.

 

 

        private async void HidePalettes()
        {
            await Application.DocumentManager.ExecuteInCommandContextAsync( async (obj) =>
            {
                await Active.Editor.CommandAsync(this.CommandName);
            }, null);
        }

 

 

After reading your posts again, I see that the problem you're having is that the command that hides the properties palette isn't running until after your other commands. The reason that's happening is because you are using Editor.CommandAsync(), where you should be using Editor.Command().

0 Likes
Message 16 of 25

Keith.Brown
Advisor
Advisor

I woke up this morning to lots of replies so I will need some time to go thru them but a couple of quick responses.

I can use the OPMSTATE variable and do some quick refactoring with the Idle event and get what I want.  I was just hoping there was a way to show/hide the palette internally and there does not appear to be.

The problem that I am having with using the Editor.Command is that I am running in Application context and Editor.Command needs to run in Document context and the switch to Document context only comes async.

private void HidePalettes()
{
	Application.DocumentManager.ExecuteInCommandContextAsync(  (obj) =>
	{
		Active.Editor.Command(this.CommandName);
		return Task.CompletedTask;
	}, null);
}

 

This also will wait till the rest of the code is complete before running so at this point I think I just need to refactor my code to use idle events to wait for certain portions to finish.

0 Likes
Message 17 of 25

ActivistInvestor
Mentor
Mentor

@Keith.Brown wrote:

I woke up this morning to lots of replies so I will need some time to go thru them but a couple of quick responses.

I can use the OPMSTATE variable and do some quick refactoring with the Idle event and get what I want.  I was just hoping there was a way to show/hide the palette internally and there does not appear to be.

The problem that I am having with using the Editor.Command is that I am running in Application context and Editor.Command needs to run in Document context and the switch to Document context only comes async.


I hate repeating myself but....

 

The delegate that you pass to ExecuteInCommandContextAsync() does not run in the application context, it runs in the document/command context, where CommandAsync() should not be used.

 

Also, did you try building the code I posted to show/hide the properaties pallet using the COM  interfaces?

 

0 Likes
Message 18 of 25

Keith.Brown
Advisor
Advisor

@ActivistInvestor wrote:


I hate repeating myself but....

 


I am not really sure why you feel you need to repeat your self or even mention it on the forum.  If you reread my last post you can clearly read that I say my code runs in the application context and the only way that I can see to switch it to document context is running the Document.ExecuteCommandContextAsync.  It does not come without the Async.  I tried all ways possible that I am aware of and nothing has worked using Editor.Command.  You specifically asked me to post code so I posted code that I am aware does not work but people want examples so I gave examples.

I could refactor my code on the palette to use a command instead and pass in the required settings as parameters for the command.  I would now be in the Command context (I believe) and could use Editor.Command and possibly get it to run before the rest of my code.  This is an option but I would rather it be the last option.   Other options using the Idle event are also doable and I can also investigate those.

I have not had a chance to look at the other code you posted as I have just gotten in to the office this morning and have some other higher priority code to finish first.  The property palette code is just  QOL so the customers do not have to remember to close it every time that want to run some scripts.

Thank you for your help as well as everyone else that has replied.  I do appreciate it.

0 Likes
Message 19 of 25

ActivistInvestor
Mentor
Mentor

@Keith.Brown wrote:

I am not really sure why you feel you need to repeat your self or even mention it on the forum.  If you reread my last post you can clearly read that I say my code runs in the application context and the only way that I can see to switch it to document context is running the Document.ExecuteCommandContextAsync.  It does not come without the Async. 

 

It certainly does come without async, if you use await. Without await'ing, the code that follows the call to ExecuteInCommandContextAsync() will run before the delegate passed to it runs.

 

If you await on the call to ExecuteInCommandContextAsync(), any code that follows will run after the delegate returns, and assuming you don't use ComandAsync() in the delegate, then the code that follows the call to await ExecuteInCommandContextAsync() will run after the command issued by Ediotor.Command() has finished.

 

private async void HidePalettes()
{
   await Application.DocumentManager.ExecuteInCommandContextAsync(  (obj) =>
   {
      Active.Editor.Command(this.CommandName);
      return Task.CompletedTask;
   }, null);
   
   // Any code that appears here will not run until 
   // the above delegate returns.
}

 

 

You can also await on the call to HidePalettes() (which might make more sense in your case), by marking the method that calls it as async, and then using await HidePalettes(), and any code that follows that call will not run until the commands are finished.

 

 

0 Likes
Message 20 of 25

Keith.Brown
Advisor
Advisor

That is one of the combinations that I have tried many times.  Is it possible that it is not working because there is no other code in my HidePalette method after the ExecuteInCommandContextAsync delegate?  The rest of the code is in other classes that run with other commands.  I will do some internal testing and see if that is the case.  At least this has been a learning experience for me on Application vs Document context works along with Async/Await has I had never really used either of those in my AutoCAD programming.

So some good news, I implemented your PropertyInspector code above and it did exactly what I needed it to do.  I created a little helper class that implements IDisposible to handle all of the state saving for me.

internal class PropertyPaletteHider : IDisposable
{
	private readonly bool _visible;

	public PropertyPaletteHider()
	{
		this._visible = PropertyInspector.PaletteSet.Visibility;
		PropertyInspector.PaletteSet.Visibility = false;
	}
	
	public void Dispose()
	{
		if (this._visible)
		{
			PropertyInspector.PaletteSet.Visibility = true;
		}
	}
}

// Usage is simply done like this.
using (new PropertyPaletteHider())
{
	this.CreateAutomatedDrawings();
}

 

Thank you for that class as I am sure that I would have never had the time to research how to do it and even if I did I doubt I would have gotten it implemented correctly.

0 Likes