def test_import_examples(self): for cat in examples_paths: if not examples_paths.get(cat): info("Dir named: %s is empty", cat) continue info("Opening Dir named: %s", cat) examples_set = Path(examples_paths.get(cat)) for listed_path in examples_set.iterdir(): # cast from Path class to dumb string. path = str(listed_path) # assuming these are all jsons for now. name = basename(path) if name in UNITTEST_BLACKLIST: info("Skipping (blacklisted) : %s to permit unit tests to continue", name) continue with self.subTest(file=name): # info("Importing: %s", name) with self.temporary_node_tree("ImportedTree") as new_tree: with self.assert_logs_no_errors(): # Do not try to process imported tree, # that will just take time anyway new_tree.sv_process = False import_tree(new_tree, path) for node in new_tree.nodes: if is_old(node): error_format = "This example contains deprecated node `{}' ({}). Please upgrade the example file." self.fail(error_format.format(node.name, node.bl_idname))
def test_import_examples(self): for cat in examples_paths: if not examples_paths.get(cat): info("Dir named: %s is empty", cat) continue info("Opening Dir named: %s", cat) examples_set = Path(examples_paths.get(cat)) for listed_path in examples_set.iterdir(): # cast from Path class to dumb string. path = str(listed_path) # assuming these are all jsons for now. name = basename(path) if name in UNITTEST_BLACKLIST: info("Skipping (blacklisted) : %s to permit unit tests to continue", name) continue with self.subTest(file=name): info("Importing: %s", name) with self.temporary_node_tree("ImportedTree") as new_tree: with self.assert_logs_no_errors(): # Do not try to process imported tree, # that will just take time anyway new_tree.sv_process = False import_tree(new_tree, path) for node in new_tree.nodes: if is_old(node): error_format = "This example contains deprecated node `{}' ({}). Please upgrade the example file." self.fail(error_format.format(node.name, node.bl_idname))
def test_monad_import(self): with self.temporary_node_tree("ImportedTree") as new_tree: with self.assert_logs_no_errors(): import_tree(new_tree, self.get_reference_file_path("monad_1.json")) self.assert_node_input_equals("ImportedTree", "Monad", "Num X", [[4]])
def execute(self, context): # print(self.id_tree, self.filepath) # if triggered from a non-initialized tree, we first make a tree if self.id_tree == '____make_new____': ng_params = { 'name': basename(self.filepath), 'type': 'SverchCustomTreeType' } ng = bpy.data.node_groups.new(**ng_params) # pass this tree to the active nodeview context.space_data.node_tree = ng else: ng = bpy.data.node_groups[self.id_tree] # Deselect everything, so as a result only imported nodes # will be selected bpy.ops.node.select_all(action='DESELECT') import_tree(ng, self.filepath) context.space_data.node_tree = ng return {'FINISHED'}
def monad_make_unique(node): """ Create a new version of the monad class (duplicate but unique) This will attempt to store the duplicate in a json using create_dict_of_tree (from the Gist IO). The upside is that this will test the pack/unpack routine continuously. The downside is that this will likely expose all the shortcommings that we don't know about because it wasn't being tested extensively. """ node_tree = node.id_data nodes = node_tree.nodes # generate a new copy of monad group node. using ( copy? ) monad_group = bpy.data.node_groups[node.monad.name] new_monad_group = monad_group.copy() new_cls_name = make_new_classname(new_monad_group) # the new tree dict will contain information about 1 node only, and # the node_group too (at the moment) but the node_group data can be ignored. layout_json = create_dict_of_tree(ng=node_tree, identified_node=node) # do not restore links this way. wipe this entry and restore at a later stage. layout_json['update_lists'] = [] # massage content of node_items, to correspond with the new desired name. node_ref = layout_json['nodes'][node.name] node_items = node_ref['params'] node_items['all_props']['name'] = new_monad_group.name node_items['all_props']['cls_bl_idname'] = new_cls_name node_items['monad'] = new_monad_group.name node_items['cls_dict']['cls_bl_idname'] = new_cls_name pre_nodes = set(nodes) # place new empty version of the monad node import_tree(node_tree, nodes_json=layout_json) """ notions..: if (original instance has no connections) then replace it outright. else if mode=='replace': store connections replace instance with new unique instance reconnect old connections elif mode=='dupe_translate': generate unique instance attache node to transform operator. """ # return newly generated node! return (set(node_tree.nodes) ^ pre_nodes).pop()
def import_sverchok_tree(self, name=None): if not SVERCHOK_AVAILABLE: raise ImportError("Sverchok is not available") if not name: name = basename(self.data) json = self.get_json_data() ng = bpy.data.node_groups.new(name=name, type='SverchCustomTreeType') import_tree(ng, nodes_json=json)
def execute(operator, context): # please not be confused: "operator" here references to # SverchPresetAddOperator instance, and "self" references to # SvPreset instance. ntree = context.space_data.node_tree id_tree = ntree.name ng = bpy.data.node_groups[id_tree] # Deselect everything, so as a result only imported nodes # will be selected bpy.ops.node.select_all(action='DESELECT') import_tree(ng, self.path) return {'FINISHED'}
def test_script_uv_import(self): with self.temporary_node_tree("ImportedTree") as new_tree: import_tree(new_tree, self.get_reference_file_path("script_uv.json")) # Check links self.assert_nodes_linked("ImportedTree", "Scripted Node Lite", "verts", "UV Connection", "vertices") self.assert_nodes_linked("ImportedTree", "UV Connection", "vertices", "Viewer Draw", "vertices") self.assert_nodes_linked("ImportedTree", "UV Connection", "data", "Viewer Draw", "edg_pol") # Check random node properties self.assert_node_property_equals("ImportedTree", "UV Connection", "cup_U", False) self.assert_node_property_equals("ImportedTree", "UV Connection", "polygons", 'Edges') self.assert_node_property_equals("ImportedTree", "UV Connection", "dir_check", 'U_dir')
def test_script_uv_import(self): with self.temporary_node_tree("ImportedTree") as new_tree: with self.assert_logs_no_errors(): import_tree(new_tree, self.get_reference_file_path("script_uv.json")) # Check links self.assert_nodes_linked("ImportedTree", "Scripted Node Lite", "verts", "UV Connection", "vertices") self.assert_nodes_linked("ImportedTree", "UV Connection", "vertices", "Viewer Draw", "verts") self.assert_nodes_linked("ImportedTree", "UV Connection", "data", "Viewer Draw", "edges") # Check random node properties self.assert_node_property_equals("ImportedTree", "UV Connection", "cap_U", False) self.assert_node_property_equals("ImportedTree", "UV Connection", "polygons", 'Edges') self.assert_node_property_equals("ImportedTree", "UV Connection", "dir_check", 'U_dir')
def execute(self, context): ng = context.scene.io_panel_properties.import_tree if not ng: self.report( type={'WARNING'}, message= "The tree was not chosen, have a look at property (N) panel") return {'CANCELLED'} import_tree(ng, self.filepath) # set new node tree to active context.space_data.node_tree = ng return {'FINISHED'}
def assert_node_equals_file(self, actual_node, reference_node_name, reference_file_name, imported_tree_name=None): """ Assert that actual_node equals to node named reference_node_name imported from file reference_file_name. This works only for simple nodes. """ if imported_tree_name is None: imported_tree_name = "ImportedTree" try: new_tree = get_or_create_node_tree(imported_tree_name) import_tree(new_tree, self.get_reference_file_path(reference_file_name)) self.assert_nodes_are_equal(actual_node, get_node(reference_node_name, imported_tree_name)) finally: remove_node_tree(imported_tree_name)
def execute(self, context): if not self.id_tree: ng_name = self.new_nodetree_name ng_params = { 'name': ng_name or 'unnamed_tree', 'type': 'SverchCustomTreeType'} ng = bpy.data.node_groups.new(**ng_params) else: ng = bpy.data.node_groups[self.id_tree] import_tree(ng, self.filepath) # set new node tree to active context.space_data.node_tree = ng return {'FINISHED'}
def execute(operator, context): # please not be confused: "operator" here references to # SverchPresetAddOperator instance, and "self" references to # SvPreset instance. ntree = context.space_data.node_tree id_tree = ntree.name ng = bpy.data.node_groups[id_tree] center = SvPreset.get_target_location(ng) # Deselect everything, so as a result only imported nodes # will be selected bpy.ops.node.select_all(action='DESELECT') import_tree(ng, self.path, center = center) bpy.ops.transform.translate('INVOKE_DEFAULT') return {'FINISHED'}
def execute(self, context): if not self.id_tree: ng_name = self.new_nodetree_name ng_params = { 'name': ng_name or 'unnamed_tree', 'type': 'SverchCustomTreeType'} ng = bpy.data.node_groups.new(**ng_params) else: ng = bpy.data.node_groups[self.id_tree] if self.gist_id == 'clipboard': self.gist_id = context.window_manager.clipboard nodes_json = load_json_from_gist(self.gist_id.strip(), self) if not nodes_json: return {'CANCELLED'} # import tree and set new node tree to active import_tree(ng, nodes_json=nodes_json) context.space_data.node_tree = ng return {'FINISHED'}
def execute(self, context): # print(self.id_tree, self.filepath) # if triggered from a non-initialized tree, we first make a tree if self.id_tree == '____make_new____': ng_params = { 'name': basename(self.filepath), 'type': 'SverchCustomTreeType'} ng = bpy.data.node_groups.new(**ng_params) # pass this tree to the active nodeview context.space_data.node_tree = ng else: ng = bpy.data.node_groups[self.id_tree] # Deselect everything, so as a result only imported nodes # will be selected bpy.ops.node.select_all(action='DESELECT') import_tree(ng, self.filepath) context.space_data.node_tree = ng return {'FINISHED'}
def test_mesh_expr_import(self): with self.temporary_node_tree("ImportedTree") as new_tree: import_tree(new_tree, self.get_reference_file_path("mesh.json"))
def test_mesh_expr_import(self): with self.temporary_node_tree("ImportedTree") as new_tree: with self.assert_logs_no_errors(): import_tree(new_tree, self.get_reference_file_path("mesh.json"))
def test_monad_import(self): with self.temporary_node_tree("ImportedTree") as new_tree: import_tree(new_tree, self.get_reference_file_path("monad_1.json")) self.assert_node_property_equals("ImportedTree", "Monad", "amplitude", 0.6199999451637268)
def test_profile_import(self): with self.temporary_node_tree("ImportedTree") as new_tree: import_tree(new_tree, self.get_reference_file_path("profile.json"))