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

PaletteSet, Pallete and other classes relations

10 REPLIES 10
Reply
Message 1 of 11
Anonymous
3049 Views, 10 Replies

PaletteSet, Pallete and other classes relations

Anonymous
Not applicable

Trying to figure out relationship in classes for managing tool palettes.

 

 

PaletteSet - class to create dockabe panel.  Bbut i cant add Palette class into there only Visual or Control. it's only for  full custom  controls?

Is Palette class just definition of  already created Palettes?

 

also Found http://help.autodesk.com/view/OARX/2018/ENU/?guid=OREFNET-Autodesk_Windows_Palettes 

what relation of this classes to   above?

 

namespace Toolpalette have own Palette class, and it completely  different thing? Who is root for showings them?

 

also I seen  mentions about PaletteGroup, but not find such class in reference

0 Likes

PaletteSet, Pallete and other classes relations

Trying to figure out relationship in classes for managing tool palettes.

 

 

PaletteSet - class to create dockabe panel.  Bbut i cant add Palette class into there only Visual or Control. it's only for  full custom  controls?

Is Palette class just definition of  already created Palettes?

 

also Found http://help.autodesk.com/view/OARX/2018/ENU/?guid=OREFNET-Autodesk_Windows_Palettes 

what relation of this classes to   above?

 

namespace Toolpalette have own Palette class, and it completely  different thing? Who is root for showings them?

 

also I seen  mentions about PaletteGroup, but not find such class in reference

10 REPLIES 10
Message 2 of 11
_gile
in reply to: Anonymous

_gile
Mentor
Mentor

Hi,

 

PaletteSet and Toolpalette are two different things.

 

PaletteSet is a class (Autodesk.AutoCAD.Windows.PaletteSet class) which defines a dockable modeless container for custom user controls (Autodesk.AutoCAD.Windows.Palette instances).

The Autodesk.AutoCAD.Windows.Palette only exposes two properties: the name of the Palette (the PaletteSet tab name) and the PaletteSet it is part of

A Palette instance is created by adding a user control either with the PaletteSet.Add() method (Winform) or the PaletteSet.AddVisual() one (WPF).

 

ToolPalette is a namespace (Autodesk.AutoCAD.Windows.ToolPalette namespace) which contains the classes and the interfaces used to manage the built-in AutoCAD tool palettes.

You can see here an example of adding items to an AutoCAD toll palette.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Hi,

 

PaletteSet and Toolpalette are two different things.

 

PaletteSet is a class (Autodesk.AutoCAD.Windows.PaletteSet class) which defines a dockable modeless container for custom user controls (Autodesk.AutoCAD.Windows.Palette instances).

The Autodesk.AutoCAD.Windows.Palette only exposes two properties: the name of the Palette (the PaletteSet tab name) and the PaletteSet it is part of

A Palette instance is created by adding a user control either with the PaletteSet.Add() method (Winform) or the PaletteSet.AddVisual() one (WPF).

 

ToolPalette is a namespace (Autodesk.AutoCAD.Windows.ToolPalette namespace) which contains the classes and the interfaces used to manage the built-in AutoCAD tool palettes.

You can see here an example of adding items to an AutoCAD toll palette.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 11
Anonymous
in reply to: _gile

Anonymous
Not applicable

and what is  Autodesk.Windows.Palettes Namespace ?

 

it create different kind  of modals, not dockable  as I understand

 

 

0 Likes

and what is  Autodesk.Windows.Palettes Namespace ?

 

it create different kind  of modals, not dockable  as I understand

 

 

Message 4 of 11
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

So   Using PaletteSet  I can implement own controls with  list of icons and execute command on click like "block: some_cool_block"?

 

