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 how to use the HyperFile class:
import c4d, os
from c4d import storage as st, gui
YOUR_IDENT=49545 #choose a personal ident
path = os.path.join("/Users", "Dev", "Desktop", "test.file")
print path
def Write(path, key):
#write
print path
hf = st.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:
gui.MessageDialog("Cannot open file to write.")
def Read(path, key):
#read
hf = st.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:
gui.MessageDialog("Cannot open file to read.")
Write(path, YOUR_IDENT)
Read(path, YOUR_IDENT)
Private
Allocates a hyper file.
Return type: | HyperFile |
---|---|
Returns: | The hyper file. |
Opens the hyper file.
Parameters: |
|
||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: |
bool |
||||||||||||||||||
Returns: |
True if the hyper file could be opened, otherwise False. |
Closes the hyper file.
Return type: | bool |
---|---|
Returns: | Return True on success. |
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. |
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. |
Write a signed short int to the hyperfile.
Parameters: | v (int) – The value to write to the hyperfile. |
---|---|
Return type: | bool |
Returns: | Success of writing the value. |
Write a unsigned short int to the hyperfile.
Parameters: | v (int) – The value to write to the hyperfile. |
---|---|
Return type: | bool |
Returns: | Success of writing the value. |
Write an int to the hyperfile.
Parameters: | v (int) – The value to write to the hyperfile. |
---|---|
Return type: | bool |
Returns: | Success of writing the value. |
Write an unsigned int to the hyperfile.
Parameters: | v (int) – The value to write to the hyperfile. |
---|---|
Return type: | bool |
Returns: | Success of writing the value. |
Write a real (single precision) value to the hyperfile.
Parameters: | v (int) – The value to write to the hyperfile. |
---|---|
Return type: | bool |
Returns: | Success of writing the value. |
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. |
Write a BaseTime to the hyperfile.
Parameters: | v (BaseTime) – The value to write to the hyperfile. |
---|---|
Return type: | bool |
Returns: | Success of writing the value. |
Write a Vector to the hyperfile.
Parameters: | v (Vector) – The value to write to the hyperfile. |
---|---|
Return type: | bool |
Returns: | Success of writing the value. |
Write a Matrix to the hyperfile.
Parameters: | v (Matrix) – The value to write to the hyperfile. |
---|---|
Return type: | bool |
Returns: | Success of writing the value. |
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. |
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. |
Write an image to the hyperfile.
Parameters: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: |
bool |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Returns: |
Success of writing the bitmap. |
Write the settings in a BaseContainer to the hyperfile.
Parameters: | v (BaseContainer) – The container to write to the hyperfile. |
---|---|
Return type: | bool |
Returns: | Success of writing the value. |
Write a long value to the hyperfile.
Parameters: | v (long) – The long to write to the hyperfile. |
---|---|
Return type: | bool |
Returns: | Success of writing the value. |
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. |
Read a character from the hyperfile.
Return type: | int |
---|---|
Returns: | The character or None if reading failed. |
Read an unsigned character from the hyperfile.
Return type: | int |
---|---|
Returns: | The unsigned character or None if reading failed. |
Read an unsigned word from the hyperfile.
Return type: | int |
---|---|
Returns: | The unsigned word or None if reading failed. |
Read an unsigned word from the hyperfile.
Return type: | int |
---|---|
Returns: | The unsigned word or None if reading failed. |
Read an int from the hyperfile.
Return type: | int |
---|---|
Returns: | The int or None if reading failed. |
Read an unsigned int from the hyperfile.
Return type: | int |
---|---|
Returns: | The unsigned int or None if reading failed. |
Read a float from the hyperfile.
Return type: | int |
---|---|
Returns: | The float or None if reading failed. |
Read a bool from the hyperfile.
Return type: | int |
---|---|
Returns: | The bool or None if reading failed. |
Read a BaseTime from the hyperfile.
Return type: | int |
---|---|
Returns: | The BaseTime or None if reading failed. |
Read a BaseTime from the hyperfile.
Return type: | int |
---|---|
Returns: | The BaseTime or None if reading failed. |
Read a Vector from the hyperfile.
Return type: | int |
---|---|
Returns: | The Vector or None if reading failed. |
Read a Matrix from the hyperfile.
Return type: | int |
---|---|
Returns: | The Matrix or None if reading failed. |
Read a string from the hyperfile.
Return type: | int |
---|---|
Returns: | The string or None if reading failed. |
Read a path from the hyperfile.
Return type: | int |
---|---|
Returns: | The path or None if reading failed. |
Read a bitmap from the hyperfile.
Return type: | BaseBitmap |
---|---|
Returns: | The bitmap or None if reading failed. |
Read a container from the hyperfile.
Return type: | BaseBitmap |
---|---|
Returns: | The container or None if reading failed. |
Read a long from the hyperfile.
Return type: | long |
---|---|
Returns: | The value or None if reading failed. |
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: | any |
---|---|
Returns: | The value or None if reading failed. |
Get the error from the last hyperfile operation.
Return type: | int |
---|---|
Returns: | The error number. |
Set the error value for this hyperfile.
Parameters: | err (int) – The error number. |
---|
Read the value header from the file. This is only necessary in combination with loops.
Example:
from c4d import storage as st
def ReadSettings(op, hf, level):
while hf.ReadValueHeader()==st.HYPERFILEVALUE_START:
chunk = hf.ReadChunkStart()
if not chunk:
return False
id = chunk["id"]
if id==2:
i1 = hf.ReadLong()
i2 = hf.ReadLong()
#do_here
elif id==3:
i1 = hf.ReadLong()
i2 = hf.ReadLong()
i3 = hf.ReadLong()
#do_here
hf.SkipToEndChunk() #never forget this at the end
if id==0:
break
test = hf.ReadString()
#do here
return True
Set the error value for this hyperfile.
Rtype h: | int | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns: |
The values or None:
|
Skip a given type of value.
Parameters: | h (int) – The header type to skip. |
---|
Write a chunk marker into the file indicating the begining 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: |
|
---|---|
Return type: |
bool |
Returns: |
Success of writing the chunk identification. |
Write a chunk ending marker into the file.
Return type: | bool |
---|---|
Returns: | Success of writing the chunk end. |
Read a chunks identification from the file:
chunk = hf.ReadChunkStart()
if chunk==None: return
id = chunk["id"] # Chunk ID, int
level = chunk["level"] # Chunk Level, int
Return type: | dict{id: int, level: int} |
---|---|
Returns: | The identification or None on failure. |
Read a chunks end marker from the file.
Return type: | bool |
---|---|
Returns: | Success of reading the chunk end. |
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. |
Gets the active document for the hyper file operation. Can be None, for example when saving layouts.
Return type: | BaseDocument |
---|---|
Returns: | The document or None. |
Get the version of CINEMA 4D that wrote the file. (Only valid during reading a CINEMA 4D scene, object, material etc.)
Return type: | int |
---|---|
Returns: | The file version. |