Skip to main content

Module nxasm

Module nxasm 

Source
Expand description

Components and placements of Siemens NX assemblies (.prt without a tessellation of their own), read from the /Root/FastLoad/Structure stream of the container (see nxpart).

The stream is an NX object serialisation (“OM”). The layout was worked out from the NIST MTC assembly and checked instance for instance against its JT export (part, rotation and translation; differences below 0.00001 mm) and with real assemblies of nested sub-assemblies (docs/src/research/nx-jt-preview.md):

0x0c   "OM"; object offsets count from 0x0e
0x1f   u32 n, n bytes platform; u32 n, n bytes file name; u32 object count N
…      N u32 object offsets (increasing), u32 N, N u32 object tags

The largest object (“SaveData”) holds, in this order: 01 <count> and count numbers = one record of 9 numbers per placed instance (rotation row 0, rotation row 1, translation in mm); 01 <M+1> and M component names (04 <len+2> text 00: the file name without .prt, upper case); 01 <N+1> and the 1-based name index of each of the N instances. Another object is an int→int hash map from instance to record: <n+1> 01 <cap+1> keys… 01 <w+1> state words… 01 <cap+1> values… (2 state bits per slot, 2 = used; keys and values stored +1). An instance without a record sits at the origin.

Numbers: a byte t with t & 0x70 in 0x20..=0x30 starts 8 bytes = the big-endian double with t + 0x10 as its first byte; 0x40..=0x50 starts 4 bytes = the first four bytes of a double with t − 0x10 first; both divided by 4. 00, 01, 81, 80 are 0, 1, −1, −0. Integers are variable-length (00..7f, 80..9f + 1 byte, a0..bf + 2, e0/ff + 4).

Rotations are row vectors: a point p of the component lands at p · R + t. Components moved to another layer are listed in one more int map (instance → layer); whether a layer is visible is part of the layer settings in /Root/UG_PART/UG_PART (visible_layers), and kind_of leaves out components on hidden layers, as NX does. Everything is read defensively: a stream that does not fit gives None, never a panic.

Structs§

Component
A component instance of an assembly.
Layers
Which of the 256 layers are visible.

Enums§

Kind
What an NX file is for the 3D preview, read with seeks (only the directory, the structure stream and the layer settings).

Constants§

STRUCTURE_STREAM
The stream with the assembly structure.
UG_PART_STREAM
The stream with the NX data, which holds the layer settings.

Functions§

components
The components of an NX assembly held in memory, or None when the bytes are no NX file with a readable assembly structure.
identity
The identity placement (the top assembly itself).
kind_of
The Kind of the NX file at path. Components on a layer the file’s layer settings make invisible are left out, as NX does.
structure
The components described by a Structure stream.
visible_layers
The layer settings of an NX file from its UG_PART stream: the one UGS::LAYER_parameter object – after 00 5f 01 04 01 four masks of 17 32-bit words (selectable, visible, and two copies with an extra bit), the work layer and the constants 1, 1. Mask 1 holds the visible layers (a superset of mask 0). None unless exactly one such object is found, so a misread never hides anything.