Sei sulla pagina 1di 3

29/3/2014 Repetier-Host-Plugin

http://rhplugins.repetier.com/ 1/3
Repetier-Host Plugin Guide
Introduction
Also we try to include as many functions as seem reasonable for such a host system, there are always cases, where you want special modifications. Maybe because you
have a printer with some special functions or you want extra tools for your daily work. To give you this flexibility, the host comes from version 0.95 onwards with a simple
to extend plugin system. All you need to do is create a plugin and copy the plugin into the hosts plugin folder. On the next start it will be included.
With a plugin you can do things like:
Add menu entries.
Add toolbar items.
Send commands to printer.
Watch printer response for special actions.
Add new communication protocols.
Add new slicers.
Add new panels.
Add your credits to the about dialog.
Distribution
If you are the author of a plugin you can do everything with it, as you like. You can sell it or offer it as download. The only thing you can not do is make a new bundle with
Repetier-Host and your plugins. What you can do is write a installer for your plugin, that adds the plugin to an existing host installation.
If you want a customized host with your plugins, please visit this website. We put a lot of work into our software and there are bills to be paid. That is our way to keep a
free version for all. Our custom versions also include more individualization for your printer.
Create a plugin
A plugin is nothing else as a c# library packed into a special directory structure. First you need a name for your plugin. For internal use choose a name without spaces. The
compiled library must create a dll that has the name of the plugin and that lies inside a directory with the same name in the hosts plugin directory. Inside that plugin, you
must have a class named like the plugin using a namespace named like the plugin implementing the interface RepetierHostExtender.interfaces.IHostPlugin.
For this tutorial we create a plugin named DemoPlugin. First we open VisualStudio and create a library project with that name. Then we add the RepetierHostExtender.dll
to the project references. Disable adding a local copy of RepetierHostExtender.dll. You find this dll in the host installation directory. Then we rename the default class to
DemoPlugin and set the namespace to DemoPlugin. We add some stubs for the interface methods. The code should now look like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RepetierHostExtender.interfaces;
namespace DemoPlugin
{
public class DemoPlugin : IHostPlugin
{
IHost host;
/// Called first to allow filling some lists. Host is not fully set up at that moment.
public void PreInitalize(IHost _host)
{
host = _host;
}
/// Called after everything is initalized to finish parts, that rely on other initializations.
/// Here you must create and register new Controls and Windows.
public void PostInitialize()
{
}
/// Last round of plugin calls. All controls exist, so now you may modify them to your wishes.
public void FinializeInitialize()
{
}
}
}
You see there are only three methods to implement. Each method is called for all plugins in that order:
1. PreInitalize
2. PostInitialize
3. FinializeInitialize
In PreInitalize you get the reference to the host instance. You need that for most operations, so you better store that value for later use. It is also the right place to register
host components. You can already to some initalization stuff that does not depend on other high level host functions.
The main initialization is done in PostInitialize. Here all basic components of the host are registered and can be used.
If you want to remove menu entries, tabs etc, this should be done in FinializeInitialize. It should be reserved on actions that require parts which get created in the first 2
initalization rounds.
29/3/2014 Repetier-Host-Plugin
http://rhplugins.repetier.com/ 2/3
If you want to test your plugin, you need to start the host. So it is a good idea to set the destination folder to the hosts plgin/DemoPlugin directory. You can copy the
complete host to a standard place or use the version in Program Files. Using the Progam Files version has one little drawback, as it is protected by windows. When you
created the DemoPlugin directory change the ownership and grant your self full privileges, or you will not be able to save the dll. Test if compilation works and you get the
dll in the directory. Don't bother to start the host - you will see nothing. But we are gonna change that now. First we want to create an additional tab for very specialized
controls. We create a UserControl and add 3 Buttons on it - Left / Right / Home. That should not be very complicated. But to get it in place and get a connection to the
host we need to implement using RepetierHostExtender.interfaces.IHostComponent. Together with the functions for the buttons we get the following code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RepetierHostExtender.interfaces;
namespace DemoPlugin
{
public partial class CoolControl : UserControl,IHostComponent
{
private IHost host;
public CoolControl()
{
InitializeComponent();
}
///
/// Store reference to host for later use
///
/// Host instance
public void Connect(IHost _host)
{
host = _host;
}
#region IHostComponent implementation
// Name inside component repository
public string ComponentName { get { return "CoolControl"; } }
// Name for tab
public string ComponentDescription { get { return "Cool Control"; } }
// Used for positioning.
public int ComponentOrder { get { return 8000; } }
// Where to add it. We want it on the right tab.
public PreferredComponentPositions PreferredPosition { get { return PreferredComponentPositions.SIDEBAR; } }
// Return the UserControl.
public Control ComponentControl { get { return this; } }
#endregion
#region Button functions
private void buttonLeft_Click(object sender, EventArgs e)
{
if(host.Connection.connector.IsConnected())
host.Connection.injectManualCommand("G1 X0");
}
private void buttonRight_Click(object sender, EventArgs e)
{
if (host.Connection.connector.IsConnected())
host.Connection.injectManualCommand("G1 X100");
}
private void buttonHome_Click(object sender, EventArgs e)
{
if (host.Connection.connector.IsConnected())
host.Connection.injectManualCommand("G28");
}
#endregion
}
}

