Creazione di un modulo aggiuntivo
Un modulo aggiuntivo è un plug-in che carica anche le DLL che espongono nuove API JavaScript.
Download dell'API di FormIt
Per creare DLL che supportino FormIt, è necessaria l'API di FormIt. L'API di FormIt può essere scaricata da Autodesk Developers Network. Per accedere al download, è necessario eseguire l'accesso.
Una volta eseguito l'accesso, l'API di FormIt è disponibile in SOFTWARE.


Un modulo aggiuntivo dispone dell'accesso all'API di FormIt e all'API C++ del kernel di modellazione di FormIt.
Un modulo aggiuntivo presenta la seguente struttura:
// 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") {}
...
...
}
Per ottenere gli argomenti nelle variabili C++, utilizzare 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;
}
Può essere restituito JSON_UNDEFINED o qualsiasi oggetto JSON. Utilizzare to_json per convertire la variabile C++ in 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);
}
Una volta definite tutte le API JS necessarie tramite la DLL, il plug-in deve indicare a FormIt quali DLL devono essere caricate. Questa operazione viene eseguita nel file manifesto.
"DLLs" : ["PLUGINLOCATION/MyClass.dll", "PLUGINLOCATION/HelloDLL.dll"]
HelloAddIn è un esempio pratico che spiega come creare un modulo aggiuntivo.
HelloWSMAddIn è un esempio pratico che spiega come creare un modulo aggiuntivo con l'API C++ del kernel di modellazione di FormIt.
Last updated