新建win32项目
选择dll,空项目。要以动态链接库的形式加载到NX中,不是独立运行的exe应用程序
进来后新建项,添加代码
设置x64项目,如果是32位NX就用win32,64位用x64
开始配置环境
更改字符集为多字节
设置附加包含目录
D:\Program Files\Siemens\NX 9.0\UGOPEN
这个路径里放的都是做二次开发SDK开发包的头文件.h,库文件.lib,给我们调用使用的。
设置预处理器
至于为啥是这三个,当你用NX开发项目去做的时候,查看它用的就是这三个,原封不动抄过来。
_CRT_SECURE_NO_WARNINGS
_SECURE_SCL=0
_USRDLL
设置链接器-附加库目录
D:\Program Files\Siemens\NX 9.0\UGOPEN
设置附加依赖项
lib文件的介绍说明
libufun.lib UFUNC API 函数库
libugopenint.lib UFUNC 对话框 API 函数库
libnxopencpp.lib NXOpen API 函数库
libnxopenuicpp.lib NXOpen 对话框即Block UI Styler API 函数库
libnxopencpp_features.lib NXOpen API 特征函数库
libnxopencpp_annotations.lib NXOpen API 用到Vector,NXString的函数库
都设置完了后,确定关闭
下面开始添加代码,不知道添加什么代码,就去录制C++代码
将录制出来的代码放到我们的项目中
// NX 9.0.3.4
// Journal created by Administrator on Thu Sep 02 22:20:54 2021 中国标准时间
//
#include <uf_defs.h>
#include <NXOpen/NXException.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
using namespace NXOpen;
extern "C" DllExport int ufusr_ask_unload()
{
return (int)Session::LibraryUnloadOptionImmediately;
}
extern "C" DllExport void ufusr(char *param, int *retCode, int paramLen)
{
Session *theSession = Session::GetSession();
Part *workPart(theSession->Parts()->Work());
Part *displayPart(theSession->Parts()->Display());
// ----------------------------------------------
// Menu: Tools->Journal->Stop Recording
// ----------------------------------------------
}
编译项目,生成成功。
添加uc1601测试代码
// NX 9.0.3.4
// Journal created by Administrator on Thu Sep 02 22:20:54 2021 中国标准时间
//
#include <uf_defs.h>
#include <NXOpen/NXException.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
//头文件
#include <uf.h>
#include <uf_ui.h>
using namespace NXOpen;
extern "C" DllExport int ufusr_ask_unload()
{
return (int)Session::LibraryUnloadOptionImmediately;
}
extern "C" DllExport void ufusr(char *param, int *retCode, int paramLen)
{
Session *theSession = Session::GetSession();
Part *workPart(theSession->Parts()->Work());
Part *displayPart(theSession->Parts()->Display());
// ----------------------------------------------
// Menu: Tools->Journal->Stop Recording
// ----------------------------------------------
UF_initialize();
uc1601("SB", 1);
UF_terminate();
}
演示,ctrl+u调用dll
项目搭建结束
阿飞
2021年9月2日