Author Topic: A very simple dockable palette application  (Read 14472 times)

0 Members and 1 Guest are viewing this topic.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
A very simple dockable palette application
« on: June 20, 2006, 06:15:36 PM »
For those new to C# and the arx .net api I thought I'd post a very simple dockable palette application to get you started.
So here goes -

1) Create a new class library application, add references to the 2 AutoCAD managed dll's, the Systym.Windows.Forms.dll and the System.Drawing dll.

2) Create 2 new UserControls, call them what you like but here I've used default names.

3) To each UserControl, add 1 button, to each button add some code to handle the click event (tip. double click the control in the ide)

4) Create a command to load up our palette and show it in AutoCAD.

5) Compile, load and give it a run.

Below is the typical code used to set up and load your palette, I've attached the solution (VS2002) for AutoCAD 2006, I'm sure it would take very little to compile in 2007.

Code: [Select]
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Collections;
using System.Data;
using System.Data.OleDb;

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Windows.ToolPalette;
namespace ClassLibrary1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class Class1
{
public Class1()
{
//
// TODO: Add constructor logic here
//
}
private Autodesk.AutoCAD.Windows.PaletteSet ps;
[CommandMethod("MyPalette")]
public void CreateMyPalette()
{
if(ps == null)
{
ps = new Autodesk.AutoCAD.Windows.PaletteSet("My Palette");
ps.Style = Autodesk.AutoCAD.Windows.PaletteSetStyles.ShowPropertiesMenu
| Autodesk.AutoCAD.Windows.PaletteSetStyles.ShowAutoHideButton
| Autodesk.AutoCAD.Windows.PaletteSetStyles.ShowCloseButton;
ps.Opacity = 90;
ps.Size = new System.Drawing.Size(250,400);
ps.MinimumSize = new System.Drawing.Size(225, 400);
//ctrl.Dock = System.Windows.Forms.DockStyle.Fill;
ps.Add("My Controls 1", new UserControl1());
ps.Add("My Controls 2", new UserControl2());
ps.Dock = Autodesk.AutoCAD.Windows.DockSides.None;
//You may or may not need the below code for list/combo boxes to retain focus.
//ps.KeepFocus = true;
ps.Visible = true;
}
else
{
ps.Visible = true;
}
}
}
}

Some typical code for the button event handler -
Code: [Select]
private void button1_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Activated Button 1 on User control 1!");
}

You may also need Document locking for times when you need to go to and from the editor, I'll post some typical code later, absorb this for now and if you have any questions, ask away :)
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.
- J.R.R. Tolkien

Bob Wahr

  • Guest
Re: A very simple dockable palette application
« Reply #1 on: June 20, 2006, 07:15:41 PM »
Thanks Mick.  I can actually follow it and it looks useful to boot.

LE

  • Guest
Re: A very simple dockable palette application
« Reply #2 on: June 20, 2006, 07:44:37 PM »
Very good Sir... once I got get! my Vegetable 8 Juice new VS 2005 (V8) and A2K7 this week, I give it a try out.

 :lol:

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: A very simple dockable palette application
« Reply #3 on: June 20, 2006, 09:51:47 PM »
Bookmarked Mick ... Thanks. !
I'll have a look when the fires go out.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

TR

  • Guest
Re: A very simple dockable palette application
« Reply #4 on: June 21, 2006, 09:32:51 AM »
Very nice. This should be quite useful.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: A very simple dockable palette application
« Reply #5 on: June 21, 2006, 05:48:04 PM »
Very nice. This should be quite useful.

Yep, I thought it might be, there are a few threads here where people are discussing dropping there current UI dev tools and thinking of going to .net.
This just might be the extra prod in the ribs they require  :evil:
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.
- J.R.R. Tolkien

LE

  • Guest
Re: A very simple dockable palette application
« Reply #6 on: June 21, 2006, 05:53:08 PM »
Mick;

So in other words, is no way to do this in plain jane arx?....  :-(

Thanks.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: A very simple dockable palette application
« Reply #7 on: June 21, 2006, 06:10:33 PM »
Yes Luis, there is, in fact you 'may' be able to do much more but no where near as easily as you can with .net.
Have a look at the sdk about palettes in arx, it's a COM & MFC nightmare. Although the palette set .net api is just a thin wrapper around the MFC portion it's still light years easier to use which is exactly what we need for 'customisation'.

I actually love C++ - when it's pure C++ - but it is more often a mix of C and C++ especially when it comes to working with the win32 api, your other option is to use MFC...

<edit>
Sorry Luis, after re-reading, the first few words were definitely not meant to 'sound' the way they looked  :oops:
</edit>
« Last Edit: June 21, 2006, 11:00:27 PM by MickD »
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.
- J.R.R. Tolkien

Draftek

  • Guest
Re: A very simple dockable palette application
« Reply #8 on: June 21, 2006, 10:27:15 PM »
I agree. It will be much easier to just expose your arx app to managed c# to write the UI's.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: A very simple dockable palette application
« Reply #9 on: April 17, 2010, 10:01:42 PM »
Yes Luis, there is, in fact you 'may' be able to do much more but no where near as easily as you can with .net.
Have a look at the sdk about palettes in arx, it's a COM & MFC nightmare. Although the palette set .net api is just a thin wrapper around the MFC portion it's still light years easier to use which is exactly what we need for 'customisation'.

It's this kind of talk that stopped me from ever trying, I hate COM in C++ and I don't particularly like nightmares either. After being traumatized for so many years and having spent so long in "C++ ain't bad" therapy, I finally worked the courage to give it try, while chewing on a tablespoon of coffee grounds, I managed to figure it out.  Geez, what a piece of cake. Add a CAdUiPaletteSet class, add couple of CAdUiPalette classes, make a command.

Code: [Select]
static void ExtTools_doit(void)
  {
    if(!gExtPaletteSet)
    {
      gExtPaletteSet = new CExtPaletteSet;
      CRect rect(0, 0, 250, 500);
      gExtPaletteSet->Create(_T("Palette"),
        WS_OVERLAPPED | WS_DLGFRAME, rect, acedGetAcadFrame());

      gBlockPalette = new CBlockPalette();
      gDummyPalette = new CAdUiPalette();

      gBlockPalette->Create(WS_CHILD |
        WS_VISIBLE,_T("Palette 1"),gExtPaletteSet,PS_EDIT_NAME);
      gExtPaletteSet->AddPalette(gBlockPalette);

      gDummyPalette->Create(WS_CHILD |
        WS_VISIBLE,_T("Palette 2"),gExtPaletteSet, PS_EDIT_NAME);
      gExtPaletteSet->AddPalette(gDummyPalette);

      gExtPaletteSet->EnableDocking(CBRS_ALIGN_ANY);
    }
    gExtPaletteSet->RestoreControlBar();
    CMDIFrameWnd* pAcadFrame = acedGetAcadFrame();
    pAcadFrame->ShowControlBar(gExtPaletteSet, TRUE, FALSE);
  }

voila ...

@ Mick, you do know I'm kidding right?  :laugh:
« Last Edit: April 17, 2010, 10:39:21 PM by Daniel »

sinc

  • Guest
Re: A very simple dockable palette application
« Reply #10 on: April 18, 2010, 09:40:15 AM »
Note that if you add a GUID to your call that creates the Palette set, Autocad will remember the location and size of the palette, even when you shut down and restart Autocad.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: A very simple dockable palette application
« Reply #11 on: April 19, 2010, 02:43:20 AM »
You're right! Thank you  8-)