(self, context)
| 246 | |
| 247 | |
| 248 | def export_node_tree(self, context): |
| 249 | to_export = [] |
| 250 | # export_type = context.scene.node_io_export_type |
| 251 | export_path = bpy.path.abspath(context.scene.node_io_export_path) |
| 252 | folder_path = None |
| 253 | folder_name = None |
| 254 | node_tree = context.space_data.node_tree |
| 255 | |
| 256 | # check data |
| 257 | if not export_path: |
| 258 | self.report({"ERROR"}, "NodeIO: Empty Export Path") |
| 259 | return |
| 260 | elif not path.exists(export_path): |
| 261 | self.report({"ERROR"}, "NodeIO: Export Path '{}' Does Not Exist".format(export_path)) |
| 262 | return |
| 263 | elif node_tree is None: |
| 264 | self.report({"ERROR"}, "NodeIO: No Active Node Tree") |
| 265 | return |
| 266 | |
| 267 | # COLLECT NEED INFORMATION: to_export allows multiple node_trees at a time. Info formatted into dict |
| 268 | # {"nodes":____, "links":____, "name":____, "bl_idname":_____} |
| 269 | if node_tree.bl_idname in ("ShaderNodeTree", "MitsubaShaderNodeTree"): |
| 270 | to_export.append({"nodes": node_tree.nodes, "links": node_tree.links, "name": |
| 271 | context.active_object.active_material.name, "bl_idname": node_tree.bl_idname}) |
| 272 | elif node_tree.bl_idname in ("an_AnimationNodeTree", "SverchCustomTreeType"): |
| 273 | to_export.append({"nodes": node_tree.nodes, "links": node_tree.links, "name": node_tree.name, |
| 274 | "bl_idname": node_tree.bl_idname}) |
| 275 | |
| 276 | # create folder if more then one node_tree, or if paths are being made relative and there might be dependencies |
| 277 | if len(to_export) > 1 or context.scene.node_io_dependency_save_type == "2": |
| 278 | try: |
| 279 | if len(to_export) > 1: |
| 280 | folder_name = "mat_group_{}".format(len(to_export)) |
| 281 | else: |
| 282 | folder_name = to_export[0]['name'] |
| 283 | folder_path = export_path + os_file_sep + folder_name |
| 284 | mkdir(folder_path) |
| 285 | except FileExistsError: |
| 286 | self.report({"INFO"}, "NodeIO: Directory '{}' Already Exists, Will Add/Overwrite Files In Directory". |
| 287 | format(folder_path)) |
| 288 | else: |
| 289 | folder_path = export_path |
| 290 | |
| 291 | # export materials |
| 292 | for node_tree in to_export: |
| 293 | json_root = {} |
| 294 | names = {} |
| 295 | data, dependencies = [], [] |
| 296 | m_links, m_nodes = node_tree["links"], node_tree["nodes"] |
| 297 | |
| 298 | # get node data |
| 299 | collect_nodes(m_nodes, m_links, dependencies, names, "main", data) |
| 300 | |
| 301 | # write data |
| 302 | # material attribs |
| 303 | t = datetime.now() |
| 304 | date_string = "{}/{}/{} at {}:{}:{} in {}".format(t.month, t.day, t.year, t.hour, t.minute, |
| 305 | t.second, tzname[0]) |
no test coverage detected