Fusion Add-In with .NET (C++ & CLR)

I've written about using MFC from a C++ Fusion add-in. You could also use .NET from your add-in, and it's even simpler to set up.

1) Create a C++ add-in inside the "Scripts and Add-Ins" Fusion dialog:

CreateAddIn

I'm leaving "Run on Startup" option above unchecked, because it would not be a good idea to pop up a modal dialog while Fusion is starting up. That would halt the startup process.

2) Open it for edit:

EditAddIn

3) Add "Common Language Runtime Support" in your C++ project's Properties dialog

ClrSupport

4) Place the Fusion related code inside a #pragma unmanaged /#pragma managed block

PragmaUnmanaged

5) Add a "Windows Form" through "PROJECT" >> "Add New Item…"

WindowsForm

Note: You can add any of the .NET Form controls to it as in case of a C# or VB.NET project. I've just added a list box for testing and filled it with items.

6) Create a function to show this dialog

a) In "MyForm.h" declare showDialog()

MyFormH

b) In "MyForm.cpp" implement the function

MyFormCpp

7) Now we can call it from the startup function called run()

a) Add #include "MyForm.h" to the top of "CustomNetUi.cpp"

b) Call showDialog() from run()

extern "C" XI_EXPORT bool run(const char* context) {   app = Application::get();   if (!app)     return false;    ui = app->userInterface();   if (!ui)     return false;    showDialog();    return true; }

8) Test the app by running it from the "Scripts and Add-Ins" Fusion dialog:

RunAddIn

AddInForm

The sample project can be found here:
https://github.com/AutodeskFusion360/NativeUI

-Adam


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading