• NX二次开发-基于MFC界面对话框与NX交互的开发


    打开VS2013

    点击新建,选择MFC DLL

    点击确定

     

    点下一步

     

    什么都不改,直接点完成

    进来之后先编译一下,看是否编译成功

     

    打开项目属性,更改这几处

     

     1 $(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入口函数和卸载方式

     

     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 }

    Caesar卢尚宇

    2019年7月13日

    NX二次开发CreateDialog函数在UI.hxx文件和WinUser.h中的冲突【转载】

    https://www.cnblogs.com/nxopen2018/p/11811708.html

  • 相关阅读:
    win8应用的编码UI测试
    什么是Peer Review
    Android开发环境的搭建
    运用int.parse()判断闰年代码实现
    等价类划分方法的应用之EditBox(二)
    等价类划分方法的应用之EditBox
    集成测试
    数据可视化简介
    关于processing
    白盒测试VS黑盒测试
  • 原文地址:https://www.cnblogs.com/nxopen2018/p/11179640.html
Copyright © 2020-2023  润新知