Author Topic: Palettset and Palette newbie question.  (Read 2358 times)

0 Members and 1 Guest are viewing this topic.

Earthbound

  • Guest
Palettset and Palette newbie question.
« on: March 02, 2015, 02:32:38 PM »
I want to move from a winform app to a paletteset. I have public methods and properties I have created in my Winform however after moving my code over to a palette (user control) I no longer have access to those public methods through the Paletteset?!  Here is some Pseudo code...

(note: I have this posed here as well : http://forums.autodesk.com/t5/net/paletteset-and-palette-newbie-question/td-p/5525512)
 
public class MyPlugin : IExtensionApplication {
 private Document m_Adoc;
 private PaletteSet m_PaletteSet = null;
 private System.Windows.Forms.Control m_ucPalette = null;

 void IExtensionApplication.Initialize() {   
  Application.DocumentManager.DocumentActivated += new DocumentCollectionEventHandler(MonitorDocumentActi​vated);
  if (Application.DocumentManager.Count > 0) {
  this.m_Adoc = Application.DocumentManager.GetDocument(HostApplic​ationServices.WorkingDatabase);
  }
 }

 void IExtensionApplication.Terminate() {
  this.UnloadPlugin();
 }
 
    private void MonitorDocumentActivated(object sender, DocumentCollectionEventArgs e) {
         if (e.Document != null) {
            this.m_Adoc = e.Document;
            if (!this.m_Adoc.IsReadOnly) this.LoadPlugin();
         } else {
            if (m_MyPalettset != null) { this.UnloadPlugin(); }
         }
    }
 private void LoadPlugin() {
  if (Tools.IsRegApp()) {
   this.LoadPalettset();
  } else {
   //do something else here....
  }
 }
 
 private void LoadPalettset() {
     this.m_PaletteSet = new PaletteSet("Earthbound Designator Tool", Guid.Parse(guid));
        this.m_PaletteSet.Style = PaletteSetStyles.ShowPropertiesMenu | PaletteSetStyles.ShowAutoHideButton | PaletteSetStyles.Snappable;
        this.m_ucPalette = new MyPalette();
        this.m_PaletteSet.Add("ucPalette", m_ucPalette);
        this.m_PaletteSet.MinimumSize = new System.Drawing.Size(350, 535);
        this.m_PaletteSet.SetSize(new System.Drawing.Size(350, 535));
        this.m_PaletteSet.EnableTransparency(true);
        this.m_PaletteSet.Location = new System.Drawing.Point(400, 400);
        this.m_PaletteSet.Visible = true;
        this.m_PaletteSet.DockEnabled = DockSides.None | DockSides.Left | DockSides.Right;
        this.m_PaletteSet.Dock = DockSides.None;
        this.m_PaletteSet.StateChanged += new PaletteSetStateEventHandler(MonitorPaletteState);
// so let's say for example I wanted to call a custom method I have exposed in m_ucPalette
// how would I access that method from here?
//Or for that matter how would I gain access to any of the other controls on the palette?

// note: for this exercise I am trying to understand how to communicate between this InitClass and the controls on the Paletteset.
 
 }

private void UnLoadPlugin() {...}
 
}

Thank you!

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Palettset and Palette newbie question.
« Reply #1 on: March 02, 2015, 04:07:21 PM »
If your methods are declared public in your form class then you should have no problem calling them from the bold section of code. 

Expose your controls as properties and you can access them in the highlighted section of code too.

Once you get outside this block of code you have highlighted, you have to have the form react to the user and control will pass to your form.
Revit 2019, AMEP 2019 64bit Win 10

Earthbound

  • Guest
Re: Palettset and Palette newbie question.
« Reply #2 on: March 02, 2015, 04:56:49 PM »
Sorry, it looks like I did a poor job of describing what I want to do. I want to completely abandon using winforms and start using nothing but Palettes. So from my InitClass I want to be able to access the Palette (usercontrol and any public properties and methods I have created for it said control).

For example, lets say I have a set of blocks that I am tracking in a drawing. My palette has a list or datagridview of those blocks. One or more of those blocks is erased by the user. They are deleting that block via the command line. Taking advantage of the drawing database and document event handlers I want to be able to call a method or somehow notify the palette that that block or blocks needs to be removed from the list or the datagridview.

With my winform this was done by calling a method I exposed and works quite well.
That same method is now on the Palette but I see no way of communicating with that method now that it is on a palettset, why?

I was expecting to access it sot of like this:  m_Palettset.ucPalette.MyMethod();


« Last Edit: March 02, 2015, 05:02:51 PM by Earthbound »

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Palettset and Palette newbie question.
« Reply #3 on: March 03, 2015, 07:45:09 AM »
The PaletteSet is just a container.  You need to put something in it like a WinForm,  an ElementHost, or my favorite a WPF control. 

Not being a Winform guy, I'm not sure how you respond to Document/Database events.  In WPF, I would create a ViewModel, bind the ViewModel to the WPF User Control, and make changes to the ViewModels properties inside the Document/Database events.
Revit 2019, AMEP 2019 64bit Win 10

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Palettset and Palette newbie question.
« Reply #4 on: March 03, 2015, 08:03:59 AM »
As MexicanCustard said your paletteset and your palette must be defined as public in order to access them from the bolded section.  You currently have them defined as private.  At least in the code you posted before.


I was expecting to access it sort of like this:  m_Palettset.ucPalette.MyMethod();


This absolutely cannot happen as long as they are set to private.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Palettset and Palette newbie question.
« Reply #5 on: March 03, 2015, 08:07:12 AM »
Try watching this video.  DevTV: Introduction to AutoCAD .Net Programming.  In the video around the 1 hour 2 min mark the author (Fenton Webb) shows how using events he is adding and removing objects from a palette based on objects being added and erased from the database.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013