NwCreate之創建nwc文件

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

發佈了51 篇原創文章 · 獲贊 24 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章