[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4187] contrib/py/scripts/addons/ io_atomblend_utilities:

Clemens Barth barth at root-1.de
Mon Jan 21 23:42:28 CET 2013


Revision: 4187
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4187
Author:   blendphys
Date:     2013-01-21 22:42:26 +0000 (Mon, 21 Jan 2013)
Log Message:
-----------

Yet an other new feature: the 'default' values (size, object type and material)
can be transferred on selected atoms.

Blendphys.

Modified Paths:
--------------
    contrib/py/scripts/addons/io_atomblend_utilities/__init__.py
    contrib/py/scripts/addons/io_atomblend_utilities/io_atomblend_utilities.py

Modified: contrib/py/scripts/addons/io_atomblend_utilities/__init__.py
===================================================================
--- contrib/py/scripts/addons/io_atomblend_utilities/__init__.py	2013-01-21 17:01:46 UTC (rev 4186)
+++ contrib/py/scripts/addons/io_atomblend_utilities/__init__.py	2013-01-21 22:42:26 UTC (rev 4187)
@@ -24,7 +24,7 @@
 #
 #  Start of project              : 2011-12-01 by Clemens Barth
 #  First publication in Blender  : 2012-11-03
-#  Last modified                 : 2013-01-20
+#  Last modified                 : 2013-01-21
 #
 #  Acknowledgements 
 #  ================
@@ -123,6 +123,11 @@
 
         box = layout.box()
         col = box.column(align=True)
+        col.label(text="Default values")
+        col.operator("atom_blend.default_atoms") 
+
+        box = layout.box()
+        col = box.column(align=True)
         col.label(text="Separate atoms")
         col2 = col.column()
         col2.active = (bpy.context.mode == 'EDIT_MESH')
@@ -278,6 +283,24 @@
 
 
 # Button for separating single atoms from a dupliverts structure
+class DefaultAtom(Operator):
+    bl_idname = "atom_blend.default_atoms"
+    bl_label = "Default"
+    bl_description = ("Use default shapes and colors for atoms.")
+
+    def execute(self, context):
+        scn = bpy.context.scene.atom_blend
+        io_atomblend_utilities.choose_objects("ATOM_DEFAULT_OBJ", 
+                                              scn.obj_who, 
+                                              None, 
+                                              None,
+                                              None,
+                                              None,
+                                              None) 
+        return {'FINISHED'}
+
+
+# Button for separating single atoms from a dupliverts structure
 class ReplaceAtom(Operator):
     bl_idname = "atom_blend.replace_atom"
     bl_label = "Replace"

Modified: contrib/py/scripts/addons/io_atomblend_utilities/io_atomblend_utilities.py
===================================================================
--- contrib/py/scripts/addons/io_atomblend_utilities/io_atomblend_utilities.py	2013-01-21 17:01:46 UTC (rev 4186)
+++ contrib/py/scripts/addons/io_atomblend_utilities/io_atomblend_utilities.py	2013-01-21 22:42:26 UTC (rev 4187)
@@ -249,7 +249,7 @@
         else:
             change_objects.append(obj)
         
-    # Consider all objects, which are in the latter list.
+    # And now, consider all objects, which are in the list 'change_objects'.
     for obj in change_objects:
         if len(obj.children) != 0:
             for obj_child in obj.children:
@@ -313,7 +313,6 @@
                 else:        
                     obj.scale = (element.radii[int(radius_type)],) * 3
 
-
     # Modify atom sticks 
     if action_type == "STICKS_RADIUS_ALL" and ('Sticks_Cups' in obj.name or 
                                        'Sticks_Cylinder' in obj.name):
@@ -364,8 +363,41 @@
         bpy.ops.object.select_all(action='DESELECT')
         obj.select = True
         bpy.ops.object.delete()            
-                   
 
+    # Default shapes and colors for atoms
+    if action_type == "ATOM_DEFAULT_OBJ" and "Stick" not in obj.name:
+
+        scn = bpy.context.scene.atom_blend
+        
+        # Copy important details from the object.
+        name = obj.name
+        location = obj.location
+        parent = obj.parent       
+
+        # Remove the "_repl" if existing
+        if "_repl" in name:
+            name = name[:name.find("_repl")]
+
+        # Create new material
+        material = bpy.data.materials.new(name)
+        material.name = material.name
+        
+        # Create new object
+        new_obj = draw_obj('0b',name,location,Vector((1.0,1.0,1.0)),material)
+        new_obj.parent = parent
+
+        # Change size and color of the new object            
+        for element in ELEMENTS:
+            if element.name in obj.name:
+                new_obj.scale = (element.radii[0],) * 3
+                new_obj.active_material.diffuse_color = element.color
+                
+        # Finally, delete the old object
+        bpy.ops.object.select_all(action='DESELECT')
+        obj.select = True
+        bpy.ops.object.delete()    
+                           
+
 # Initialization of the list 'ELEMENTS'.
 def read_elements():
 



More information about the Bf-extensions-cvs mailing list