Holaps
Bien, la pregunta es sencilla...
¿Se pueden grabar datos a un archivo en formato binario con Max Script?
A priori la función createFile no tiene ningún parámetro para especificar el formato de grabación,
en cambio sí lo tiene la función openFile mode:" ". Lo que hago es crear el archivo normalmente
con createFile y luego closeFile, para finalmente hacer un openFile con "wb". Aún así sigo
en las mismas. Todo me hace suponer k eso solo sirve para reconocer el archivo k abres de
forma binaria, para luego acabar guardandolo en modo texto XD
También he visto k no hay nada aparte de print y format, y estas funciones solo actuan con streams
de cadena....así k creo k me van a dar por saco.
Ale, asias de antemano y un saludo
No sé si desde la versión 5 o 6 de MAX, MAXScript soporta I/O para archivos binarios. Aquí está lo que pone en la ayuda de MAXScript.
CitarBinStream for Binary Reading and Writing
fopen
Opens a file for reading or writing based on the mode parameter. The function will return a BinStream value.
The fopen method parses the mode string looking for exactly one of {rwa}, at most one '+', at most one of {tb}, at most one of {SR}, at most one 'T', and at most one 'D'.
The rwatb+ modes are described in the FileStream Values topic topic
The additional mode options for fopen are:
S - access is primarily sequentional
R - access is primarily random
T - temporary storage file, try not to flush
D - file is deleted when last handle is closed
FClose
Close a BinStream value. Returns True if it successfully closed the BinStream.
fseek <#seek_set | #seek_cur | #seek_end>
Move the file pointer to the specified location based off the seek parameter.
#seek_set - base off start of file.
#seek_cur - base off current position.
#seek_end - base off end of file.
ftell
Returns the current file pointer position.
WriteByte [#signed | #unsigned]
Writes a Integer to the file as one byte. Returns True if write was successful.
WriteShort [#signed | #unsigned]
Writes a Integer to the file as two bytes. Returns True if write was successful.
WriteLong [#signed | #unsigned]
Writes a Integer to the file as four bytes. Returns True if write was successful.
WriteFloat
Writes a Float to the file as four bytes. Returns True if write was successful.
WriteString
Writes a string to the file. Returns True if write was successful.
ReadByte [#signed | #unsigned]
Read a one byte value and return as an Integer.
ReadShort [#signed | #unsigned]
Read a two byte value and return as an Integer.
ReadLong [#signed | #unsigned]
Read a four byte value and return as an Integer.
ReadFloat
Read a four byte value and return as an Float.
ReadString
Read a string from the file.
Example:
f=fopen "c:\test.bin" "wb"
WriteString f "String"
WriteByte f 64
WriteShort f 128
WriteLong f 256
WriteFloat f 512.0
WriteString f "gnirtS"
WriteLong f (ftell f)
fclose f
f=fopen "c:\test.bin" "rb"
ReadString f
ReadByte f
ReadShort f
ReadLong f
ReadFloat f
ReadString f
ftell f
ReadLong f
fclose f
Saludos.
Gracias Jonny
Aprovexo para decir que la refde de Max Script es una puta basura XD
Si miras en filestream no hay ningún linkado a esa página, tienes k poner en el índice "BinStream" como
si fueras adivino XD
La verdad es k Max Script es una pasada cuando te acostumbras a utilizarlo (y sobre todo cuando aprendes a usar la ayuda XD), pero la ref se podría mejorar bastante la verdad....
En fin, gracias de nuevo!
Saludos