How to store BaseShader to HyperFile
-
I'm trying to store the Shaders created in my plugin into Hyperfile for next use.
I can store the GetDataInstance() of the shader, but when I encounter layer shader, the internal shaders can't be stored.
So I'm wondering if I can store the shader directly to the hyperfile. -
Hey @gheyret,
Thank you for reaching out to us. To store multiple nodes in a HyperFile, you can use HyperFile.WriteData as GeData can wrap a
BaseList2D
. The alternative would be to just use C4DAtom.Write or.WriteObject
. What to use concretely depends a bit on what you are doing.In general I would also avoid serializing nodes myself, but in some cases it can be necessary, it again depends on the case.
Cheers,
Ferdinand -
Hi @ferdinand
Thank you for your reply.
I try to useHyperFile.WriteData
to store my shader and save it on my local path.
And when I try to read the hyperfile to get that shader, that return None for me.
This is my test code:import c4d key = 12345 path = "..." def store_shader(data): hf = c4d.storage.HyperFile() if hf.Open(ident=key, filename=path, mode=c4d.FILEOPEN_WRITE, error_dialog=c4d.FILEDIALOG_NONE): hf.WriteData(data) hf.Close() return True return False def read_shader(): hf = c4d.storage.HyperFile() if hf.Open(ident=key, filename=path, mode=c4d.FILEOPEN_READ, error_dialog=c4d.FILEDIALOG_NONE): data = hf.ReadData() hf.Close() return data return None def main() -> None: shader = doc.GetActiveMaterial()[c4d.MATERIAL_COLOR_SHADER] # this will print True print(store_shader(shader)) # this will print None, the shader is missing? print(read_shader()) if __name__ == '__main__': main()
-
Hey @gheyret,
sorry, today is a bank holiday in Germany, I just answered this on the side. This probably means nodes have not been implemented in the Python wrapper for
HyerFile.WriteData
. I would try my luck with theC4DAtom
methods then.Cheers,
Ferdinand -
it's okay, It's not a big rush for me.
Hope you enjoy your holiday.
Cheers~ -
Hey @gheyret,
okay, I had a brief look, and I could not get the shader deserialization to work either. Not sure why, I think I was passing the wrong disk level. This is too much of a complex problem as that I could answer this on the side, we will have a closer look after our company meeting.
I would recommend to use
c4d
files in the mean time to store your shaders as materials in a file. Alternatively, you could also store them as assets if you want to get all fancy.Cheers,
Ferdinand -
Hi @ferdinand ,
Yeah! I'm actually considering saving the shader to
.c4d
file as well.
But it would be great if posible to store BaseList2D in Hyperfile.Thank you!
Cheers!