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.
Either feature does not mean you can add additional model/elements to the existing model. Instead, you can just create your own model on a blank document. The difference of them is:
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
\api\nwcreate\lib\x64
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.
#include "stdafx.h"
#include "nwcreate/LiNwcAll.h"
int _tmain(int argc, _TCHAR* argv[])
{
// Initialise low-level API first.
LiNwcApiErrorInitialise();
// Then initialise the rest of the API.
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;
}
5. Implement the export function doExport.
void doExport()
{
LtWideString wfilename = L"C:\\test.nwc";
LtNwcScene scene;
LtNwcGeometry geom;
LtNwcGeometryStream stream;
//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);
LiNwcGeometryDestroy(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.