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 RibbonServices 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 RibbonServicesEvents
{
[CommandMethod("TestRibbonServicesEvents")]
public void TestRibbonServicesEvents_Method()
{
RibbonServicesEvents eventManager = new RibbonServicesEvents();
eventManager.Register();
}
public void Register()
{
Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSetCreated += new EventHandler(RibbonServices_RibbonPaletteSetCreated);
}
void RibbonServices_RibbonPaletteSetCreated(object sender, EventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("RibbonServices_RibbonPaletteSetCreated\n");
}
}
}
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 RibbonServices Event Wizard to help create start code of event handlers automatically, quickly, flexibly and reliably.
Posted by: |