Creating a plugin
This topic will describe setting up a CamBam plugin project in Visual Studio 2010, linking to the CamBam API references
and exposing methods to register the plugin in CamBam.
Creating the project
Create a new project in Visual Studio using File - New - Project.
From the list of project templates, choose Visual C# - Windows - Class Library.
At the top of the 'New Project' dialog, select .NET Framework version 2.0.
Enter the name of your project at the bottom of the dialog then press OK.
Setting references
Right click the Reference folder in the project tree and select New Reference.
The plugin will typically require the following standard .NET references:
- System.Drawing
- System.Windows.Forms
Next, in the add reference dialog, select the Browse tab, then browse to the CamBam program installation folder.
This is typically:
C:\Program Files\CamBam plus 0.9.8\
Select the following CamBam libraries from this folder:
- CamBam.CAD.dll
- CamBam.Geom.dll
- CamBam.OpenGL.dll
Change the build output directory.
Plugin .dlls must be located in the 'plugins' sub folder of the CamBam program installation folder.
For example:
C:\Program Files\CamBam plus 0.9.8\plugins\
To prevent having to manually copy the project output to this location, edit the project properties and select the Build tab.
Select configuration : All Configurations, then in the Output path property, browse to the CamBam plugin folder.
Save and close the project properties.
Setting up the plugin class
By default, the new project template will create a class called Class1. It is a good idea
to rename this class to something more meaningful. In this example MyPlugin.
The plugin class will need to provide a public static method called InitPlugin.
When CamBam starts, it will scan all the .dlls in the 'plugins' subfolder of the CamBam program installation folder.
If the library exposes InitPlugin, this method will be invoked once, which usually contains code
to register your plugin to a menu handler or other callback hooks.
Here is a skeleton plugin class that will initialise the plugin and define a menu handler that simply
displays a message box when selected.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using CamBam;
using CamBam.UI;
using CamBam.Util;
using CamBam.CAD;
namespace CBPluginDemo
{
public class MyPlugin
{
protected static CamBamUI _ui;
// This is the main entry point into the plugin.
public static void InitPlugin(CamBamUI ui)
{
// Store a reference to the CamBamUI object passed to InitPlugin
_ui = ui;
// Create a new menu item in the top Plugins menu
ToolStripMenuItem mi = new ToolStripMenuItem();
mi.Text = "My test plugin";
mi.Click += new EventHandler(TestPlugin_Click);
ui.Menus.mnuPlugins.DropDownItems.Add(mi);
}
// Simple menu handler
static void TestPlugin_Click(object sender, EventArgs e)
{
ThisApplication.MsgBox("Hi there!");
}
}
}
Compile the project (this should also copy the output to the CamBam plugins folder.
Note! CamBam must be closed before recompiling the plugin as it will lock any existing plugins
from being updated.
Start CamBam and your plugin should now appear in the Plugins menu.