An Add-In is a plugin that also loads DLLs that expose new JavaScript APIs.
Download FormIt API
To build DLLs that support FormIt, the FormIt API is needed. The FormIt API can be downloaded from the Autdesk Developers Network. A login is needed to access the download.
Once logged in, the FormIt API is available under SOFTWARE.
// FormIt looks for REGISTERAPIMETHODS to load new JS APIs
REGISTERAPIMETHODS
{
// Declare new namespace for the new JS APIs
REGISTERNAMESPACE("HelloDLL")
// Create a JS API with no arguments
APIMETHOD(HelloDLL, API1, "") {}
// Create a JS API with 1 argument
APIMETHOD(HelloDLL, API2, "arg1") {}
// Create a JS API with 2 argument
APIMETHOD(HelloDLL, API3, "arg1, arg2") {}
...
...
}
To get the arguements into C++ variables use SCRIPTCONVERTER-
// Create a JS API with 2 argument
APIMETHOD(HelloDLL, API3, "arg1, arg2")
{
// NOTE: The arg names above ^^^^ have to match the args in the macros below.
// arg1 expects a bool
SCRIPTCONVERTER(bool, arg1);
// arg2 expects an int
SCRIPTCONVERTER(int, arg2);
return JSON_UNDEFINED;
}
Either JSON_UNDEFINED or any json object can be returned. Use to_json to convert your C++ variable to json
// Create a JS API with 2 argument
APIMETHOD(HelloDLL, API3, "arg1, arg2")
{
// NOTE: The arg names above ^^^^ have to match the args in the macros below.
// arg1 expects a bool
SCRIPTCONVERTER(bool, arg1);
// arg2 expects an int
SCRIPTCONVERTER(int, arg2);
std::string myValue = "Test";
return to_json(myValue);
}
Once the DLL is defining all the needed JS APIs, the plugin must tell FormIt what DLLs need loaded. This is done in the manifest.