ContextMenuExtension Attacher is a coder of the AutoCAD .NET Addin Coder group of AutoCAD .NET Addin Wizard (AcadNetAddinWizard). It can be found from the menu group of AutoCAD .NET Addin Coder under the Tools main menu or the toolbar:
After the ContextMenuExtension Attacher menu item or toolbar button is cliecked, the AutoCAD ContextMenuExtension Attacher window will pup up:
If some ContextMenu Extensioners have already been created in the project, they will be listed out in the Context Menu Extension combo box. If it is empty, it means no ContextMenu Extension has been defined. Then the ContextMenu Extensioner wizard can be used to help us create the ContextMenu Extension automatically in no time.
Then we can choose what kind of environments to attach the ContextMenuExtension, the object context menu of a particular AutoCAD .NET object type, which can be selected from another handy combo box, or the application default context menu.
Last we can choose where to place the ContextMenuExtension Attacher, in an Extension Application, under the current cursor position, or both.
If the options are set as the above dialog shows and the current cursor is placed inside the try block of the following local command:
[CommandMethod("CmdGroup1", "Command1", null, CommandFlags.Modal, null, "AcadNetAddinCS1", "Command1")]
public void Command1_Method()
{
Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
}
catch (System.Exception ex)
{
Debug.WriteLine(ex.ToString());
ed.WriteMessage(ex.ToString());
}
}
The ContextMenuExtension Attacher code will be generated automatically for both the Circle context menu and the AutoCAD application default context menu:
[CommandMethod("CmdGroup1", "Command1", null, CommandFlags.Modal, null, "AcadNetAddinCS1", "Command1")]
public void Command1_Method()
{
Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
ContextMenuExtensioner1 cmExtForAppDefault = new ContextMenuExtensioner1();
MgdAcApplication.AddDefaultContextMenuExtension(cmExtForAppDefault);
ContextMenuExtensioner1 cmExtForObj = new ContextMenuExtensioner1();
RXClass rx = RXClass.GetClass(typeof(Circle));
MgdAcApplication.AddObjectContextMenuExtension(rx, cmExtForObj);
}
catch (System.Exception ex)
{
Debug.WriteLine(ex.ToString());
ed.WriteMessage(ex.ToString());
}
}
And the Initialize method of the chosen IExtensionApplication derivative will look like the following with the ContextMenuExtension attaching code appended as well:
public void Initialize()
{
//TODO: add code to run when the ExtApp initializes. Here are a few examples:
// Checking some host information like build #, a patch or a particular Arx/Dbx/Dll;
// Creating/Opening some files to use in the whole life of the assembly, e.g. logs;
// Adding some ribbon tabs, panels, and/or buttons, when necessary;
// Loading some dependents explicitly which are not taken care of automatically;
// Subscribing to some events which are important for the whole session;
// Etc.
//
//
ContextMenuExtensioner1 cmExtForAppDefault = new ContextMenuExtensioner1();
MgdAcApplication.AddDefaultContextMenuExtension(cmExtForAppDefault);
ContextMenuExtensioner1 cmExtForObj = new ContextMenuExtensioner1();
RXClass rx = RXClass.GetClass(typeof(Circle));
MgdAcApplication.AddObjectContextMenuExtension(rx, cmExtForObj);
}
The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) provides some cool coders to facilitate the development work using AutoCAD .NET API.
Recent Comments