Read/Write nodes (including hierarchy)
On 20/10/2016 at 09:39, xxxxxxxx wrote:
I still can not figure out how to use C4DAtom.Read(). It appaers that writing the node is easy, but how
do your read it back in? The snippet below doesn't work. Although the Read() method returns True, the
material doesn't reflect the same properties as the one that I wrote (ie. I changed the name and added
a shader to the color channel).
import c4d mat = doc.GetActiveMaterial() # Write the material into the MemoryFileStruct mem = c4d.storage.MemoryFileStruct() mem.SetMemoryWriteMode() hf = c4d.storage.HyperFile() hf.Open(0, mem, c4d.FILEOPEN_WRITE, c4d.FILEDIALOG_NONE) mat.Write(hf) # Read the material from the MemoryFileStruct. data, size = mem.GetData() mem = c4d.storage.MemoryFileStruct() mem.SetMemoryReadMode(data, size) hf = c4d.storage.HyperFile() hf.Open(0, mem, c4d.FILEOPEN_READ, c4d.FILEDIALOG_NONE) mat = c4d.BaseMaterial(c4d.Mmaterial) result = mat.Read(hf, c4d.Mmaterial, 0) # << What to do here? print(result) print(mat) print(mat.GetFirstShader())
Any help would be very much appreciated.
On 21/10/2016 at 04:47, xxxxxxxx wrote:
can you share some information on what you want to achieve? C4DAtom.Read() and Write() are pretty low level function are typically only used internally and are not recommended for third party developers. I'm not sure if these functions can even be utilized properly in plugins.
You could save a Material by storing it in a BaseDocument and save and load this document with the appropriate SaveDocument() and LoadDocument() functions.
On 25/10/2016 at 03:49, xxxxxxxx wrote:
I currently use the workaround with a BaseDocument, but it feels a bit hacky.
And it also increases filesize. And on top of that I am curious how to use the Read() method(s)
correctly, anyway. I just want to write a material (and of course all of its shaders) into a file, nothing
more. Eventually it would make things easier than using the BaseDocument workaround, assuming
you can utilize the Read() method properly from a plugin.
A page in the SDK that describes how to use Read()/Write() or the BaseDocument workaround would
be very nice (preferring the former or a description of both).
PS: I'm actually using C++ but I get the same behaviour in Python for the above snippet.