环境:Navisworks 2016、Navisworks 2016 SDK、Microsoft Visual Studio 2013。
1、创建应用程序,选择默认设置,点击完成。
2、在新建项目右键“属性“,设置平台为x64。
3、安装了SDK之后,在安装目录会多出一个api文件夹,这里只介绍nwcreate
4、设置附加包含目录(include)。
5、设置附加依赖项(nwcreate.lib、lcodpnwcreate.lib)。
这里做的是单独的exe,只需包含nwcreate.lib即可。
6、copy指定文件到指定目录。
7、不多说了,直接上代码。
#include "nwcreate\LiNwcAll.h"
void doExport();
int _tmain(int argc, _TCHAR* argv[])
{
LiNwcApiErrorInitialise();
switch (LiNwcApiInitialise())
{
case LI_NWC_API_OK:
doExport();
break;
case LI_NWC_API_NOT_LICENSED:
printf("Not Licensed\n");
return 1;
case LI_NWC_API_INTERNAL_ERROR:
default:
printf("Internal Error\n");
return 1;
}
LiNwcApiTerminate();
return 0;
}
void doExport()
{
LtWideString wfilename = L"D:\\test.nwc";
LtNwcScene scene = LiNwcSceneCreate();
LtNwcGeometry geom = LiNwcGeometryCreate();
LtNwcGeometryStream stream = LiNwcGeometryOpenStream(geom);
//open geometry stream, draw a triangle, close stream
stream = LiNwcGeometryOpenStream(geom);
LiNwcGeometryStreamBegin(stream, 0);
LiNwcGeometryStreamTriangleVertex(stream, 1, 0, 0);
LiNwcGeometryStreamTriangleVertex(stream, 2, 0, 10);
LiNwcGeometryStreamTriangleVertex(stream, 3, 10, 10);
LiNwcGeometryStreamEnd(stream);
LiNwcGeometryCloseStream(geom, stream);
//add the geometry to the scene and cleanup geom
LiNwcSceneAddNode(scene, geom);
LiNwcGeometryDestroy(geom);
//write out the NWC file
LiNwcSceneWriteCacheEx(scene, wfilename, wfilename, 0, 0);
}
8、运行程序,在D盘会生成test.nwc,在Navisworks中打开查看。
刚开始研究,有兴趣的朋友可以加我QQ一起学习。
QQ:408507803,备注:NwCreate