AutoCAD .NET has wrapped almost all ObjectARX events through one way or another using still the event concept or something slightly different. As a whole, the AutoCAD .NET event or notification system is powerful and useful and a professional and relatively big addin cannot totally ignore the important force.
In this article, we will be talking about the AutoCAD .NET RibbonPaletteSet events. It is always good to start with some cool, concise and still full sample code. Here it is:
using System;
using System.Text;
using System.Linq;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Forms;
using System.IO;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.GraphicsSystem;
using GSManager = Autodesk.AutoCAD.GraphicsSystem.Manager;
using GSView = Autodesk.AutoCAD.GraphicsSystem.View;
using GSDevice = Autodesk.AutoCAD.GraphicsSystem.Device;
using GSModel = Autodesk.AutoCAD.GraphicsSystem.Model;
using AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application;
using AcadDocument = Autodesk.AutoCAD.ApplicationServices.Document;
using AcadWindows = Autodesk.AutoCAD.Windows;
namespace AcadNetAddinWizard_Namespace
{
public class RibbonPaletteSetEvents
{
[CommandMethod("TestRibbonPaletteSetEvents")]
public void TestRibbonPaletteSetEvents_Method()
{
RibbonPaletteSetEvents eventManager = new RibbonPaletteSetEvents();
eventManager.Register();
}
public void Register()
{
Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.Destroy += new EventHandler(RibbonPaletteSet_Destroy);
Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.DockStateChanged += new EventHandler(RibbonPaletteSet_DockStateChanged);
Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.Help += new PaletteSetHelpEventHandler(RibbonPaletteSet_Help);
Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.HostSizeChanged += new EventHandler<Autodesk.Internal.Windows.RibbonHostWindowSizeEventArgs>(RibbonPaletteSet_HostSizeChanged);
Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.Loaded += new EventHandler(RibbonPaletteSet_Loaded);
Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.Moved += new EventHandler(RibbonPaletteSet_Moved);
Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.Save += new PalettePersistEventHandler(RibbonPaletteSet_Save);
Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.SizeChanged += new PaletteSetSizeEventHandler(RibbonPaletteSet_SizeChanged);
Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.StateChanged += new PaletteSetStateEventHandler(RibbonPaletteSet_StateChanged);
Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.Unloading += new EventHandler(RibbonPaletteSet_Unloading);
Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.VisibleChanged += new EventHandler(RibbonPaletteSet_VisibleChanged);
}
void RibbonPaletteSet_VisibleChanged(object sender, EventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("RibbonPaletteSet_VisibleChanged\n");
}
void RibbonPaletteSet_Unloading(object sender, EventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("RibbonPaletteSet_Unloading\n");
}
void RibbonPaletteSet_StateChanged(object sender, PaletteSetStateEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("RibbonPaletteSet_StateChanged\n");
}
void RibbonPaletteSet_SizeChanged(object sender, PaletteSetSizeEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("RibbonPaletteSet_SizeChanged\n");
}
void RibbonPaletteSet_Save(object sender, PalettePersistEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("RibbonPaletteSet_Save\n");
}
void RibbonPaletteSet_Moved(object sender, EventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("RibbonPaletteSet_Moved\n");
}
void RibbonPaletteSet_Loaded(object sender, EventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("RibbonPaletteSet_Loaded\n");
}
void RibbonPaletteSet_HostSizeChanged(object sender, Autodesk.Internal.Windows.RibbonHostWindowSizeEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("RibbonPaletteSet_HostSizeChanged\n");
}
void RibbonPaletteSet_Help(object sender, PaletteSetHelpEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("RibbonPaletteSet_Help\n");
}
void RibbonPaletteSet_DockStateChanged(object sender, EventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("RibbonPaletteSet_DockStateChanged\n");
}
void RibbonPaletteSet_Destroy(object sender, EventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("RibbonPaletteSet_Destroy\n");
}
}
}
The code is short and self-explanatory so we will not waste our words here. Let us play around the command and look at some command outputs:
Command: TestRibbonPaletteSetEvents
Command: RIBBONCLOSE
RibbonPaletteSet_VisibleChanged
RibbonPaletteSet_StateChanged
RibbonPaletteSet_VisibleChanged
RibbonPaletteSet_StateChanged
Command: RIBBON
RibbonPaletteSet_DockStateChanged
RibbonPaletteSet_VisibleChanged
RibbonPaletteSet_StateChanged
RibbonPaletteSet_DockStateChanged
RibbonPaletteSet_VisibleChanged
RibbonPaletteSet_StateChanged
Command: RibbonPaletteSet_HostSizeChanged
RibbonPaletteSet_SizeChanged
RibbonPaletteSet_HostSizeChanged
RibbonPaletteSet_SizeChanged
RibbonPaletteSet_HostSizeChanged
RibbonPaletteSet_SizeChanged
RibbonPaletteSet_HostSizeChanged
RibbonPaletteSet_SizeChanged
RibbonPaletteSet_HostSizeChanged
RibbonPaletteSet_SizeChanged
RibbonPaletteSet_VisibleChanged
RibbonPaletteSet_StateChanged
RibbonPaletteSet_DockStateChanged
RibbonPaletteSet_VisibleChanged
RibbonPaletteSet_StateChanged
RibbonPaletteSet_HostSizeChanged
RibbonPaletteSet_SizeChanged
RibbonPaletteSet_VisibleChanged
RibbonPaletteSet_StateChanged
RibbonPaletteSet_HostSizeChanged
RibbonPaletteSet_SizeChanged
RibbonPaletteSet_DockStateChanged
RibbonPaletteSet_VisibleChanged
RibbonPaletteSet_StateChanged
RibbonPaletteSet_HostSizeChanged
RibbonPaletteSet_SizeChanged
RibbonPaletteSet_VisibleChanged
RibbonPaletteSet_StateChanged
RibbonPaletteSet_Moved
RibbonPaletteSet_HostSizeChanged
RibbonPaletteSet_SizeChanged
RibbonPaletteSet_Moved
RibbonPaletteSet_DockStateChanged
RibbonPaletteSet_VisibleChanged
RibbonPaletteSet_StateChanged
RibbonPaletteSet_HostSizeChanged
RibbonPaletteSet_SizeChanged
RibbonPaletteSet_Moved
Command:
Command:
Command:
Command:
Command:
Command: _RibbonClose RibbonPaletteSet_VisibleChanged
RibbonPaletteSet_StateChanged
RibbonPaletteSet_VisibleChanged
RibbonPaletteSet_StateChanged
Command: RIBBON
RibbonPaletteSet_DockStateChanged
RibbonPaletteSet_VisibleChanged
RibbonPaletteSet_StateChanged
RibbonPaletteSet_DockStateChanged
RibbonPaletteSet_VisibleChanged
RibbonPaletteSet_StateChanged
By the way, the sample code does not cover how to unsubscribe these events. I would like to leave it as an exercise to readers who have interest.
The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) provides kinds of AutoCAD .NET Event Handler Wizards including an AutoCAD RibbonPaletteSet Event Wizard to help create start code of event handlers automatically, quickly, flexibly and reliably.
Recent Comments