It is possible to use MFC functionality inside your Fusion add-in on Windows.
First I tried going down the path of creating a C++ add-in inside the "Scripts and Add-Ins" Fusion dialog and then add MFC support to the created Visual Studio C++ project. However, that proved quite difficult and I just gave up and went the other way: created an MFC DLL project and turned it into a Fusion add-in. That was much simpler.
1) Create an MFC DLL project
2) Add a Dialog resource to it
Open CustomMfcUi.rc, right-click and choose "Add Resource..."
... then select "Dialog" and click "New"
3) Double-click the "OK" button of the newly added Dialog so that the "MFC Add Class Wizard" dialog will pop up:
Fill it in and click "Finish"
4) Rename IDD_DIALOG1 to IDD_MYDIALOG just to keep things tidy
You can use the "Find and Replace" dialog of Visual Studio for that:
There should be 4 instances replaced at the end:
5) Add a function to show our dialog
a) Inside CustomMfcUi.cpp add this code:
void showDialog()
{
// Always call this macro first thing in any function that
// will use MFC functionality
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CMyDialog myDialog;
myDialog.DoModal();
};
b) Inside CustomMfcUi.h add this code at the top:
#include "MyDialog.h"
void showDialog();
6) Add Fusion functionality
Add a new C++ file to the project called FusionCode.cpp
Fill it with this code:
#include "stdafx.h"
#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>
// XI_WIN is a macro added by Fusion headers
// to show if the project is a Windows project
#ifdef XI_WIN
#include "CustomMfcUi.h"
#endif
using namespace adsk::core;
using namespace adsk::fusion;
Ptr<Application> app;
Ptr<UserInterface> ui;
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;
}
extern "C" XI_EXPORT bool stop(const char* context)
{
if (ui)
{
ui->messageBox("in stop");
ui = nullptr;
}
return true;
}
7) Make the project compile as 64 bit since Fusion 360 is 64 bit too
Inside the "Configuration Manager" dialog, under "Active solution platform" select "<New...>"
... and add the "x64" platform
8) Add references to Fusion headers and libraries so that our project will compile
a) Inside the project settings, under "C/C++" >> "Additional Include Directories" add "$(APPDATA)/Autodesk/Autodesk Fusion 360/API/CPP/include"
b) Under "Linker" >> "Additional Library Directories" add "$(APPDATA)/Autodesk/Autodesk Fusion 360/API/CPP/lib"
c) Under "Linker" >> "Additional Dependencies" add "core.lib;fusion.lib;"
9) Let Fusion find our project
a) Under "$(APPDATA)\Autodesk\Autodesk Fusion 360\API\AddIns" create a folder named the same as our dll "CustomMfcUi"
Add to that folder a manifest file with the same name, i.e. "CustomMfcUi.manifest" and add the following content to it in any text editor:
{
"autodeskProduct":"Fusion360",
"type":"addin",
"author":"",
"description":{"":""},
"supportedOS":"windows",
"editEnabled":false,
"id":"38EE9339-591A-4F72-AFFF-7B20111CC10C",
"version":"1.0.0",
"runOnStartup":false
}
The "id" part in the above text needs to be unique. You could use e.g. Visual Studio's "Create GUID" dialog for that. Just remove the curly braces from the generated string
I'm setting the "runOnStartup" option above to false 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.
b) Make our project output the created dll into the Add-In folder we just created. Inside the project settings under "General" >> "Output Directory" add the path of our folder "$(APPDATA)\Autodesk\Autodesk Fusion 360\API\AddIns\CustomMfcUi"
10) Test it
Compile the project and inside the "Scripts and Add-Ins" dialog of Fusion, select our add-in and click "Run"
Our dialog should pop up
The sample project can be found here:
https://github.com/AutodeskFusion360/NativeUI
-Adam