Table Of Contents:
Before writing NX files, you need to initialise Datakit API.
Parasolid writer is required for NX writer.
See main entry point to see call of Dtk_API::StartAPI function, and Dtk_API::StopAPI. This entry point calls UgWriteSample function.
In this function, we make twice the same tests, one ine version NX5, another with version NX1980. Datakit writer supports to write these versions.
The list of available tests of this sample are in function UgWriteSampleVersion
Let's start with a simple code that will write a NX file containing a cube.
In this example, we get a cube as Dtk_Body (see common exemples)
This cube has some faces colored, these colors are inside the info fields of each face.
Then we initialize the writer with Ugw::InitFile. We provide the name of the file, for example "simplebody.prt", and also the version. The supported versions are DTK_UGW_VERSION_NX5 or DTK_UGW_VERSION_NX1980 Note that version parameter is optional, an default value is DTK_UGW_VERSION_NX5.
We put the cube wth Ugw::WriteBody, then close the writer with Ugw::EndFile.
The macro CHECK_OK just check the return value (a Dtk_ErrorStatus, if an error occurs, it returns the errors aborting the operation).
This sample gives the result below.
This example shows how to write more than one bodies, and shows some options.
We create two cubes, we apply a transformation on the second with Dtk_transfo translate, then we use two times the function Ugw::WriteBody. You may use this function as many times you want to write more bodies.
We give a name for each cube "FirstCube" and" "SecondCube" in info field of each body. These names appear in part navigator as featurename.
This example shows how to write a mesh.
This simple code shows the function Ugw::WriteMesh. We give the name "MyMesh" to the mesh.
This example shows how to write wireframe.
To set wireframe, you need to fill a body with wire entity, then put it inside NX with Ugw::WriteBody With info field of each curve, we can give each feature a name, here "mycircle", "myline". We can also give a color.
This example shows how to write axis systems, reference planes, references axis, reference points.
Let's see the function UgReferences. We can Ugw::InitFile and Ugw::WriteBody like previous example.
We finally a point Ugw::WriteReferenceGeometry. The function MakeRefPoint make the geometry, we give a name, but not NXNAME because NX does not set another name on this feature. This will appear in NX as "Point"
This example shows how to add extern Parasolid file
This example add a Parasolid file instead of a Dtk_Body as body. We read the file in memory before giving raw pointer of Parasolid file to function Ugw::WriteExternParasolidBody
This example shows how to make layer filters.
In this sample we use function Ugw::SetLayerData to fill layer datas. NX manage 256 layers (from 1 to 256 included), each of this layer can be invisible, visible only, or visible and selectable. We fill a Dtk_tab of size 257 to define each layer.
The Dtk_LayerInfoSet also contain default layer, and layer filters. In our sample, we make a filter "FILTER_456" contain layers 4,5,6, and "FILTER_678" contain layers 6,7,8
We define default layer as layer 12. We define CubeBody in layer 5, CylMesh in layer 6. Layer 6 is invisible here, so part navigator shows CylMesh as invisible.
We retrieve all these informations on the screenshot below.
This example shows how to make groups.
In this example, we make 2 cubes. Filling attribute "NXGROUPS" into info field of each cube, we define cube1 is in group GroupRoot/Sub1, and cube2 is in group GroupRoot/Sub1 ans GroupRoot/Sub2 The groups are a tree, it is possible to make a more complex hierarchy.
We set that group "Sub2" is invisible, and in layer 23 in this sample with Ugw::SetGoupDatas. We also make an empty group, layer 19, still with function Ugw::SetGoupDatas.
This example shows how to make reference sets.
We use custom attribute "NXREFERENCESET" in a body (or a mesh, or other feature) to include it in some reference sets. Here, Cube1 into reference set "MyRef1","MyRef2","MyRef3", Cube2 into reference set "MyRef1","MyRef3".
This example shows how to set default units, and modeling preferences and metadatas
In this example, we use a last parameter of Ugw::InitFile as 0 (=inch). If not set, default value = 1 (millimeters). We see on screenshot the file, in inches.
Custom metadatas are "MyPropTitle", we retrieve it in display part properties. Note that category is not supported in NX_5 output, but it is in NX_1980 output.
Specific metadatas, with catergory name as "Modeling Preferences" define some modeling preferences we see in the screeshot below. For Density Units, supported values are "lb/in3", "lb/ft3", "g/m3", "kg/m3"
This example shows how to customize colors
NX stores a palette color. (A palette color per part). There is 217 colors available. Each color can be redefined with RGB value, and a name. Function Ugw::SetColorInTable can set custom colors. Function Ugw::GetColorInTable exists too to retrieve colors.
Note : in default mode, our writer try to find the closer color in existing palette, that's why the cube appears red.
This example shows how to make an simple assembly
To create open a subassembly, use function Ugw::OpenInstance. We give a name, that will be the file name (without .prt), then a placement matrix (cubetransfo here) And some properties as Dtk_InfoPtr given by MakeInstanceData.
Note that we reinstanciate leaf2 twice, with different matrix, colors, and visibility. To reinstanciate an existing subassembly, call Ugw::OpenInstance with a part name already used previously, the call Ugw::CloseLastInstance immediatly.
Note that not only leaves can have bodies, see the line "put a cube on the subassembly".
This example shows how to make an assembly from existing files.
The function Ugw::AddExternInstance adds an existing part or assembly. As a new instance the Dtk_InfoPtr works like the Dtk_InfoPtr of function Ugw::OpenInstance.
About the last parameter, in a normal NX assembly, the root files knows all its hierarchy, not only its children, but grand children, all tree, all leaves, even deep leaves.
Including an assembly with Ugw::AddExternInstance, and NULL at last parameter make the root file (here externasm.prt) knowing only its child (asm.prt) but not the leaves. If we want externasm.prt to know all its leaves, we need to link the Datakit NX Reader, then activate USE_NX_READER, it will link the function pointer nxreader_GetData that will retrieve all datas needed from external assembly.
This example shows how to make an annotation
In this example, we create a simple Annotation. The function UGW_Sample_MakePMI shows differents options you retrieve on the screenshot.
Actually, annotation creation is limited as :
one arrow with one stub