打开VS2013
点击新建,选择MFC DLL
点击确定
点下一步
什么都不改,直接点完成
进来之后先编译一下,看是否编译成功
打开项目属性,更改这几处
1 $(UGII_BASE_DIR)\ugopen
1 libufun.lib 2 3 libufun_cae.lib 4 5 libufun_cam.lib 6 7 libufun_die.lib 8 9 libufun_vdac.lib 10 11 libufun_weld.lib 12 13 libnxopencpp.lib 14 15 libnxopencpp_annotations.lib 16 17 libnxopencpp_assemblies.lib 18 19 libnxopencpp_bodydes.lib 20 21 libnxopencpp_cae.lib 22 23 libnxopencpp_cam.lib 24 25 libnxopencpp_diagramming.lib 26 27 libnxopencpp_diagramminglibraryauthor.lib 28 29 libnxopencpp_die.lib 30 31 libnxopencpp_display.lib 32 33 libnxopencpp_drafting.lib 34 35 libnxopencpp_drawings.lib 36 37 libnxopencpp_facet.lib 38 39 libnxopencpp_features.lib 40 41 libnxopencpp_fields.lib 42 43 libnxopencpp_formboard.lib 44 45 libnxopencpp_gateway.lib 46 47 libnxopencpp_geometricanalysis.lib 48 49 libnxopencpp_geometricutilities.lib 50 51 libnxopencpp_issue.lib 52 53 libnxopencpp_layer.lib 54 55 libnxopencpp_layout2d.lib 56 57 libnxopencpp_markup.lib 58 59 libnxopencpp_mechanicalrouting.lib 60 61 libnxopencpp_mechatronics.lib 62 63 libnxopencpp_mfg.lib 64 65 libnxopencpp_modldirect.lib 66 67 libnxopencpp_motion.lib 68 69 libnxopencpp_openxml.lib 70 71 libnxopencpp_optimization.lib 72 73 libnxopencpp_options.lib 74 75 libnxopencpp_partfamily.lib 76 77 libnxopencpp_pdm.lib 78 79 libnxopencpp_physmat.lib 80 81 libnxopencpp_placement.lib 82 83 libnxopencpp_plas.lib 84 85 libnxopencpp_positioning.lib 86 87 libnxopencpp_preferences.lib 88 89 libnxopencpp_report.lib 90 91 libnxopencpp_routing.lib 92 93 libnxopencpp_shapesearch.lib 94 95 libnxopencpp_sheetmetal.lib 96 97 libnxopencpp_shipdesign.lib 98 99 libnxopencpp_sim.lib 100 101 libnxopencpp_tooling.lib 102 103 libnxopencpp_userdefinedobjects.lib 104 105 libnxopencpp_userdefinedtemplate.lib 106 107 libnxopencpp_validate.lib 108 109 libnxopencpp_visualreporting.lib 110 111 libnxopencpp_weld.lib 112 113 libugopenint.lib 114 115 libugopenint_cae.lib 116 117 libugopenint_cam.lib 118 119 libnxopenuicpp.lib
然后点确定
添加头文件
添加ufusr入口函数和卸载方式
1 extern "C" DllExport void ufusr(char *param, int *retcod, int param_len) 2 { 3 4 if (UF_initialize()) 5 { 6 /* Failed to initialize */ 7 return; 8 } 9 // The following method shows the dialog immediately 10 11 12 13 UF_terminate(); 14 } 15 16 extern "C" DllExport int ufusr_ask_unload() 17 { 18 return (UF_UNLOAD_UG_TERMINATE); 19 //return (UF_UNLOAD_IMMEDIATELY); 20 //return UF_UNLOAD_SEL_DIALOG; 21 }
将项目改成64位的
打开配置管理器
编译项目,成功
添加对话框,找到资源视图,右键添加资源
选择Dialog,点新建
添加类
对话框右键-添加类
随便取名字,CFirstMFCDialog,点完成
编译项目成功
添加对话框初始化虚函数
对话框点右键-添加类向导
然后点确定
在编译项目成功
添加头文件
在去ufusr入口函数里获取UG窗口句柄,设置对话框。写的内容固定格式
1 AFX_MANAGE_STATE(AfxGetStaticModuleState()); 2 3 4 5 HWND UGHwnd = (HWND)UF_UI_get_default_parent();//获取UG窗口句柄 6 7 CWnd *ugwindow = CWnd::FromHandle(UGHwnd); 8 9 10 11 CFirstMFCDialog *dlg = new CFirstMFCDialog(ugwindow); 12 13 if (dlg != NULL) 14 15 { 16 17 BOOL ret = dlg->Create(IDD_DIALOG1, ugwindow); 18 19 dlg->ShowWindow(SW_SHOW); 20 21 //dlg->SetWindowPos(ugwindow, 300, 220, 200, 200, SWP_NOSIZE);//设置对话框固定位置 22 23 }
在编译项目成功
打开UG去调对话框就出来了
提示,因为选择的卸载方式,需求每次修改代码重新编译,都要关闭UG。来卸载掉。
截止到这个MFC+NX二次开发的这个环境搭建就结束了
下面做一个实例。
选择位置,创建块。(大概演示,不在详细写步骤)
对话框
对话框初始化代码
1 BOOL CFirstMFCDialog::OnInitDialog() 2 { 3 CDialogEx::OnInitDialog(); 4 5 // TODO: 在此添加额外的初始化 6 7 //对话框初始值 8 m_edit1.SetWindowText("100"); 9 m_edit2.SetWindowText("50"); 10 m_edit3.SetWindowText("25"); 11 12 return TRUE; // return TRUE unless you set the focus to a control 13 // 异常: OCX 属性页应返回 FALSE 14 }
点构造器代码
1 void CFirstMFCDialog::OnBnClickedButton1() 2 { 3 // TODO: 在此添加控件通知处理程序代码 4 5 UF_initialize(); 6 7 UF_UI_lock_ug_access(UF_UI_FROM_CUSTOM);//对话框加锁 8 9 char sCue[] = "点构造器"; 10 UF_UI_POINT_base_method_t base_method = UF_UI_POINT_INFERRED; 11 tag_t tPoint = NULL_TAG; 12 double sBasePoint[3]; 13 int iResponse; 14 UF_UI_point_construct(sCue, &base_method, &tPoint, sBasePoint, &iResponse); 15 16 UF_UI_unlock_ug_access(UF_UI_FROM_CUSTOM);//对话框解锁 17 18 UF_terminate(); 19 }
点确定的代码
1 void CFirstMFCDialog::OnBnClickedOk() 2 { 3 // TODO: 在此添加控件通知处理程序代码 4 CDialogEx::OnOK(); 5 6 UF_initialize(); 7 8 //获取对话框里的输入值 9 CString length; 10 m_edit1.GetWindowTextA(length); 11 12 CString width; 13 m_edit2.GetWindowTextA(width); 14 15 CString high; 16 m_edit3.GetWindowTextA(high); 17 18 //转换 19 //CString转char* 20 USES_CONVERSION; 21 char* length1 = T2A(length.GetBuffer(0)); 22 length.ReleaseBuffer(); 23 24 char* width1 = T2A(width.GetBuffer(0)); 25 width.ReleaseBuffer(); 26 27 char* high1 = T2A(high.GetBuffer(0)); 28 high.ReleaseBuffer(); 29 30 UF_FEATURE_SIGN sign = UF_NULLSIGN; 31 char * edge_len[3] = { length1, width1, high1 }; 32 tag_t blk_obj_id = NULL_TAG; 33 UF_MODL_create_block1(sign, sBasePoint, edge_len, &blk_obj_id); 34 35 UF_terminate(); 36 }
源代码下载
链接:https://pan.baidu.com/s/1Pjveurp-tEDUiqMI5uDhGA 密码:mvqq
Caesar卢尚宇
2019年7月13日
原文:https://www.cnblogs.com/nxopen2018/p/11179640.html