def execute(self, context): if not self.id_tree: msg = "Node tree is not specified" error(msg) self.report({'ERROR'}, msg) return {'CANCELLED'} if not self.preset_name: msg = "Preset name is not specified" error(msg) self.report({'ERROR'}, msg) return {'CANCELLED'} ng = bpy.data.node_groups[self.id_tree] nodes = list(filter(lambda n: n.select, ng.nodes)) if not len(nodes): msg = "There are no selected nodes to export" error(msg) self.report({'ERROR'}, msg) return {'CANCELLED'} layout_dict = create_dict_of_tree(ng, selected=True) preset = SvPreset(name=self.preset_name) preset.make_add_operator() destination_path = preset.path write_json(layout_dict, destination_path) msg = 'exported to: ' + destination_path self.report({"INFO"}, msg) info(msg) return {'FINISHED'}
def execute(self, context): ng = bpy.data.node_groups[self.id_tree] destination_path = self.filepath if not destination_path.lower().endswith('.json'): destination_path += '.json' # future: should check if filepath is a folder or ends in \ layout_dict = create_dict_of_tree(ng) if not layout_dict: msg = 'no update list found - didn\'t export' self.report({"WARNING"}, msg) warning(msg) return {'CANCELLED'} write_json(layout_dict, destination_path) msg = 'exported to: ' + destination_path self.report({"INFO"}, msg) info(msg) if self.compress: comp_mode = zipfile.ZIP_DEFLATED # destination path = /a../b../c../somename.json base = basename(destination_path) # somename.json basedir = dirname(destination_path) # /a../b../c../ # somename.zip final_archivename = base.replace('.json', '') + '.zip' # /a../b../c../somename.zip fullpath = os.path.join(basedir, final_archivename) with zipfile.ZipFile(fullpath, 'w', compression=comp_mode) as myzip: myzip.write(destination_path, arcname=base) info('wrote:', final_archivename) return {'FINISHED'}