I have managed to serialize materials with the following code:
from rna_xml import rna2xml
import bpy
import sys
import os
print(os.getcwd())
scn = bpy.data.scenes["Scene"]
for i in range(len(bpy.data.materials)):
with open(bpy.data.materials[i].name + '.xml', "w+") as f:
print(f)
rna2xml(fw=f.write, root_node="something", root_rna=bpy.data.materials[i].node_tree)
print(bpy.data.materials[i].name)
Now I am trying to de-serialize with the following:
from xml.dom import minidom
from rna_xml import rna2xml, xml2rna
import bpy
import sys
scn = bpy.data.scenes["Scene"]
# reload test
from os import listdir
from os.path import isfile, join
materials_path = '/some/path'
onlyfiles = [f for f in listdir(materials_path) if isfile(join(materials_path, f))]
for f in onlyfiles:
if f.startswith("Materia") and f.endswith("xml") :
print(f)
xml = minidom.parse(join(materials_path, f))
xml2rna(xml)
but I get the following message:
Traceback (most recent call last):
File "/deserialize_materials.py", line 21, in <module>
File "/home/simone/blender/blender-2.92.0-linux64/2.92/scripts/modules/rna_xml.py", line 346, in xml2rna
rna2xml_node(root_xml, root_rna)
File "/home/simone/blender/blender-2.92.0-linux64/2.92/scripts/modules/rna_xml.py", line 251, in rna2xml_node
for attr in xml_node.attributes.keys():
AttributeError: 'NoneType' object has no attribute 'keys'
How do I do this round-trip right?