Custom File Streams

Arbitrary user data can be written to and read from 3ds Max scene files (or any other OLE Structure Storage-based files) using the Custom File Stream API.

Within 3ds Max, this API is used by CustomFileStream.dlu and implemented by CustomFileStreamAPI.dll source. The source for these are in maxsdk\samples\utilities\CustomFileStream.

Note:

These interfaces are also accessible by MAXScript. See the documentation for the CustomFileStream and CustomFileStreamManager interfaces.

CustomFileStreamAPI.dll defines the low level file access methods that are used by CustomFileStream.dlu, and can be used by external applications to read, write, and modify the CustomFileStream as supported by the CustomSceneStreamManager and CustomFileStream interfaces. To use this dll, you would link against CustomFileStreamAPI.lib in maxsdk\libs. There are no dependencies by CustomFileStreamAPI.dll on other 3ds Max dlls. To see how these low level methods should be tied together, see the CustomFileStream.dlu source.

This API will read and write CustomFileStream to 3ds Max scene files written by any version of 3ds Max. The CustomSceneStreamManager is required to persist the custom data streams across scene file load and save operations. CustomFileStream as supported by CustomSceneStreamManager and CustomFileStream are located in the CustomFileStream IStorage of the 3ds Max scene file main IStorage.

Each stream consists of a header consisting of a 1 WORD version number and two 32 bit DWORD values (see CustomFileStreamHeader), followed by a non-null terminated wchar string or an array of null terminated wchar strings. The current version number is 1.

The first 32 bit DWORD is considered private (flag bit usage defined by Autodesk) and the second is considered public (flag bit usage defined by the creator of the stream).

Currently, bits 1 to 3 of the private DWORD are used.

Bit 1 signifies that the stream is a persistent stream. When this bit is set, the CustomSceneStreamManager will write this stream to the scene file when the scene file is saved. This allows a CustomFileStream to be automatically persisted across a load/save operation.

Bit 2 signifies that the stream is to be saved to the scene file when the scene file is saved, but the stream is not necessarily a persistent stream. This allows the user to add streams to CustomSceneStreamManager's cache and have those streams be written to the scene file. This bit is not persisted to the scene file, and is cleared when read from the scene file.

Bit 3 signifies that the stream is not to be added to the CustomSceneStreamManager's cache when the scene file is loaded. If neither of the first 2 bits are set, CustomSceneStreamManager does not write this stream to the scene file when the scene file is saved.

The content of the stream is considered to be an array of strings if the last character in the content is a null character (signifying an array of null terminated strings), otherwise the content is considered to be a single non-null terminated string.