From 4009ff189d59f7cd69370aa94178d04a7ee60dac Mon Sep 17 00:00:00 2001 From: Clemens Barth Date: Fri, 21 Jan 2022 17:54:49 +0100 Subject: io_mesh_atomic, utility panel: bug in option 'Default values' - Error message "'NoneType' object has no attribute 'nodes'" because of wrong handling of the material properties. - After bug removal, the standard size and material properties can be assigned to all selected atom strctures. --- io_mesh_atomic/utility_panel.py | 45 +++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/io_mesh_atomic/utility_panel.py b/io_mesh_atomic/utility_panel.py index 9910bb8a..07974777 100644 --- a/io_mesh_atomic/utility_panel.py +++ b/io_mesh_atomic/utility_panel.py @@ -492,27 +492,41 @@ def modify_objects(action_type, if atom.parent != None: atom.hide_set(True) - # Default shapes and colors for atoms + # Default shape and colors for atoms if action_type == "ATOM_DEFAULT_OBJ" and "STICK" not in atom.name.upper(): scn = bpy.context.scene.atom_blend - # Create new material - new_material = bpy.data.materials.new("tmp") - # Create new object (NURBS sphere = '1b') - new_atom = draw_obj('1b', atom, new_material) - new_atom.active_material = new_material - new_material = draw_obj_material('0', new_material) - - # Change size and color of the new object + # We first obtain the element form the list of elements. for element in ELEMENTS: - if element.name in new_atom.name: - new_atom.scale = (element.radii[0],) * 3 - new_atom.active_material.diffuse_color = element.color - new_atom.name = element.name + "_ball" - new_atom.active_material.name = element.name + if element.name in atom.name: break + # Create now a new material with normal properties. Note that the + # 'normal material' initially used during the import could have been + # deleted by the user. This is why we create a new one. + if "vacancy" in atom.name.lower(): + new_material = draw_obj_material('2', atom.active_material) + else: + new_material = draw_obj_material('1', atom.active_material) + # Assign now the correct color. + mat_P_BSDF = new_material.node_tree.nodes['Principled BSDF'] + mat_P_BSDF.inputs['Base Color'].default_value = element.color + new_material.name = element.name + "_normal" + + # Create a new atom because the current atom might have any kind + # of shape. For this, we use a definition from below since it also + # deletes the old atom. + if "vacancy" in atom.name.lower(): + new_atom = draw_obj('2', atom, new_material) + else: + new_atom = draw_obj('1b', atom, new_material) + + # Now assign the material properties, name and size. + new_atom.active_material = new_material + new_atom.name = element.name + "_ball" + new_atom.scale = (element.radii[0],) * 3 + # Separating atoms from a dupliverts structure. def separate_atoms(scn): @@ -1154,7 +1168,6 @@ def read_elements(): # Custom data file: changing color and radii by using the list 'ELEMENTS'. def custom_datafile_change_atom_props(): - for atom in bpy.context.selected_objects: FLAG = False @@ -1213,6 +1226,8 @@ def custom_datafile_change_atom_props(): FLAG = False + bpy.ops.object.select_all(action='DESELECT') + # Reading a custom data file and modifying the list 'ELEMENTS'. def custom_datafile(path_datafile): -- cgit v1.2.3