I saw example you mentioned. Not  able to  make it run.  Should I somehow register  lisp function?

 

 

   [LispFunction("TP-CREATE")]
    public ResultBuffer CreateToolPaletteCommand(

it say that it's not found

0 Likes

So   Using PaletteSet  I can implement own controls with  list of icons and execute command on click like "block: some_cool_block"?

 

I saw example you mentioned. Not  able to  make it run.  Should I somehow register  lisp function?

 

 

   [LispFunction("TP-CREATE")]
    public ResultBuffer CreateToolPaletteCommand(

it say that it's not found

Message 5 of 11
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
0 Likes

Message 6 of 11
ActivistInvestor
in reply to: Anonymous

ActivistInvestor
Advisor
Advisor

@Anonymous wrote:

Trying to figure out relationship in classes for managing tool palettes.

 

 

PaletteSet - class to create dockabe panel.  Bbut i cant add Palette class into there only Visual or Control. it's only for  full custom  controls?

Is Palette class just definition of  already created Palettes?

 

also Found http://help.autodesk.com/view/OARX/2018/ENU/?guid=OREFNET-Autodesk_Windows_Palettes 

what relation of this classes to   above?

 

namespace Toolpalette have own Palette class, and it completely  different thing? Who is root for showings them?

 

also I seen  mentions about PaletteGroup, but not find such class in reference


I think you're referring to the WPF-based PaletteSet, Palette, and related classes (including PaletteGroup), which lives in AdUiPalettes.dll.

 

They are pure WPF-based alternatives to the existing/legacy PaletteSet and Palette classes, and offer some additional functionality (the user can drag palettes and dock them to any PaletteSet). Beyond that I can't tell you much as I've not used or experimented with them thus-far.

 

 

 

ilspy.png

0 Likes


@Anonymous wrote:

Trying to figure out relationship in classes for managing tool palettes.

 

 

PaletteSet - class to create dockabe panel.  Bbut i cant add Palette class into there only Visual or Control. it's only for  full custom  controls?

Is Palette class just definition of  already created Palettes?

 

also Found http://help.autodesk.com/view/OARX/2018/ENU/?guid=OREFNET-Autodesk_Windows_Palettes 

what relation of this classes to   above?

 

namespace Toolpalette have own Palette class, and it completely  different thing? Who is root for showings them?

 

also I seen  mentions about PaletteGroup, but not find such class in reference


I think you're referring to the WPF-based PaletteSet, Palette, and related classes (including PaletteGroup), which lives in AdUiPalettes.dll.

 

They are pure WPF-based alternatives to the existing/legacy PaletteSet and Palette classes, and offer some additional functionality (the user can drag palettes and dock them to any PaletteSet). Beyond that I can't tell you much as I've not used or experimented with them thus-far.

 

 

 

ilspy.png

Message 7 of 11
Juergen_Becker
in reply to: Anonymous

Juergen_Becker
Advocate
Advocate

Hi,

I do it like that way.

 

 

using Autodesk.AutoCAD.Windows;

Declare a paletteset object variable. The best way is to do that in that class where the initialize method is.

 

 

 

static public Autodesk.AutoCAD.Windows.PaletteSet ZFRegisterPalette = null;

 

Create a usercontrol (a Windows or WPF Control) which will include into the Palette and declare it in the same class. You must not use WPF, when you not familiar with it.

 

static public ZF.CAD.Register.usrRegisterPalette USrRegisterPalette = null;

Then create a command which open a Palette.

 

if (ZF_CAD.ZFRegisterPalette == null)
 {

     USrRegisterPalette = new ZF.CAD.Register.usrRegisterPalette()
     {

     };
     USrRegisterPalette.FillData();


     ZF_CAD.ZFRegisterPalette = new PaletteSet("ZF-Register zeichnen");

     ZF_CAD.ZFRegisterPalette.Style = 
        PaletteSetStyles.NameEditable |
        PaletteSetStyles.ShowPropertiesMenu |
        PaletteSetStyles.ShowAutoHideButton |
        PaletteSetStyles.ShowCloseButton;
      ZF_CAD.ZFRegisterPalette.MinimumSize = new System.Drawing.Size(800, 400);

      ZF_CAD.ZFRegisterPalette.Add("ZF-Register zeichnen", USrRegisterPalette);
 }
 else
 {
      USrRegisterPalette.FillData();
}
ZF_CAD.ZFRegisterPalette.Visible = true;

Now the ZFRegisterpalette can be used as a normal AutoCAD Palette.

 

 

Regards Jürgen

I hope my tip helps. If so then give me kudos and mark the tip as a solution.
Thanks.

Jürgen A. Becker
Building Services

Development and Support
Autodesk Forge Spezialist


CAD-Becker.de
https://www.CAD-Becker.de

Hi,

I do it like that way.

 

 

using Autodesk.AutoCAD.Windows;

Declare a paletteset object variable. The best way is to do that in that class where the initialize method is.

 

 

 

static public Autodesk.AutoCAD.Windows.PaletteSet ZFRegisterPalette = null;

 

Create a usercontrol (a Windows or WPF Control) which will include into the Palette and declare it in the same class. You must not use WPF, when you not familiar with it.

 

static public ZF.CAD.Register.usrRegisterPalette USrRegisterPalette = null;

Then create a command which open a Palette.

 

if (ZF_CAD.ZFRegisterPalette == null)
 {

     USrRegisterPalette = new ZF.CAD.Register.usrRegisterPalette()
     {

     };
     USrRegisterPalette.FillData();


     ZF_CAD.ZFRegisterPalette = new PaletteSet("ZF-Register zeichnen");

     ZF_CAD.ZFRegisterPalette.Style = 
        PaletteSetStyles.NameEditable |
        PaletteSetStyles.ShowPropertiesMenu |
        PaletteSetStyles.ShowAutoHideButton |
        PaletteSetStyles.ShowCloseButton;
      ZF_CAD.ZFRegisterPalette.MinimumSize = new System.Drawing.Size(800, 400);

      ZF_CAD.ZFRegisterPalette.Add("ZF-Register zeichnen", USrRegisterPalette);
 }
 else
 {
      USrRegisterPalette.FillData();
}
ZF_CAD.ZFRegisterPalette.Visible = true;

Now the ZFRegisterpalette can be used as a normal AutoCAD Palette.

 

 

Regards Jürgen

I hope my tip helps. If so then give me kudos and mark the tip as a solution.
Thanks.

Jürgen A. Becker
Building Services

Development and Support
Autodesk Forge Spezialist


CAD-Becker.de
https://www.CAD-Becker.de

Message 8 of 11
Anonymous
in reply to: Juergen_Becker

Anonymous
Not applicable

I'm OK with WPF -  going this way.

 

what is inside FillData?

how specific command should look? As I suppose above - just regular elements with handle click and run declared command in document context?

 

0 Likes

I'm OK with WPF -  going this way.

 

what is inside FillData?

how specific command should look? As I suppose above - just regular elements with handle click and run declared command in document context?

 

Message 9 of 11
Juergen_Becker
in reply to: Anonymous

Juergen_Becker
Advocate
Advocate

HI,

 

the filldata method only fills the usercontrol with the needed datas. Not so important for you.

 

This is the CommandMethod definition.

 

[CommandMethod("ZF_Register", CommandFlags.Session)]
public static void ZF_Register()
{


}
I hope my tip helps. If so then give me kudos and mark the tip as a solution.
Thanks.

Jürgen A. Becker
Building Services

Development and Support
Autodesk Forge Spezialist


CAD-Becker.de
https://www.CAD-Becker.de

0 Likes

HI,

 

the filldata method only fills the usercontrol with the needed datas. Not so important for you.

 

This is the CommandMethod definition.

 

[CommandMethod("ZF_Register", CommandFlags.Session)]
public static void ZF_Register()
{


}
I hope my tip helps. If so then give me kudos and mark the tip as a solution.
Thanks.

Jürgen A. Becker
Building Services

Development and Support
Autodesk Forge Spezialist


CAD-Becker.de
https://www.CAD-Becker.de

Message 10 of 11
_gile
in reply to: Anonymous

_gile
Mentor
Mentor

Here's the way I typically use.

The CMD_PALETTE command shows the palette (it creates it if not already created).

In this example, the palette owns 2 tabs (a user control defined with Winform: WinFormUserControl-, the other one with WPF: WpfUserControl) which should contains controls to interact with AutoCAD.

 

If you can read French, you can see this tutorial about AutoCAD user interfaces (specifically the Palette and Palette avec MVVM topics).

 

 

 

using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows;
using System;
using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace AcadUISample.Palette
{
    public class Commands
    {
        static PaletteSet palette;
        static bool wasVisible;;
        
        [CommandMethod("CMD_PALETTE")]
        public void ShowPaletteSet()
        {
            if (palette == null)
            {
                palette = new PaletteSet(
                    "Palette", // the palette set name
                    "CMD_PALETTE", // the command name
                    new Guid("{1836C7AC-C70E-4CF7-AA05-F6298D257046}")); a GUID used by AutoCAD to restore the palettte state
                palette.Style =
                    PaletteSetStyles.ShowAutoHideButton |
                    PaletteSetStyles.ShowCloseButton |
                    PaletteSetStyles.ShowPropertiesMenu;
                palette.MinimumSize = new System.Drawing.Size(300, 300);
		// Add a palette using a class derived from System.Windows.Form.UserControl
                palette.Add("WinForm Palette", new WinFormUserControl());
		// Add a palette using a class derived from System.Windows.Controls.UserControl
		palette.AddVisual("WPF Palette", new WpfUserControl());
                
                // automatically hide the palette on 'no document state'.
                var docs = AcAp.DocumentManager;
                docs.DocumentBecameCurrent += (s, e) => 
                    palette.Visible = e.Document == null ? false : wasVisible;
                docs.DocumentCreated += (s, e) => 
                    palette.Visible = wasVisible;
                docs.DocumentToBeDeactivated += (s, e) => 
                    wasVisible = palette.Visible;
                docs.DocumentToBeDestroyed += (s, e) =>
                {
                    wasVisible = palette.Visible;
                    if (docs.Count == 1)
                        palette.Visible = false;
                };
            }
            palette.Visible = true;
        }
    }
}

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Here's the way I typically use.

The CMD_PALETTE command shows the palette (it creates it if not already created).

In this example, the palette owns 2 tabs (a user control defined with Winform: WinFormUserControl-, the other one with WPF: WpfUserControl) which should contains controls to interact with AutoCAD.

 

If you can read French, you can see this tutorial about AutoCAD user interfaces (specifically the Palette and Palette avec MVVM topics).

 

 

 

using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows;
using System;
using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace AcadUISample.Palette
{
    public class Commands
    {
        static PaletteSet palette;
        static bool wasVisible;;
        
        [CommandMethod("CMD_PALETTE")]
        public void ShowPaletteSet()
        {
            if (palette == null)
            {
                palette = new PaletteSet(
                    "Palette", // the palette set name
                    "CMD_PALETTE", // the command name
                    new Guid("{1836C7AC-C70E-4CF7-AA05-F6298D257046}")); a GUID used by AutoCAD to restore the palettte state
                palette.Style =
                    PaletteSetStyles.ShowAutoHideButton |
                    PaletteSetStyles.ShowCloseButton |
                    PaletteSetStyles.ShowPropertiesMenu;
                palette.MinimumSize = new System.Drawing.Size(300, 300);
		// Add a palette using a class derived from System.Windows.Form.UserControl
                palette.Add("WinForm Palette", new WinFormUserControl());
		// Add a palette using a class derived from System.Windows.Controls.UserControl
		palette.AddVisual("WPF Palette", new WpfUserControl());
                
                // automatically hide the palette on 'no document state'.
                var docs = AcAp.DocumentManager;
                docs.DocumentBecameCurrent += (s, e) => 
                    palette.Visible = e.Document == null ? false : wasVisible;
                docs.DocumentCreated += (s, e) => 
                    palette.Visible = wasVisible;
                docs.DocumentToBeDeactivated += (s, e) => 
                    wasVisible = palette.Visible;
                docs.DocumentToBeDestroyed += (s, e) =>
                {
                    wasVisible = palette.Visible;
                    if (docs.Count == 1)
                        palette.Visible = false;
                };
            }
            palette.Visible = true;
        }
    }
}

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 11 of 11
ActivistInvestor
in reply to: Anonymous

ActivistInvestor
Advisor
Advisor

@Anonymous wrote:

I'm OK with WPF -  going this way.

 

what is inside FillData?

how specific command should look? As I suppose above - just regular elements with handle click and run declared command in document context?

 


In the very early versions of the AutoCAD API (pre-2008 or -2009, I believe), the PaletteSet class was sealed, and you could not derive specializations from it. Then the ribbon and floating Layer properties palette came along, and Autodesk unsealed the PaletteSet class and made some of its methods/properties virtual so they can overridden in derived types. The ribbon is hosted by a class derived from PaletteSet, and all other managed PaletteSets that come in the box (like the Layer Palette) use specialized derived types that allow much greater control over the PaletteSet.

 

Unlike the examples given by both @_gile@ and @Anonymous_Becke, I think it is better in the long-term to follow that same pattern and derive a class from the PaletteSet and create an instance of that rather than the base PaletteSet class. That gives you a way to initialize it internally in the constructor, so that it has no external dependence on the command that shows it. The command that shows your PaletteSet should do nothing other than create an instance of the PaletteSet and call it's Visible method. The rest should be handled internally by the PaletteSet (in a derived type, just place all of the code that initializes it in the constructor). You don't want a UI component like a PaletteSet to have a dependence on a command method, or any other code for that matter, because you may want/need to create and show the PaletteSet from some other place or context, and you would need to replicate all of the Initialization code that is done in the commands shown in the examples from @_gile and @Juergen_Becker in any other place where you need to create/show the PaletteSet.

 

Just as we don't (and should not) use the System.Windows.Forms.Form class directly (Visual Studio creates a class derived from it when you add a Windows Form to your project), we also shouldn't do that with the PaletteSet either.

 

You can see a very basic example of using a PaletteSet by deriving a class from it in >this post<, which also shows how to run code in the document context from the click handler of a Button or other control on a PaletteSet.

 

 

0 Likes


@Anonymous wrote:

I'm OK with WPF -  going this way.

 

what is inside FillData?

how specific command should look? As I suppose above - just regular elements with handle click and run declared command in document context?

 


In the very early versions of the AutoCAD API (pre-2008 or -2009, I believe), the PaletteSet class was sealed, and you could not derive specializations from it. Then the ribbon and floating Layer properties palette came along, and Autodesk unsealed the PaletteSet class and made some of its methods/properties virtual so they can overridden in derived types. The ribbon is hosted by a class derived from PaletteSet, and all other managed PaletteSets that come in the box (like the Layer Palette) use specialized derived types that allow much greater control over the PaletteSet.

 

Unlike the examples given by both @_gile@ and @Anonymous_Becke, I think it is better in the long-term to follow that same pattern and derive a class from the PaletteSet and create an instance of that rather than the base PaletteSet class. That gives you a way to initialize it internally in the constructor, so that it has no external dependence on the command that shows it. The command that shows your PaletteSet should do nothing other than create an instance of the PaletteSet and call it's Visible method. The rest should be handled internally by the PaletteSet (in a derived type, just place all of the code that initializes it in the constructor). You don't want a UI component like a PaletteSet to have a dependence on a command method, or any other code for that matter, because you may want/need to create and show the PaletteSet from some other place or context, and you would need to replicate all of the Initialization code that is done in the commands shown in the examples from @_gile and @Juergen_Becker in any other place where you need to create/show the PaletteSet.

 

Just as we don't (and should not) use the System.Windows.Forms.Form class directly (Visual Studio creates a class derived from it when you add a Windows Form to your project), we also shouldn't do that with the PaletteSet either.

 

You can see a very basic example of using a PaletteSet by deriving a class from it in >this post<, which also shows how to run code in the document context from the click handler of a Button or other control on a PaletteSet.

 

 

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report