c# pallete create

c# pallete create

Anonymous
Not applicable
5,569 Views
19 Replies
Message 1 of 20

c# pallete create

Anonymous
Not applicable

hello kean if you have me in c # environment send autocad palette creation file I need this much mail address cihanbaki2144@gmail.com

0 Likes
Accepted solutions (1)
5,570 Views
19 Replies
Replies (19)
Message 2 of 20

_gile
Consultant
Consultant

Hi,

 

A good practice should be:

  1. Define the commands (PC, Method1, Method2, Method3, Method4 and TEST) decoring them with the CommandMethod attribute so that they work as expected when called from AutoCAD Command line.
  2. Add a UserControl to the project with the buttons and define the Click handler of each button to launch the corresponding command with SendStringToExecute() method.
  3. Define a class deriving from PaletteSet to host the UserControl.
  4. Define a command to show the palette.

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 20

_gile
Consultant
Consultant

Here's a short example

 

The Commands class

    public class Commands
    {
        [CommandMethod("PC")]
        public void Pc()
        {
            // here the code of the PC command
        }

        [CommandMethod("Method1")]
        public void Method1()
        {
            // here the code of the Method1 command
        }

        [CommandMethod("Method2")]
        public void Method2()
        {
            // here the code of the Method2 command
        }

        [CommandMethod("Method3")]
        public void Method3()
        {
            // here the code of the Method3 command
        }

        [CommandMethod("Method4")]
        public void Method4()
        {
            // here the code of the Method4 command
        }

        [CommandMethod("TEST")]
        public void Test()
        {
            // here the code of the TEST command
        }

        static CustomPaletteSet palette;

        [CommandMethod("CMDPALETTE")]
        public void CmdPalette()
        {
            if (palette == null)
                palette = new CustomPaletteSet();
            palette.Visible = true;
        }
    }

The Palettetab class (UserControl)  with the buttons event handlers

    public partial class PaletteTab : UserControl
    {
        public PaletteTab()
        {
            InitializeComponent();
        }

        private void btnPc_Click(object sender, EventArgs e)
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            if (doc != null)
                doc.SendStringToExecute("PC ", false, false, true);
        }

        private void btnMethod1_Click(object sender, EventArgs e)
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            if (doc != null)
                doc.SendStringToExecute("Method1 ", false, false, true);
        }

        private void btnMethod2_Click(object sender, EventArgs e)
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            if (doc != null)
                doc.SendStringToExecute("Method2 ", false, false, true);
        }

        private void btnMethod3_Click(object sender, EventArgs e)
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            if (doc != null)
                doc.SendStringToExecute("Method3 ", false, false, true);
        }

        private void btnMethod4_Click(object sender, EventArgs e)
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            if (doc != null)
                doc.SendStringToExecute("Method4 ", false, false, true);
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            if (doc != null)
                doc.SendStringToExecute("TEST ", false, false, true);
        }
    }

The CustomPaletteSet class

    public class CustomPaletteSet : PaletteSet
    {
        public CustomPaletteSet()
            : base("COMMANDS", "CMDPALETTE", new Guid("{CB44AAE8-B3C8-4F97-817B-D5F96FDB3C1C}"))
        {
            Style = PaletteSetStyles.ShowAutoHideButton |
                    PaletteSetStyles.ShowCloseButton |
                    PaletteSetStyles.ShowPropertiesMenu;
            MinimumSize = new System.Drawing.Size(150, 220);
            Add("Tab", new PaletteTab());
        }
    }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 20

Anonymous
Not applicable

do you have a situation to mail me in a form of example I do not know too much yemiyorum mail can cihanbaki2147@gmail.com 

0 Likes
Message 5 of 20

_gile
Consultant
Consultant

I can try to help you here, in the forum, but I won't  communicate by mail.

 

If you clearly expose what you're trying to achieve, and show what you have done so far, you should get help from more people and every one could benefit of the discussion.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 6 of 20

Anonymous
Not applicable

