Wednesday, 28 January 2015

Metasequoia 4 Plugins – part 5

We can create a project template to generate an empty Metasequoia plugin project with most of the project properties already set.

Once we have created the project template we can select it from the list of templates in the File>Add>New Project dialog.

This means we won’t have to set all the project’s properties manually every time we create a new plugin.

Rather than create one template for all plugin categories as I do here you could make a separate template for each plugin category.

First we need to make a new plugin project that has all the settings we wish to save in the template.

With the mqsdk solution open in Visual Studio and selected in the Solution Explorer window add a new Visual C++ Win32 project.

I used spaces in the project name here but it is better if you do not have spaces in the name. The space caused an error for the Post-Build Event command.

Add new project to solution

Choose DLL and Empty project in Application Settings.

Choose DLL and Empty project

Set the project’s properties in the Property Pages the same as in previous posts.

Remember to click OK or Apply to save the changes.

Use the Using Visual Studio instructions in the mqsdk_en.html document to create Debug and Release configurations for 64 bit Windows if required.

Create 64 bit configuration

For All Configurations and All Platforms set Configuration Properties>General>Output Directory to “$(Platform)\$(Configuration)\”.

For All Configurations and All Platforms the Configuration Properties>General>Intermediate Directory to “$(Platform)\$(Configuration)\obj\”.

For All Configurations and All Platforms set Configuration Properties>General>Character Set to “Multi-Byte Character Set”.

Set General properties for all platforms

For All Configurations and All Platforms set Configuration Properties>C/C++>General > Additional Include Directories to “..” so Visual Studio will search the project’s parent directory for any SDK header files it needs for the project.

Set Additional Include directories

For Debug Configuration and All Platforms set Configuration Properties>Debugging> Command to the path to Metaseq.exe.

Unfortunately I found that this setting is not saved in the template and will have to be set for each project created using the template.

Set path to metaseq exe

For Debug Configuration and All Platforms use Command Prompt commands and Macros to set Configuration Properties>Build Events>Post-Build Event>Command Line to copy the output *.dll to the appropriate folder in Metasequoia\Plugins\.

This project property will need to be changed manually to match each type of plugin we create. If we create a wizard for the template we may be able to set this property from user input.

If creating separate templates for each plugin category the correct folder can be set for each.

Set Post-Build event

Add a new blank *.cpp file to the project and name it “myplugin.cpp”.

Add new cpp file

Add MQInit.cpp located in the project’s parent directory to the project.

Add MQInit cpp

Open myplugin.cpp in the editor and type in the following code which includes all the functions necessary for all categories of plugin.

Replace any information like the author name and Product (author) number to your personal details.

// REMEMBER to change destination folder in Post-Build Event command
// REMEMBER to set Debugging Command to Metaseq.exe
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <cstdio>
#include <cstdlib>
#include "MQPlugin.h"
// TODO rename this function
BOOL myfunction(const char *filename, MQDocument doc);
BOOL myfunction(MQDocument doc);
MQPLUGIN_EXPORT void MQGetPlugInID(DWORD *Product, DWORD *ID)
{
*Product = 0xc0cca200;
// TODO change ID number
*ID = 0xcccccccc;
}
MQPLUGIN_EXPORT const char *MQGetPlugInName(void)
{
// TODO enter plugin description
return "Plugin (c) 2014 sapper";
}
MQPLUGIN_EXPORT int MQGetPlugInType(void)
{
// TODO change to correct plugin type
return MQPLUGIN_TYPE_IMPORT;
//return MQPLUGIN_TYPE_EXPORT;
//return MQPLUGIN_TYPE_CREATE;
//return MQPLUGIN_TYPE_OBJECT;
//return MQPLUGIN_TYPE_SELECT;
//return MQPLUGIN_TYPE_STATION;
//return MQPLUGIN_TYPE_COMMAND;
}
// This function required for Import/Export plugins only
MQPLUGIN_EXPORT const char *MQEnumFileType(int index)
{
switch (index){
// TODO change extension description
case 0: return "File Type(*.mqo)";
}
return NULL;
}
// This function required for Import/Export plugins only
MQPLUGIN_EXPORT const char *MQEnumFileExt(int index)
{
switch (index){
// TODO change extension
case 0: return "mqo";
}
return NULL;
}
// This function required for Import plugins only
MQPLUGIN_EXPORT BOOL MQImportFile(int index, const char *filename, MQDocument doc)
{
switch (index){
// TODO rename function to match forward declaration up top
case 0: return myfunction(filename, doc);
}
return FALSE;
}
// This function required for Export plugins only
MQPLUGIN_EXPORT BOOL MQExportFile(int index, const char *filename, MQDocument doc)
{
switch (index){
// TODO rename function to match forward declaration up top
case 0: return myfunction(filename, doc);
}
return FALSE;
}
// This function used by all plugins except Import/Export
// The string appears as the menu item caption
MQPLUGIN_EXPORT const char *MQEnumString(int index)
{
switch (index){
// TODO change text to plugin name
case 0: return "Plugin";
}
return NULL;
}
// This function required for Create plugins only
MQPLUGIN_EXPORT BOOL MQCreate(int index, MQDocument doc)
{
switch (index){
// TODO rename function to match forward declaration up top
case 0: return myfunction(doc);
}
return FALSE;
}
// This function required for Select plugins only
MQPLUGIN_EXPORT BOOL MQModifySelect(int index, MQDocument doc)
{
switch (index){
// TODO rename function to match forward declaration up top
case 0: return myfunction(doc);
}
return FALSE;
}
// This function required for Object plugins only
MQPLUGIN_EXPORT BOOL MQModifyObject(int index, MQDocument doc)
{
switch (index){
// TODO rename function to match forward declaration up top
case 0: return myfunction(doc);
}
return FALSE;
}
// This function required for Command/Station plugins
// In the SDK samples these plugins are all class plugins
// Unsure how to implement in a non class plugin
// See MQOnEvent in MQBasePlugin.cpp for example
BOOL MQOnEvent(MQDocument doc, int event_type, void *option)
{
// See MQPlugin.h for all event types
return FALSE;
}
// This function used for Import/Export plugins
// This function does all the "work"
// TODO rename to match forward declaration up top
BOOL myfunction(const char *filename, MQDocument doc)
{
// TODO write code here
return TRUE;
}
// This function used for plugins other than Import/Export
// This function does all the "work"
// TODO rename to match forward declaration up top
BOOL myfunction(MQDocument doc)
{
// TODO write code here
return TRUE;
}
view raw myplugin.cpp hosted with ❤ by GitHub


Save all if you haven’t already and click File>Export Template to run the Export Template Wizard.
Select Project Template and select the project in the drop down list.

Run the export Template Wizard

Name the template, add a description and icon and preview images if you wish.

Uncheck the option to automatically import into Visual Studio but do check the option to open the exported template folder in File Explorer.

Template Options

Navigate to your custom project template folder which by default is, C:\Users\<username> \Documents\Visual Studio 2013\Templates\ProjectTemplates\.

Create a new folder named “Metasequoia Plugin” inside the Visual C++ Project folder.

Copy to the Visual C   Projects custom template folder

Copy the zip file containing the exported project template into the “Metasequoia Plugin” folder you created.

The template now appears in the template list and can be used as a starting point for a new plugin project.

Project template in Add New Project dialog



prev | next | first

No comments:

Post a Comment