Thursday, 22 January 2015

Metasequoia 4 Plugins – part 3

For more practise with creating plugins we will build a sample plugin that is bundled with mqdl’s Keynote plugin [link]. [web.archive.org]

Keynote is a plugin that allows animating in Metasequoia and includes another plugin to save the animations to *.x format.

The sample plugin included with Keynote is an Export plugin and demonstrates how to get the data from Keynote so you can save an animation.

The sample plugin doesn’t actually save a file but displays it in a console window.

The plugin needs the Keynote plugin (bone.dll) installed because it uses Keynote functions to access the data.

Instead of installing the Japanese version of Keynote there is a translated version available at the Sword of Moonlight forum [link].

I only tested with the Japanese version and the sample files and sample plugin are only included in the Japanese download.

To access the data Keynote must also be activated in the command panel otherwise the sample plugin reports an error.

With the Metasequoia SDK solution open in Visual Studio go to FILE>Add>New Project.
Select Visual C++, Win32 Project and give it a name.

Add a project

Make sure you select DLL and empty project in the Application Settings.

Select DLL and Empty Project

Open the project’s folder in File Explorer by choosing that option from the menu when you right click on the project in Solution Explorer.

Copy all the files from the “sdk” folder inside the Keynote download folder into the project folder.

Copy files to project folder

With the project selected in Solution Explorer go to PROJECT>Add Existing Item and add all the files we copied into the project folder.

The files should appear listed under the project in the Solution Explorer Window.

Add the existing files to the project

Click FILE>Save All to save the new project.

Double click on the Sources\ExportXS.cpp file in Solution Explorer to open it in the text editor.

Open ExportXS cpp in text editor

Notice all the red marks on the right hand side of the editor indicating errors. The errors should reduce as we add files and configure the project properties.

Scrolling through the code you see the functions have “ExportXS::”  before their names.

In the previous post we created the plugin using plain functions but this plugin is a class and the functions are preceded by “ExportXS::” to indicate that the functions belong to a class.

If you need a 64 bit version of the plugin follow the “Using Visual Studio” instructions in the documentation included with the Metasequoia SDK to configure the project to build a 64 bit *.dll and make sure you select that platform when you build the project.

In the project’s Property Pages for All Configurations, set Configuration Properties>C/C++>General>Additional Include Directories to “..”.

This means Visual Studio will look in the project’s parent folder for any MQ*.h header files the project needs.

Set Additional Include Directoriess

With the Property Pages still open go to Configuration Properties>General and for All Configurations set
  • Output Directory to “$(Platform)\$(Configuration)\”
  • Intermediate Directory to “$(Platform)\$(Configuration)\obj\”
  • Character Set to “Use Multi-Byte Character Set”
Click Apply to save the changes.

Set Output directories and Character Set

For the Debug configuration set Configuration Properties>Debugging>Command to the path to Metaseq.exe, e.g. “C:\Program Files\Metasequoia\Metaseq.exe”.

For the Debug configuration set Configuration Properties>Build Events>Post-Build Event>Command Line to a command that will copy the *.dll to the Export folder in the Metasequoia\Plugins\Export folder, e.g. “copy $(TargetPath) “C:\Program Files\Metasequoia\Plugins\Export\”.

Click OK to save the changes and close the Property Pages.

You will notice the red marks on the right hand side of the editor have mostly disappeared now that Visual studio can locate the header files.

The one remaining error is because of a missing semi colon  “;” at the end of line 364 so add it.

Next we need to add the MQ*.cpp files required.

All plugins require MQInit.cpp so add that to the project using Add>Existing Item.

One of the included files in ExportXS.cpp is MQBasePlugin.h so add MQBasePlugin.cpp to the project.

Right click on the text “MQBasePlugin.h” and use the Open Document MQBasePlugin.h option to open it in the editor.

At the top of MQBasePlugin.h we see that MQPlugin.h is included so add MQPlugin.cpp to the project.

Build the project with BUILD>Build projectname.

Unresolved symbol error

We get a linker error about an unresolved symbol. This usually means the linker looked for the compiled code (object code) for some function and couldn’t find it.

In this case it mentions MQSetting so add MQSetting.cpp to the project and build the project again.

Building succeeds so plugins defined as a class need the following *.cpp files added to the project.
  • MQInit
  • MQSetting
  • MQBasePlugin
  • MQPlugin

Click the Local Windows Debugger toolbar button or DEBUG>Start Debugging to start Metasequoia so we can test the plugin.

Open “chara.mqo” located in “sample” folder of the Keynote download and click the button at the bottom of the command panel to activate Keynote.

If you installed the Japanese version it may have a mojibake caption.

Activate Keynote

Since the plugin we created was an Export plugin it appears as a file type in the Save File dialog when we use Save As.

If XSFormat is not in the list check that the *.dll that matches your project's name is in the Plugins\Export folder.

Select XS Format in the Save as Type dropdown and click Save.

Save as XSFormat

The plugin creates a console window for its output and pauses a couple of times waiting for keypresses before printing out all the data.

Output start

Output finish




prev | next | first

No comments:

Post a Comment