Fusion 360 API : 调用MFC对话框

来源:互联网 发布:巨人网络收购投哪网 编辑:程序博客网 时间:2024/04/30 09:58

原文地址: http://modthemachine.typepad.com/my_weblog/2016/02/fusion-add-in-with-mfc.html

我的同事Adam研究了一个有趣的内容,即如何在Fusion 360调用传统的MFC对话框。显然需要用到C++ API . 开始Adam琢磨基于Fusion 产生的C++插件工程,添加MFC支持,最后发现这个太挫折感,最后他想到一个聪明的办法,先创建一个MFC 的DLL,然后在Fusion C++工程中调用之。搞定!

源码在此:https://github.com/AutodeskFusion360/NativeUI

1) 创建一个MFC DLL

MfcCreate1

MfcCreate2

2) 添加对话框资源

  MfcResource

MfcResourceNew


 3)添加对话框类,并根据需要调整合适的名字。

MfcWizard

4) 在对话框.cpp中增加方法显示对话框

void showDialog(){    // Always call this macro first thing in any function that  // will use MFC functionality   AFX_MANAGE_STATE(AfxGetStaticModuleState());  CMyDialog myDialog;   myDialog.DoModal();};

在对话框.h文件中增加:

#include "MyDialog.h"void showDialog();


5) 增减一个名为FusionCode.cpp 的c++文件,并添加如下代码:
FusionCode

#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"#endifusing 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;}

6) 修改工程配置为X64,因为Fusion 360只有64位的。

7) 给工程配置好Fusion 360 C++头文件与库文件所在路径。

8) 编译,生成dll,例如CustomMfcUi.dll 

9) 在 "$(APPDATA)\Autodesk\Autodesk Fusion 360\API\AddIns" 创建一个名为CustomMfcUi的文件夹。并添加一个“CustomMfcUi.manifest"。 其内容为:

    

{"autodeskProduct":"Fusion360","type":"addin","author":"","description":{"":""},"supportedOS":"windows","editEnabled":false,"id":"38EE9339-591A-4F72-AFFF-7B20111CC10C","version":"1.0.0","runOnStartup":false}

id是个guid

10)  将前面编译好的dll也放到这个文件夹。

11) 启动Fusion后,在插件管理器能看到此插件。

MfcTest


点击它,对话框出现: 

MfcTest2

0 0