環境: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