Création d’un add-in

Un add-in est un plug-in qui charge également les DLL qui exposent les nouvelles API JavaScript.

Télécharger l’API FormIt

Pour créer des DLL prenant en charge FormIt, l’API FormIt est nécessaire. L’API FormIt peut être téléchargée sur le site Autodesk Developers Network. Une connexion est nécessaire pour accéder au téléchargement.

Une fois que vous êtes connecté, l’API FormIt est disponible sous LOGICIEL.

Un add-in a accès à l’API FormIt et à l’API FormIt Modeling Kernel C++ .

Un add-in a la structure suivante :

            // 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") {}
                ...
                ...
            }

Pour obtenir les arguments dans les variables C++, utilisez 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;
            }

JSON_UNDEFINED ou tout autre objet JSON peut être renvoyé. Utiliser to_json pour convertir votre variable C++ en 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);
            }

Une fois que la DLL définit toutes les API JS nécessaires, le plug-in doit indiquer à FormIt les DLL à charger. Cette opération est effectuée dans le fichier manifest.

        "DLLs" : ["PLUGINLOCATION/MyClass.dll", "PLUGINLOCATION/HelloDLL.dll"]

HelloAddIn est un exemple qui explique comment créer un add-in.

HelloWSMAddIn est un exemple qui explique comment créer un add-in avec l’API FormIt Modeling Kernel C++.

Last updated