The NWCreate API provides a means of creating NavisWorks models, either for export of NWD files from a third party application (LiNwcApi) or to implement a file loader (LiNwcLoader) for NavisWorks. The figure below shows the two features.
LiNwcAPI is a standalone EXE which creates the model. You can save to a nwd file. i.e. a new file.
LiNwcLoader is a kind of plugin which is loaded by Navisworks. This plugin provides the machaism how to create a model with the data of the specific file format which Navisworks does not support. e.g. assume you have a file format whose extension name is: *.myfile, when you try to open such file, Navisworks will look for the corresponding loader and get to know how to use the data of the file, finally create the models.
NWCreate is a stdcall interface callable from C, C++, etc. All data manipulation is by means of handles (LiNwcTypes) providing complete encapsulation. For ease of use a C++ wrapper API is provided that gives an object oriented interface to the API.
We deploy the binary dll and lib for the features in the SDK folder api\NwCreate\bin and api\NwCreate\lib. Note: you will need to link to 32bits lib for 32bits program and 64bits for 64bits program.
In this section, we firstly introduce LiNwcAPI. Your application should link with nwcreate.lib distributed in from the ‘lib’ directory. The implementation of the API is in nwcreate.dll from the ‘bin’ directory. You should distribute this dll with your application.
The typical workflow is:
Let us start with a sample. This sample is to export a NWC file.
1. Create a C++ Console Application
2. Link with nwcreate.lib. I am testing on 64bits OS, so link to 64bits version at
3. Add include folder \api\nwcreate\include
3. Add necessary head files ‘nwcreate/LiNwcAll.h’ in testLiNwcAPI.cpp. This head file includes all head files of NwCreate.
4. Add the code in main function.
int _tmain(int argc, _TCHAR* argv)
// Initialise low-level API first.
// Then initialise the rest of the API.
5. Implement the export function doExport.
LtWideString wfilename = L"C:\\test.nwc";
//create scene and geometry
scene = LiNwcSceneCreate();
geom = LiNwcGeometryCreate();
//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);
//write out the NWC file
LiNwcSceneWriteCacheEx(scene, wfilename, wfilename, 0, 0);
6. Copy the NwCreate bindary dll files in the folder \api\nwcreate\bin\x64 to the same folder of your application binary, e.g.
7. Run the program, a file named test.nwc will be generated, in which a triangle is produced.