def main(): filename = os.path.splitext(bpy.data.filepath)[0] + ".xml" file = open(filename, 'w') if 0: # blend file rna_xml.rna2xml(file.write, root_rna=bpy.data, root_rna_skip={"window_managers"}) else: # theme. just another test rna_xml.rna2xml(file.write, root_rna=bpy.context.user_preferences.themes[0], method='ATTR') file.close() # read back to ensure this is valid! from xml.dom.minidom import parse xml_nodes = parse(filename) print("Written:", filename) # test reading back theme if 1: theme = xml_nodes.getElementsByTagName("Theme")[0] rna_xml.xml2rna(theme, root_rna=bpy.context.user_preferences.themes[0],)
def main(): filename = os.path.splitext(bpy.data.filepath)[0] + ".xml" file = open(filename, 'w') if 1: # blend file rna_xml.rna2xml(file.write, root_rna=bpy.data, root_rna_skip={"window_managers"}) else: # theme. just another test rna_xml.rna2xml(file.write, root_rna=bpy.context.user_preferences.themes[0], method='ATTR') file.close() # read back to ensure this is valid! from xml.dom.minidom import parse xml_nodes = parse(filename) print("Written:", filename) # test reading back theme if 1: theme = xml_nodes.getElementsByTagName("Theme")[0] rna_xml.xml2rna( theme, root_rna=bpy.context.user_preferences.themes[0], )
def nestedGroups(self, tree): if hasattr(tree, 'nodes') == False: return False for x in tree.nodes: if x.type == 'GROUP': print('<group name="' + x.node_tree.name + '">') rna2xml(root_node="groupdata", root_rna=x.node_tree) print('</group>') self.nestedGroups(x.node_tree)
def execute(self, context): name = bpy.context.scene.material_props.material_name description = bpy.context.scene.material_props.material_description category = int(bpy.context.scene.material_props.material_category) if name == '': self.message("ERROR", "You must give your material a name") return {"CANCELLED"} if category <= 0: self.message("ERROR", "Please select a category") return {"CANCELLED"} material = bpy.context.active_object.active_material f = io.StringIO() with redirect_stdout(f): rna2xml(root_node="Material", root_rna=material.node_tree) print('<groups>') self.nestedGroups(material.node_tree) print('</groups>') url = bl_info['api_url'] + 'api/import' myobj = { 'xml': '<xml>' + f.getvalue() + '</xml>', 'material_name': name, 'material_description': description, 'material_category': category } if material.get('shadercloud_id'): myobj['material_id'] = material.get('shadercloud_id') api_key = context.preferences.addons['shadercloud'].preferences.api_key # Check if there are any images that need uploading images = [] for node in material.node_tree.nodes: if hasattr(node, "image"): myobj['images[' + node.name + '][image_data]'] = img_to_png( node.image) myobj['images[' + node.name + '][color_space]'] = node.image.colorspace_settings.name headers = { "Authorization": "Bearer " + api_key, "Accept": "application/json" } try: req = requests.post(url, data=myobj, headers=headers) x = req.json() if req.status_code != 200: self.message("ERROR", "API Request Failed: " + x.get('message')) return {"CANCELLED"} except requests.exceptions.RequestException as e: self.message("ERROR", "API Request Failed") return {"CANCELLED"} if (x.get('success') == False): self.message("ERROR", 'Shader Cloud Error: ' + x.get('error')) return {"CANCELLED"} material['shadercloud_id'] = x.get('material_id') self.message("INFO", "Material was succesfully added to Shader Cloud") return {"FINISHED"}
import bpy, rna_xml, random import xml.etree.ElementTree as ET tempfilename = '.rna2xmltemp_' + str(hex(random.randrange(5000)))[2:] + '.xml' filehandle = open(tempfilename, 'w') root_rna = bpy.data fw = filehandle.write rna_xml.rna2xml( fw, root_rna=root_rna, skip_classes=(bpy.types.WindowManager, bpy.types.Operator, bpy.types.Panel, bpy.types.KeyingSet, bpy.types.Header, bpy.types.Screen, bpy.types.Texture, bpy.types.Armature, bpy.types.Brush, bpy.types.Camera, bpy.types.VectorFont, bpy.types.GreasePencil, bpy.types.Lamp, bpy.types.Material, bpy.types.Mesh, bpy.types.Object, bpy.types.ParticleSettings, bpy.types.Speaker), method='ATTR') filehandle.close() skipdata = [ 'cameras', 'objects', 'materials', 'meshes', \ 'lamps', 'screens', 'window_managers','lattices', \ 'metaballs', 'fonts', 'textures', 'brushes', 'shape_keys',\ 'scripts', 'texts', 'speakers', 'sounds', 'armatures', 'particles','grease_pencil', 'worlds'] skipscenesdata = [ 'tool_settings', 'unit_settings', 'render', 'game_settings',\ 'view_settings', 'display_settings', 'cycles', 'object_bases', 'objects', 'orientations' ] tree = ET.parse(tempfilename) root = tree.getroot() for skipped in skipdata:
tempfilename = '.rna2xmltemp_' + str(hex(random.randrange(5000)))[2:] + '.xml' filehandle = open(tempfilename, 'w') root_rna = bpy.data fw = filehandle.write rna_xml.rna2xml(fw, root_rna=root_rna, skip_classes=(bpy.types.WindowManager, bpy.types.Operator, bpy.types.Panel, bpy.types.KeyingSet, bpy.types.Header, bpy.types.Screen, bpy.types.Texture, bpy.types.Armature, bpy.types.Brush, bpy.types.Camera, bpy.types.VectorFont, bpy.types.GreasePencil, bpy.types.Lamp, bpy.types.Material, bpy.types.Mesh, bpy.types.Object, bpy.types.ParticleSettings, bpy.types.Speaker), method = 'ATTR') filehandle.close() skipdata = [ 'cameras', 'objects', 'materials', 'meshes', \ 'lamps', 'screens', 'window_managers','lattices', \ 'metaballs', 'fonts', 'textures', 'brushes', 'shape_keys',\ 'scripts', 'texts', 'speakers', 'sounds', 'armatures', 'particles','grease_pencil', 'worlds']
# # Saves the structure of the selected node in a a file named glossy_rna.xml in # project’s directory. (specified in the root_rna parameter) to this file. import bpy import os from rna_xml import rna2xml file = open(os.path.dirname(bpy.data.filepath) + os.sep + 'glossy_rna.xml', 'w') rna2xml(file.write, root_node = 'glossy_bsdf', root_rna = bpy.context.active_object.active_material.node_tree.nodes.active) file.close()