Now that we have our tab ready to work, we need to add it. We do this in the PostInitalize method. All needed is a call to the host.RegisterHostComponent method with
an instance of it. We also want our attribution in the about dialog. Now the PostInitalize method looks like this:
public void PostInitialize()
{
// Add the CoolControl to the right tab
CoolControl cool = new CoolControl();
cool.Connect(host);
host.RegisterHostComponent(cool);
// Add some text in the about dialog
host.AboutDialog.RegisterThirdParty("DemoPlugin", "\r\n\r\nDemoPlugin written by Repetier\r\nUse it like you want.");
}
29/3/2014 Repetier-Host-Plugin
http://rhplugins.repetier.com/ 3/3

You can download the sources for this demo plugin here. You might need to change the dll reference and target directory.
Download DemoPlugin
Important hooks
Adding menu entries
The IHost interface provides a GetMenuFolder method to retrieve all main folders. The parameter determines the Menu to return.
Using registry
You should save your data in the same registry tree like the host does. Use the IHost function GetRegistryFolder for this. Usage is then like this:
IRegMemoryFolder reg = GetRegistryFolder ("DemoPlugin");
double speed = reg.GetDouble("speed",100);
...
reg.SetDouble(speed,newSpeed);
Check the RepetierHostExtender.interfaces.IRegMemoryFolder reference for other types and window positions.
Classes
The plugin structure is fairly new, so some interfaces may grow or change if required. There are also many other classes and methods that may be useful for you. We can
not describe them all in detail, but we gave them meaningful names so most of it should be self-explanatory.
Repetier-Host 0.95 Plugin Classes
Some delegates and enums not visible in class description
namespace RepetierHostExtender.interfaces
{
public delegate void PrinterChangedEvent(IPrinter printer);
public delegate void FunctionInt(int val);
public delegate void FunctionString(string val);
public delegate void FunctionVoid();
public delegate void FunctionSDStateChanged(GCodeAnalyzer.SDStateValue old,GCodeAnalyzer.SDStateValue current);
public delegate void FunctionGCode(GCode code);
public enum ProgressType
{
NONE, // Nothing to progress
PRINT_JOB,
UPLOAD_JOB,
CACHE_JOB,
SDPRINT
};
public enum MenuFolder
{
FILE_MENU = 0,
VIEW_MENU,
CONFIG_MENU,
TEMPERATURE_MENU,
PRINTER_MENU,
TOOLS_MENU,
HELP_MENU
};
public delegate void ProgressChangedEvent(ProgressType pType,double value);
}

Introduction
Create a plugin
Classes

Potrebbero piacerti anche