c4d.storage.HyperFile¶
-
class
c4d.storage.HyperFile¶ - Hyper files are used to store data in a file.The HyperFile works with the ‘FIFO’ concept.The values will be written and read in the same order.The following source code is a simple example showing how to use the
HyperFileclass.import c4d, os YOUR_IDENT = 49545 # Choose a custom ident path = os.path.join("/Users", "Dev", "Desktop", "test.file") print(path) def Write(path, key): #write print(path) hf = c4d.storage.HyperFile() if hf.Open(ident=key, filename=path, mode=c4d.FILEOPEN_WRITE, error_dialog=c4d.FILEDIALOG_NONE): bc = c4d.BaseContainer() bc[0] = "test" bc[1] = "3" hf.WriteContainer(bc) hf.Close() else: c4d.gui.MessageDialog("Cannot open file to write.") def Read(path, key): #read hf = c4d.storage.HyperFile() if hf.Open(ident=key, filename=path, mode=c4d.FILEOPEN_READ, error_dialog=c4d.FILEDIALOG_NONE): bc = hf.ReadContainer() hf.Close() print(bc[0], bc[1]) #output: test 3 else: c4d.gui.MessageDialog("Cannot open file to read.") Write(path, YOUR_IDENT) Read(path, YOUR_IDENT)
Overview¶
Chunk Reading |
|
Read a chunks end marker from the file. |
|
Read a chunks identification from the file. |
|
Move the file pointer to the end of the chunk. |
|
Chunk Writing |
|
Write a chunk ending marker into the file. |
|
Write a chunk marker into the file indicating the beginning of a new chunk of data. |
|
Error Handling |
|
Get the error from the last hyperfile operation. |
|
Set the error value for this hyperfile. |
|
File Context |
|
Gets the active document for the hyper file operation. |
|
Get the version of Cinema 4D that wrote the file. |
|
Gets the filter flags, the value is valid only during a Load or a Merge. |
|
File Lifecycle |
|
Closes the hyper file. |
|
Opens the hyper file. |
|
Geometric Reading |
|
Read a |
|
Read a |
|
Read a double precision |
|
Read a |
|
Read a |
|
Read a double precision |
|
Geometric Writing |
|
Write a |
|
Write a |
|
Write a double precision |
|
Write a |
|
Write a |
|
Write a double precision |
|
Magic Methods |
|
Allocates a hyper file. |
|
Numeric Reading |
|
Read a character from the hyperfile. |
|
Read a float from the hyperfile. |
|
Read a float from the hyperfile. |
|
Read a double precision float from the hyperfile. |
|
Read a signed word from the hyperfile. |
|
Read an int from the hyperfile. |
|
Read a double precision int from the hyperfile. |
|
Read an unsigned character from the hyperfile. |
|
Read an unsigned word from the hyperfile. |
|
Read an unsigned int from the hyperfile. |
|
Read a double precision unsigned int from the hyperfile. |
|
Numeric Writing |
|
Write a character to the hyperfile. |
|
Write a float value to the hyperfile. |
|
Write a double precision float value to the hyperfile. |
|
Write a signed short int to the hyperfile. |
|
Write an int to the hyperfile. |
|
Write a double precision int value to the hyperfile. |
|
Write a very short int to the hyperfile. |
|
Write an unsigned short int to the hyperfile. |
|
Write an unsigned int to the hyperfile. |
|
Write a double precision unsigned int value to the hyperfile. |
|
Scalar And Text Reading |
|
Read a bool from the hyperfile. |
|
Read a path from the hyperfile. |
|
Read a string from the hyperfile. |
|
Read a |
|
Scalar And Text Writing |
|
Write a bool to the hyperfile. |
|
Write a path to the hyperfile. |
|
Write a string to the hyperfile. |
|
Write a |
|
Structured Data Reading |
|
Read a container from the hyperfile. |
|
Read a data from the hyperfile. |
|
Read a bitmap from the hyperfile. |
|
Read a block of memory from the hyperfile. |
|
Structured Data Writing |
|
Write the settings in a |
|
Write data to the container. |
|
Write an image to the hyperfile. |
|
Write a block of memory to the hyperfile. |
|
Value Navigation |
|
Read the value header from the file. |
|
Skip a given type of value. |
|
Members¶
Chunk Reading¶
-
HyperFile.ReadChunkEnd(self)¶ Read a chunks end marker from the file.
- Return type
bool
- Returns
Success of reading the chunk end.
-
HyperFile.ReadChunkStart(self)¶ Read a chunks identification from the file.
import c4d hf = c4d.storage.HyperFile() chunk = hf.ReadChunkStart() if chunk is None: return id = chunk["id"] # Chunk ID, int level = chunk["level"] # Chunk Level, int
- Return type
Optional[Dict[id: int, level: int]]
- Returns
The identification or None on failure.
-
HyperFile.SkipToEndChunk(self)¶ Move the file pointer to the end of the chunk.
Note
This should always be called after finishing reading your values from this chunk.
- Return type
bool
- Returns
Success of finding the end of the chunk.
Chunk Writing¶
-
HyperFile.WriteChunkEnd(self)¶ Write a chunk ending marker into the file.
- Return type
bool
- Returns
Success of writing the chunk end.
-
HyperFile.WriteChunkStart(self, id, level)¶ Write a chunk marker into the file indicating the beginning of a new chunk of data.
Note
Chunks should only be used if absolutely necessary.If a plugin uses chunks badly then the file structure can become corrupted.- Parameters
id (int) – The ID for the chunk.
level (int) – If you want to write additional information you can increase the level this allows you to easily save/read new values.
- Return type
bool
- Returns
Success of writing the chunk identification.
Error Handling¶
-
HyperFile.GetError(self)¶ Get the error from the last hyperfile operation.
- Return type
int
- Returns
The error number.
-
HyperFile.SetError(self, err)¶ Set the error value for this hyperfile.
- Parameters
err (int) – The error number.
File Context¶
-
HyperFile.GetDocument(self)¶ Gets the active document for the hyper file operation.
Note
Can be None, for example when saving layouts.
- Return type
Optional[c4d.documents.BaseDocument]
- Returns
The document or None.
-
HyperFile.GetFileVersion(self)¶ Get the version of Cinema 4D that wrote the file.
Note
Only valid during reading a Cinema 4D scene, object, material etc.
- Return type
int
- Returns
The file version.
-
HyperFile.GetFilterFlags(self)¶ Gets the filter flags, the value is valid only during a Load or a Merge.
New in version R21.108.
- Return type
int
- Returns
The filter flags:
SCENEFILTER_NONE
None.
SCENEFILTER_OBJECTS
Load/save objects.
SCENEFILTER_MATERIALS
Load/save materials.
SCENEFILTER_DIALOGSALLOWED
Flag to inform a plugin that a dialog can be displayed. If this flag is not set then no dialogs must be opened.
SCENEFILTER_PROGRESSALLOWED
Flag to inform a plugin that a progress bar can be displayed. The progress bar can be set by calling
StatusSetBar().SCENEFILTER_MERGESCENE
Flag to inform a plugin that this is a merge operation, i.e. the document that is inserted to is an existing scene.
SCENEFILTER_NONEWMARKERS
Objects loaded from disk will keep their markers.
SCENEFILTER_SAVECACHES
For melange export only. Caches of objects will also be written (only supported by Cinema 4D format). This is the same as the global option “Save Polygon Objects for Melange Exchange”.
SCENEFILTER_NOUNDO
Use together with SCENEFILTER_MERGESCENE to avoid that undos are created for the merge operation.
SCENEFILTER_SAVE_BINARYCACHE
Save the binary compiled shaders with the scene (only for Cinema 4D format).
SCENEFILTER_IDENTIFY_ONLY
Do not load the whole document, identify it only.
SCENEFILTER_ONLY_RENDERDATA
Only load render settings. If this flag is set, SCENEFILTER_OBJECTS and SCENEFILTER_MATERIALS are ignored.
SCENEFILTER_IGNOREMISSINGPLUGINSINNONACTIVERENDERDATA
Ignore all missing plugins which are part of a non-active render data.
SCENEFILTER_IGNOREXREFS
New in version R16.038: Avoid that included X-Refs will be loaded.
SCENEFILTER_DONTCORRECTOUTPUTFORMAT
Do not change unknown output formats in render settings.
File Lifecycle¶
-
HyperFile.Close(self)¶ Closes the hyper file.
- Return type
bool
- Returns
True on success.
-
HyperFile.Open(self, ident, filename, mode, error_dialog)¶ Opens the hyper file.
- Parameters
ident (int) – File identification.
filename (Union[str, c4d.storage.MemoryFileStruct]) – File to open.
mode (int) –
File mode:
FILEOPEN_APPEND
Open an existing file for writing and set the position to the end of that file.
FILEOPEN_READ
Open the file for reading.
FILEOPEN_WRITE
Create a new file for writing. Warning: If the file name points to an existing file, it will be overwritten.
FILEOPEN_READWRITE
Open the file for both reading and writing.
FILEOPEN_READ_NOCACHE
Private.
FILEOPEN_SHAREDREAD
Private.
FILEOPEN_SHAREDWRITE
Private.
error_dialog (int) –
File error dialog:
FILEDIALOG_NONE
Never show an error dialog.
FILEDIALOG_ANY
Show an error dialog for any error.
FILEDIALOG_IGNOREOPEN
Do not show an error dialog if the file does not exist, otherwise like FILEDIALOG_ANY.
- Return type
bool
- Returns
True if the hyper file could be opened, otherwise False.
Geometric Reading¶
-
HyperFile.ReadMatrix(self)¶ Read a
Matrixfrom the hyperfile.- Return type
Optional[c4d.Matrix]
- Returns
The matrix or None if reading failed.
-
HyperFile.ReadMatrix32(self)¶ Read a
Matrixfrom the hyperfile.New in version R16.021.
- Return type
Optional[c4d.Matrix]
- Returns
The matrix or None if reading failed.
-
HyperFile.ReadMatrix64(self)¶ Read a double precision
Matrixfrom the hyperfile.New in version R15.037.
- Return type
Optional[c4d.Matrix]
- Returns
The matrix or None if reading failed.
-
HyperFile.ReadVector(self)¶ Read a
Vectorfrom the hyperfile.- Return type
Optional[c4d.Vector]
- Returns
The vector or None if reading failed.
-
HyperFile.ReadVector32(self)¶ Read a
Vectorfrom the hyperfile.New in version R16.021.
- Return type
Optional[c4d.Vector]
- Returns
The vector or None if reading failed.
-
HyperFile.ReadVector64(self)¶ Read a double precision
Vectorfrom the hyperfile.New in version R15.037.
- Return type
Optional[c4d.Vector]
- Returns
The vector or None if reading failed.
Geometric Writing¶
-
HyperFile.WriteMatrix(self, v)¶ Write a
Matrixto the hyperfile.- Parameters
v (c4d.Matrix) – The value to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
-
HyperFile.WriteMatrix32(self, v)¶ Write a
Matrixto the hyperfile.New in version R16.021.
- Parameters
v (c4d.Matrix) – The value to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
-
HyperFile.WriteMatrix64(self, v)¶ Write a double precision
Matrixto the hyperfile.New in version R15.037.
- Parameters
v (c4d.Matrix) – The value to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
-
HyperFile.WriteVector(self, v)¶ Write a
Vectorto the hyperfile.- Parameters
v (c4d.Vector) – The value to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
-
HyperFile.WriteVector32(self, v)¶ Write a
Vectorto the hyperfile.New in version R16.021.
- Parameters
v (c4d.Vector) – The value to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
-
HyperFile.WriteVector64(self, v)¶ Write a double precision
Vectorto the hyperfile.New in version R15.037.
- Parameters
v (c4d.Vector) – The value to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
Numeric Reading¶
-
HyperFile.ReadChar(self)¶ Read a character from the hyperfile.
- Return type
Optional[int]
- Returns
The character or None if reading failed.
-
HyperFile.ReadFloat(self)¶ Read a float from the hyperfile.
New in version R15.037.
- Return type
Optional[float]
- Returns
The float or None if reading failed.
-
HyperFile.ReadFloat32(self)¶ Read a float from the hyperfile.
New in version R16.021.
- Return type
Optional[float]
- Returns
The float or None if reading failed.
-
HyperFile.ReadFloat64(self)¶ Read a double precision float from the hyperfile.
New in version R15.037.
- Return type
Optional[float]
- Returns
The float or None if reading failed.
-
HyperFile.ReadInt16(self)¶ Read a signed word from the hyperfile.
New in version R15.037.
- Return type
Optional[int]
- Returns
The unsigned word or None if reading failed.
-
HyperFile.ReadInt32(self)¶ Read an int from the hyperfile.
New in version R15.037.
- Return type
Optional[int]
- Returns
The unsigned int or None if reading failed.
-
HyperFile.ReadInt64(self)¶ Read a double precision int from the hyperfile.
New in version R15.037.
- Return type
Optional[int]
- Returns
The value or None if reading failed.
-
HyperFile.ReadUChar(self)¶ Read an unsigned character from the hyperfile.
- Return type
Optional[int]
- Returns
The unsigned character or None if reading failed.
-
HyperFile.ReadUInt16(self)¶ Read an unsigned word from the hyperfile.
New in version R15.037.
- Return type
Optional[int]
- Returns
The unsigned word or None if reading failed.
-
HyperFile.ReadUInt32(self)¶ Read an unsigned int from the hyperfile.
New in version R15.037.
- Return type
Optional[int]
- Returns
The unsigned int or None if reading failed.
-
HyperFile.ReadUInt64(self)¶ Read a double precision unsigned int from the hyperfile.
New in version R16.021.
- Return type
Optional[int]
- Returns
The value or None if reading failed.
Numeric Writing¶
-
HyperFile.WriteChar(self, v)¶ Write a character to the hyperfile.
- Parameters
v (int) – A char to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
-
HyperFile.WriteFloat32(self, v)¶ Write a float value to the hyperfile.
New in version R16.021.
- Parameters
v (float) – The value to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
-
HyperFile.WriteFloat64(self, v)¶ Write a double precision float value to the hyperfile.
New in version R15.037.
- Parameters
v (float) – The value to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
-
HyperFile.WriteInt16(self, v)¶ Write a signed short int to the hyperfile.
New in version R15.037.
- Parameters
v (int) – The value to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
-
HyperFile.WriteInt32(self, v)¶ Write an int to the hyperfile.
New in version R15.037.
- Parameters
v (int) – The value to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
-
HyperFile.WriteInt64(self, v)¶ Write a double precision int value to the hyperfile.
New in version R15.037.
- Parameters
v (int) – The integer to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
-
HyperFile.WriteUChar(self, v)¶ Write a very short int to the hyperfile.
- Parameters
v (int) – The value to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
-
HyperFile.WriteUInt16(self, v)¶ Write an unsigned short int to the hyperfile.
New in version R15.037.
- Parameters
v (int) – The value to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
-
HyperFile.WriteUInt32(self, v)¶ Write an unsigned int to the hyperfile.
New in version R15.037.
- Parameters
v (int) – The value to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
-
HyperFile.WriteUInt64(self, v)¶ Write a double precision unsigned int value to the hyperfile.
New in version R15.037.
- Parameters
v (int) – The integer to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
Scalar And Text Reading¶
-
HyperFile.ReadBool(self)¶ Read a bool from the hyperfile.
- Return type
Optional[bool]
- Returns
The bool or None if reading failed.
-
HyperFile.ReadFilename(self)¶ Read a path from the hyperfile.
- Return type
Optional[str]
- Returns
The path or None if reading failed.
-
HyperFile.ReadString(self)¶ Read a string from the hyperfile.
- Return type
Optional[str]
- Returns
The string or None if reading failed.
-
HyperFile.ReadTime(self)¶ Read a
BaseTimefrom the hyperfile.- Return type
Optional[c4d.BaseTime]
- Returns
The time or None if reading failed.
Scalar And Text Writing¶
-
HyperFile.WriteBool(self, v)¶ Write a bool to the hyperfile.
- Parameters
v (bool) – The value to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
-
HyperFile.WriteFilename(self, v)¶ Write a path to the hyperfile.
- Parameters
v (str) – The path to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
-
HyperFile.WriteString(self, v)¶ Write a string to the hyperfile.
- Parameters
v (str) – The value to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
-
HyperFile.WriteTime(self, v)¶ Write a
BaseTimeto the hyperfile.- Parameters
v (c4d.BaseTime) – The value to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
Structured Data Reading¶
-
HyperFile.ReadContainer(self)¶ Read a container from the hyperfile.
- Return type
Optional[c4d.bitmaps.BaseBitmap]
- Returns
The container or None if reading failed.
-
HyperFile.ReadData(self)¶ Read a data from the hyperfile.
Note
Please check the constructor of GeData in the C++ SDK to see what type this method accepts.
- Return type
Optional[Any]
- Returns
The value or None if reading failed.
-
HyperFile.ReadImage(self)¶ Read a bitmap from the hyperfile.
- Return type
Optional[c4d.bitmaps.BaseBitmap]
- Returns
The bitmap or None if reading failed.
-
HyperFile.ReadMemory(self)¶ Read a block of memory from the hyperfile.
Note
Only use this when you need to, be aware that the byte sequences will not be platform independent.
- Return type
Optional[bytes]
- Returns
The value or None if reading failed.
Structured Data Writing¶
-
HyperFile.WriteContainer(self, v)¶ Write the settings in a
BaseContainerto the hyperfile.- Parameters
v (c4d.BaseContainer) – The container to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the value.
-
HyperFile.WriteData(self, v)¶ Write data to the container.
Note
Please check the constructor of GeData in the C++ SDK to see what type this method accepts.
- Parameters
v (any) – The data.
- Return type
bool
- Returns
Success of writing the value.
-
HyperFile.WriteImage(self, v, format, data, savebits=1)¶ Write an image to the hyperfile.
- Parameters
v (c4d.bitmaps.BaseBitmap) – The bitmap to write to the hyperfile.
format (int) –
The image format:
FILTER_TIF
TIFF.
FILTER_TGA
TGA.
FILTER_BMP
BMP.
FILTER_IFF
IFF.
FILTER_JPG
JPEG.
FILTER_PICT
PICT.
FILTER_PSD
PSD.
FILTER_RLA
RLA.
FILTER_RPF
RPF.
FILTER_B3D
BodyPaint 3D.
FILTER_TIF_B3D
TIFF BodyPaint 3D.
FILTER_PSB
PSB.
FILTER_AVI
AVI Movie.
FILTER_MOVIE
Quicktime Movie.
FILTER_QTVRSAVER_PANORAMA
QTVR Panorama.
FILTER_QTVRSAVER_OBJECT
QTVR Object.
FILTER_HDR
HDR.
FILTER_EXR_LOAD
EXR (Load).
FILTER_EXR
EXR.
FILTER_PNG
PNG.
FILTER_IES
IES.
FILTER_B3DNET
BodyPaint 3D NET. Private.
FILTER_DPX
DPX.
FILTER_DDS
New in version R19: DDS.
data (Optional[c4d.BaseContainer]) –
A container with additional format settings, or None.
Symbol ID
Description
SAVEBIT_NONE
None.
SAVEBIT_ALPHA
Save the alpha channel(s) in the file. (For filter plugins, do not save an alpha channel if this is not set.)
SAVEBIT_MULTILAYER
Save multiple layers.
SAVEBIT_USESELECTEDLAYERS
Use selected layers.
SAVEBIT_USE16BITCHANNELS
Use 16-bit channels.
SAVEBIT_GREYSCALE
Save in grayscale mode.
SAVEBIT_INTERNALNET
Private.
SAVEBIT_DONTMERGE
Avoid merging of layers in BodyPaint 3D files.
SAVEBIT_USE32BITCHANNELS
Use 32-bit channels.
SAVEBIT_SAVERENDERRESULT
Private.
SAVEBIT_FIRSTALPHA_ONLY
Private.
SAVEBIT_KEEP_COLOR_MODE
Private.
savebits (int) –
The save bits:
Symbol ID
Description
SAVEBIT_NONE
None.
SAVEBIT_ALPHA
Save the alpha channel(s) in the file. (For filter plugins, do not save an alpha channel if this is not set.)
SAVEBIT_MULTILAYER
Save multiple layers.
SAVEBIT_USESELECTEDLAYERS
Use selected layers.
SAVEBIT_USE16BITCHANNELS
Use 16-bit channels.
SAVEBIT_GREYSCALE
Save in grayscale mode.
SAVEBIT_INTERNALNET
Private.
SAVEBIT_DONTMERGE
Avoid merging of layers in BodyPaint 3D files.
SAVEBIT_USE32BITCHANNELS
Use 32-bit channels.
SAVEBIT_SAVERENDERRESULT
Private.
SAVEBIT_FIRSTALPHA_ONLY
Private.
SAVEBIT_KEEP_COLOR_MODE
Private.
- Return type
bool
- Returns
Success of writing the image.
-
HyperFile.WriteMemory(self, data)¶ Write a block of memory to the hyperfile.
Note
Only use this when you need to, be aware that the byte sequences will not be platform independent.
- Parameters
data (bytearray) – The data to write to the hyperfile.
- Return type
bool
- Returns
Success of writing the data.