Creating a plugin for A:M V9 and higher

At first you should download the example project here.
After starting Visual C++ we create a new project with FILE->NEW. The dialog window should look like this (with english descriptions of course, if you're using the english version of VC++)
Bild2
Now we choose the MFC-Application-Assistent, then give our project a name (sample), and choose our working directory. It's convenient to choose a working directory under the path AM90SDK\PLUGIN\HXT, the directory will be created automatically.
In the example it would be: AM90SDK\PLUGIN\HXT\sample .

After confirming with ok, there are more options of the application-assistent, but we don't have to change anything here and we can click on finish.
Bild2

After were again in the main window, we have to make some adjustements to reference the path for the includes and libraries of the AM SDK. This is done with project-options .

At first we choose the C/C++ page, on this page praeprocessor and all definitions and we add the path of the AM SDK-includes to additional include-directories. The easiest way is to use relative path-addresses, in the example: ..\..\..\include .
Bild3

Now we have to change the extension of the file, which will be created, into .hxt and to set the libraries of the SDK, which will be linked to our project. This configuration is made on the "Linker"-page.
At first for the debug-version
Bild7
And for the release-version
Bild8
It's important to make sure, that both versions are created in different directories (again relative path) and that both file-extensions are changed to .hxt.

These are the necessesary configuration options for the project.

Now we go to the main window.
For the description, which will be visible in the menu in A:M, we create a string ressource with Insert->Ressource .
Bild9
Here the string table is to be chosen and created with New
Now we set on the first entry IDS_STRING1 the menu name.
Bild10
It's important to use the ID of the string (here: ID_STRING1) if the name of the menu is added to the menu in the function HxtOnAddCommandMenu in entry.cpp.

Next we create a simple dialog with Insert->Ressource Dialog .
Bild12
Now we have our simple dialog.
And we create with the class-assistent a new class for this dialog.
Bild13
Here we choose a new class and give it in the next step the name sample_dialog.
Bild14
Now the frame for our project is ready. Following is the actual coding for which it would be useful to take a look on the source of the example project.
At first a new C++-source file has to be added to the project. We call it entry.cpp. In this file
are the functions for initialization: HxtLoadCommandEntry (determines which type of object AM should create, definitions are in includes\objtype.h), HxtOnAddCommandMenu (determines the name of the plugin as shown in the menu and the type of the plugin),
and HxtOnCommand (the function, which is executed after calling the plugin).
It's important to check, if all includes are set. The easiest way is to copy the functions out of the sample source code into your project.

Now we have to do some changes in sample.h.
We insert the following includes
#include "SDK\HPropert.h"
#include "SDK\HPropDri.h"
#include "SDK\HPatch.h"
#include "SDK\HModel.h"
And the classes
class HModelCache;
class HGroupCP;
And the function
BOOL OnSampleWizard(HModelCache *hmc);
at least
virtual BOOL InitInstance();
virtual int ExitInstance();
(The place where to put these insertions you could find in the source code file sample.h :-))
The new functions now have to be fleshed out of course and this happens in
sample.cpp. I only mention the most important function in this tutorial: OnSampleWizard .
BOOL CSampleApp::OnSampleWizard(HModelCache *hmc)
{
sample_dialog dlg(NULL); //creation of the dialog
if (dlg.DoModal()!=IDOK)
return TRUE;

return TRUE; //here is otherwise the function, which does the work;
//in the example project the function does nothing
//so: return TRUE
//in a real project it could be: return NewShape(hmc), as shown in Grid\HXT.cpp Grid\evalute.cpp
}

That's all. After pressing F7 the example project should be compiled without any problem. If there are problems, you better compare your code with the sample code provided here. Mostly forgotten includes are responsible for problems. After successfull compiling copy the file sample.hxt in the AM HXT directory and after a new start of AM the plugin should be visible if a object or model is selected.
To see how to make something useful with the plugin, you have to study the sources of the example plugins of the SDK. Personally I found the grid-plugin the most helpful; also it's the model for my first plugin.
My second minitutorial shows how to debug such a plugin.

Return