[Bf-extensions-cvs] [84f5f469] master: Fix io_mesh_atomic, utility panel: changing the atom material did not change the material of the sticks

Clemens Barth noreply at git.blender.org
Mon Jan 24 23:52:49 CET 2022


Commit: 84f5f4699232decc2f1a8694312680b9e5159462
Author: Clemens Barth
Date:   Mon Jan 24 23:43:02 2022 +0100
Branches: master
https://developer.blender.org/rBA84f5f4699232decc2f1a8694312680b9e5159462

Fix io_mesh_atomic, utility panel: changing the atom material did not change the material of the sticks

Reason: a material change of both was simply not included.

Now, the atoms and corresponding sticks change the material when
using the utility 'Change atom shape' in the 'Utility Panel'.

===================================================================

M	io_mesh_atomic/utility_panel.py

===================================================================

diff --git a/io_mesh_atomic/utility_panel.py b/io_mesh_atomic/utility_panel.py
index 5dc23d62..20aabd2e 100644
--- a/io_mesh_atomic/utility_panel.py
+++ b/io_mesh_atomic/utility_panel.py
@@ -470,6 +470,12 @@ def modify_objects(action_type,
             else:
                 atom = draw_obj(scn.replace_objs, atom, new_material)
 
+            # If sticks are available, then assign the same material.
+            sticks_cylinder, sticks_cup =find_sticks_of_atom(atom)
+            if sticks_cylinder != None and sticks_cup != None:
+                sticks_cylinder.active_material = new_material
+                sticks_cup.active_material = new_material
+
         # If the atom is the representative ball of a dupliverts structure,
         # then make it invisible.
         if atom.parent != None:
@@ -510,6 +516,12 @@ def modify_objects(action_type,
         new_atom.name = element.name + "_ball"
         new_atom.scale = (element.radii[0],) * 3
 
+        # If sticks are available, then assign the same material.
+        sticks_cylinder, sticks_cup =find_sticks_of_atom(new_atom)
+        if sticks_cylinder != None and sticks_cup != None:
+            sticks_cylinder.active_material = new_material
+            sticks_cup.active_material = new_material
+
 
 # Separating atoms from a dupliverts structure.
 def separate_atoms(scn):
@@ -670,6 +682,48 @@ def get_collection_object(obj):
     return coll
 
 
+# Find the sticks of an atom.
+def find_sticks_of_atom(atom):
+
+    # Initialization of the stick objects 'cylinder' and 'cup'.
+    sticks_cylinder = None
+    sticks_cup = None
+
+    if atom.parent != None:
+
+        D = bpy.data
+        C = bpy.context
+
+        # Get a list of all scenes.
+        cols_scene = [c for c in D.collections if C.scene.user_of_id(c)]
+
+        # This is the collection where the atom is inside.
+        col_atom = atom.parent.users_collection[0]
+
+        # Get the parent collection of the latter collection.
+        col_parent = [c for c in cols_scene if c.user_of_id(col_atom)][0]
+
+        # Get **all** children collections inside this parent collection.
+        parent_childrens = col_parent.children_recursive
+
+        # For each child collection do:
+        for child in parent_childrens:
+            # It should not have the name of the atom collection.
+            if child.name != col_atom.name:
+                # If the sticks are inside then ...
+                if "sticks" in child.name:
+                    # For all objects do ...
+                    for obj in child.objects:
+                        # If the stick objects are inside then note them.
+                        if "sticks_cylinder" in obj.name:
+                            sticks_cylinder = obj
+                        if "sticks_cup" in obj.name:
+                            sticks_cup = obj
+
+    # Return the stick objects 'cylinder' and 'cup'.
+    return sticks_cylinder, sticks_cup
+
+
 # Draw an object (e.g. cube, sphere, cylinder, ...)
 def draw_obj(atom_shape, atom, new_material):



More information about the Bf-extensions-cvs mailing list