打开VS2013
点击新建,选择MFC DLL
点击确定
点下一步
什么都不改,直接点完成
进来之后先编译一下,看是否编译成功
打开项目属性,更改这几处
$(UGII_BASE_DIR)\ugopen
libufun.lib
libufun_cae.lib
libufun_cam.lib
libufun_die.lib
libufun_vdac.lib
libufun_weld.lib
libnxopencpp.lib
libnxopencpp_annotations.lib
libnxopencpp_assemblies.lib
libnxopencpp_bodydes.lib
libnxopencpp_cae.lib
libnxopencpp_cam.lib
libnxopencpp_diagramming.lib
libnxopencpp_diagramminglibraryauthor.lib
libnxopencpp_die.lib
libnxopencpp_display.lib
libnxopencpp_drafting.lib
libnxopencpp_drawings.lib
libnxopencpp_facet.lib
libnxopencpp_features.lib
libnxopencpp_fields.lib
libnxopencpp_formboard.lib
libnxopencpp_gateway.lib
libnxopencpp_geometricanalysis.lib
libnxopencpp_geometricutilities.lib
libnxopencpp_issue.lib
libnxopencpp_layer.lib
libnxopencpp_layout2d.lib
libnxopencpp_markup.lib
libnxopencpp_mechanicalrouting.lib
libnxopencpp_mechatronics.lib
libnxopencpp_mfg.lib
libnxopencpp_modldirect.lib
libnxopencpp_motion.lib
libnxopencpp_openxml.lib
libnxopencpp_optimization.lib
libnxopencpp_options.lib
libnxopencpp_partfamily.lib
libnxopencpp_pdm.lib
libnxopencpp_physmat.lib
libnxopencpp_placement.lib
libnxopencpp_plas.lib
libnxopencpp_positioning.lib
libnxopencpp_preferences.lib
libnxopencpp_report.lib
libnxopencpp_routing.lib
libnxopencpp_shapesearch.lib
libnxopencpp_sheetmetal.lib
libnxopencpp_shipdesign.lib
libnxopencpp_sim.lib
libnxopencpp_tooling.lib
libnxopencpp_userdefinedobjects.lib
libnxopencpp_userdefinedtemplate.lib
libnxopencpp_validate.lib
libnxopencpp_visualreporting.lib
libnxopencpp_weld.lib
libugopenint.lib
libugopenint_cae.lib
libugopenint_cam.lib
libnxopenuicpp.lib
然后点确定
添加头文件
添加ufusr入口函数和卸载方式
extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
{ if (UF_initialize())
{
/* Failed to initialize */
return;
}
// The following method shows the dialog immediately UF_terminate();
} extern "C" DllExport int ufusr_ask_unload()
{
return (UF_UNLOAD_UG_TERMINATE);
//return (UF_UNLOAD_IMMEDIATELY);
//return UF_UNLOAD_SEL_DIALOG;
}
将项目改成64位的
打开配置管理器
编译项目,成功
添加对话框,找到资源视图,右键添加资源
选择Dialog,点新建
添加类
对话框右键-添加类
随便取名字,CFirstMFCDialog,点完成
编译项目成功
添加对话框初始化虚函数
对话框点右键-添加类向导
然后点确定
在编译项目成功
添加头文件
在去ufusr入口函数里获取UG窗口句柄,设置对话框。写的内容固定格式
AFX_MANAGE_STATE(AfxGetStaticModuleState()); HWND UGHwnd = (HWND)UF_UI_get_default_parent();//获取UG窗口句柄 CWnd *ugwindow = CWnd::FromHandle(UGHwnd); CFirstMFCDialog *dlg = new CFirstMFCDialog(ugwindow); if (dlg != NULL) { BOOL ret = dlg->Create(IDD_DIALOG1, ugwindow); dlg->ShowWindow(SW_SHOW); //dlg->SetWindowPos(ugwindow, 300, 220, 200, 200, SWP_NOSIZE);//设置对话框固定位置 }
在编译项目成功
打开UG去调对话框就出来了
提示,因为选择的卸载方式,需求每次修改代码重新编译,都要关闭UG。来卸载掉。
截止到这个MFC+NX二次开发的这个环境搭建就结束了
下面做一个实例。
选择位置,创建块。(大概演示,不在详细写步骤)
对话框
对话框初始化代码
BOOL CFirstMFCDialog::OnInitDialog()
{
CDialogEx::OnInitDialog(); // TODO: 在此添加额外的初始化 //对话框初始值
m_edit1.SetWindowText("");
m_edit2.SetWindowText("");
m_edit3.SetWindowText(""); return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
点构造器代码
void CFirstMFCDialog::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码 UF_initialize(); UF_UI_lock_ug_access(UF_UI_FROM_CUSTOM);//对话框加锁 char sCue[] = "点构造器";
UF_UI_POINT_base_method_t base_method = UF_UI_POINT_INFERRED;
tag_t tPoint = NULL_TAG;
double sBasePoint[];
int iResponse;
UF_UI_point_construct(sCue, &base_method, &tPoint, sBasePoint, &iResponse); UF_UI_unlock_ug_access(UF_UI_FROM_CUSTOM);//对话框解锁 UF_terminate();
}
点确定的代码
void CFirstMFCDialog::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
CDialogEx::OnOK(); UF_initialize(); //获取对话框里的输入值
CString length;
m_edit1.GetWindowTextA(length); CString width;
m_edit2.GetWindowTextA(width); CString high;
m_edit3.GetWindowTextA(high); //转换
//CString转char*
USES_CONVERSION;
char* length1 = T2A(length.GetBuffer());
length.ReleaseBuffer(); char* width1 = T2A(width.GetBuffer());
width.ReleaseBuffer(); char* high1 = T2A(high.GetBuffer());
high.ReleaseBuffer(); UF_FEATURE_SIGN sign = UF_NULLSIGN;
char * edge_len[] = { length1, width1, high1 };
tag_t blk_obj_id = NULL_TAG;
UF_MODL_create_block1(sign, sBasePoint, edge_len, &blk_obj_id); UF_terminate();
}
Caesar卢尚宇
2019年7月13日