I would like to add the palette creation phase as a video, which is more useful, I add the code, it gives an error, thank you very much for your video.

0 Likes
Message 7 of 20

_gile
Consultant
Consultant

If you want to get some help, please, give more precision about what you're already able to do and what you need help for.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 8 of 20

Anonymous
Not applicable
you will correct the mistakes in the article you added to the form and add the final form to you.
0 Likes
Message 9 of 20

Anonymous
Not applicable

you can correct the errors in the file and add the final state.

0 Likes
Message 10 of 20

Anonymous
Not applicable

I uploaded the wrong files. Could you upload these files to the forum after fixing these errors? I apologize for tiring you

0 Likes
Message 11 of 20

_gile
Consultant
Consultant
Accepted solution

Obviously you are missing the basics of .NET programming.
You should not start by wanting to make a palette for AutoCAD, it's like trying to run before you know how to walk.
You should start by learning the basics of object-oriented programming with .NET and C # outside AutoCAD and only when you are comfortable with the basics you can start learning the AutoCAD API (you'll get learning material here and the documentation here).

 

I attached the corrected 'palet' solution



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 12 of 20

Anonymous
Not applicable
Thank you very much for the valuable information you give
0 Likes
Message 13 of 20

Anonymous
Not applicable

Hi @_gile ,

How to disable the menu bar as image below:

longuyenstrongtie_0-1634908859673.png

 

0 Likes
Message 14 of 20

_gile
Consultant
Consultant

Hi,

As far as I know, you cannot. This is part of the PaletteSet.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 15 of 20

Anonymous
Not applicable

Can you offer a series of "new Guid" like this?

new Guid("63B8DB5B-10E4-4924-B8A2-A9CF9158E4F6")

I think it can be done by changing this Guid.

0 Likes
Message 16 of 20

_gile
Consultant
Consultant

There are many free GUID generators on the web, you can also use the one provided by Visual Studio (Tools menu > Create GUID).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 17 of 20

BlackBox_
Advisor
Advisor

@_gile wrote:

Hi,

 

A good practice should be:

  1. Define the commands (PC, Method1, Method2, Method3, Method4 and TEST) decoring them with the CommandMethod attribute so that they work as expected when called from AutoCAD Command line.
  2. Add a UserControl to the project with the buttons and define the Click handler of each button to launch the corresponding command with SendStringToExecute() method.
  3. Define a class deriving from PaletteSet to host the UserControl.
  4. Define a command to show the palette.

 


Was reading through this old thread and saw this post by @_gile - if only @TimYarris & team adhered to Step #2 (invoking Commands from Palettes or Context MenuItem.Click() events, instead of simply calling the underlying Method) we'd be able to fix a lot of issues on our own, by simply Veto()-ing Commands, fixing the issue, then re-invoke same.

 

Cheers


"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

Message 18 of 20

norman.yuan
Mentor
Mentor

@Anonymous 

If you want a window floating(modeless) like PalatteSet, but no the frame of the PaletteSet, then why use PaletteSet? You can simply create a winForm/WPF window and show it as modeless dialog/window, whoch you can set the winform/wpf window as borderless (but you surely want provide a way for user to close/hide the form/window, don't you?).

 

Norman Yuan

Drive CAD With Code

EESignature

Message 19 of 20

Anonymous
Not applicable

Hi @norman.yuan ,

Because the PaletteSet is always activate when autoCAD is activate and a winForm/WPF window is not.

I am looking for 2 solutions:
1. The PaletteSet without the Menu bar.
2. Setting winForm/WPF window always activate with autoCAD .

Currently I am using option 2:
I've set winForm/WPF window to always on top, but they're annoying when working with other programs. How to make winForm/WPF window always active when autoCAD is active?

0 Likes
Message 20 of 20

_gile
Consultant
Consultant

@Anonymous 

As @norman.yuan already said, you have to show the dialog box as modeless dialog using either:

Application.ShowModelessDialog with a WinForms dialog

or:

Application.ShowModelessWindow with a WPF dialog.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub