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

Clemens Barth barth at root-1.de
Thu Jan 24 19:47:48 CET 2013


Revision: 4201
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4201
Author:   blendphys
Date:     2013-01-24 18:47:46 +0000 (Thu, 24 Jan 2013)
Log Message:
-----------

And yet again, some major changes:

1. I included some security checks such that changing shapes and materials of 
atoms does not produce errors. For instance, separating atoms from a dupliverts
structure only is possible when the EDIT mode is active. However, when pushing 
the 'separate' button in the OBJECT mode, an error occured. Now, this is
inhibited.

2. Separating atoms from a dupliverts structure: Before, it was done by copying
the properties of the child object and directly creating new objects. Now, the 
child is taken and duplicated (new object). After, the parent of the new object
is removed such that the new object is a 'free' and independent one. Then, 
the location is modified. - All this is repeated for the number of selected 
vertices of the dupliverts structure. Advantage: the shape, size, material, 
etc. are automatically conserved. 

3. When creating new materials, a new name for the material is created such that 
the old material is still existing without any changes of its prarameters.

4. Code cleaning

I think that this is now somewhat a final state. I hope that there will not be 
any other big changes in future.

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-24 13:25:40 UTC (rev 4200)
+++ contrib/py/scripts/addons/io_atomblend_utilities/__init__.py	2013-01-24 18:47:46 UTC (rev 4201)
@@ -24,7 +24,7 @@
 #
 #  Start of project              : 2011-12-01 by Clemens Barth
 #  First publication in Blender  : 2012-11-03
-#  Last modified                 : 2013-01-23
+#  Last modified                 : 2013-01-24
 #
 #  Acknowledgements 
 #  ================

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-24 13:25:40 UTC (rev 4200)
+++ contrib/py/scripts/addons/io_atomblend_utilities/io_atomblend_utilities.py	2013-01-24 18:47:46 UTC (rev 4201)
@@ -174,13 +174,13 @@
     # In the 'EDIT' mode
     if bpy.context.mode == 'EDIT_MESH':
 
-        obj = bpy.context.edit_object
-        bm = bmesh.from_edit_mesh(obj.data)
+        atom = bpy.context.edit_object
+        bm = bmesh.from_edit_mesh(atom.data)
         locations = []
 
         for v in bm.verts:
             if v.select:
-                locations.append(obj.matrix_world * v.co)
+                locations.append(atom.matrix_world * v.co)
                 
         if len(locations) > 1:
             location1 = locations[0]
@@ -223,49 +223,49 @@
                 
         # Put all objects, which are in the layers, into a list.
         change_objects_all = []
-        for obj in bpy.context.scene.objects:
+        for atom in bpy.context.scene.objects:
             for layer in layers:
-                if obj.layers[layer] == True:
-                    change_objects_all.append(obj)                                  
+                if atom.layers[layer] == True:
+                    change_objects_all.append(atom)                                  
     # For selected objects of the visible layer                               
     elif who == "ALL_ACTIVE":
         change_objects_all = []
         # Note all selected objects first.
-        for obj in bpy.context.selected_objects:
-            change_objects_all.append(obj)   
+        for atom in bpy.context.selected_objects:
+            change_objects_all.append(atom)   
                     
     # This is very important now: If there are dupliverts structures, note 
     # only the parents and NOT the children! Otherwise the double work is 
     # done or the system can even crash if objects are deleted. - The 
     # chidlren are accessed anyways (see below).
     change_objects = []
-    for obj in change_objects_all:
-        if obj.parent != None:
+    for atom in change_objects_all:
+        if atom.parent != None:
             FLAG = False
-            for obj2 in change_objects:
-                if obj2 == obj.parent:
+            for atom2 in change_objects:
+                if atom2 == atom.parent:
                    FLAG = True
             if FLAG == False:        
-                change_objects.append(obj)
+                change_objects.append(atom)
         else:
-            change_objects.append(obj)
+            change_objects.append(atom)
         
     # 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:
-                if obj_child.type in {'SURFACE', 'MESH', 'META'}: 
+    for atom in change_objects:
+        if len(atom.children) != 0:
+            for atom_child in atom.children:
+                if atom_child.type in {'SURFACE', 'MESH', 'META'}: 
                     modify_objects(action_type, 
-                                   obj_child,
+                                   atom_child,
                                    radius_all, 
                                    radius_pm, 
                                    radius_type,
                                    radius_type_ionic,
                                    sticks_all)
         else:
-            if obj.type in {'SURFACE', 'MESH', 'META'}:
+            if atom.type in {'SURFACE', 'MESH', 'META'}:
                 modify_objects(action_type, 
-                                   obj,  
+                                   atom,  
                                    radius_all, 
                                    radius_pm, 
                                    radius_type,
@@ -275,7 +275,7 @@
 
 # Modifying the radius of a selected atom or stick
 def modify_objects(action_type, 
-                   obj, 
+                   atom, 
                    radius_all, 
                    radius_pm, 
                    radius_type, 
@@ -283,18 +283,18 @@
                    sticks_all):
 
     # Modify atom radius (in pm) 
-    if action_type == "ATOM_RADIUS_PM" and "Stick" not in obj.name:
-        if radius_pm[0] in obj.name:
-            obj.scale = (radius_pm[1]/100,) * 3
+    if action_type == "ATOM_RADIUS_PM" and "Stick" not in atom.name:
+        if radius_pm[0] in atom.name:
+            atom.scale = (radius_pm[1]/100,) * 3
             
     # Modify atom radius (all selected)
-    if action_type == "ATOM_RADIUS_ALL" and "Stick" not in obj.name:
-        obj.scale *= radius_all      
+    if action_type == "ATOM_RADIUS_ALL" and "Stick" not in atom.name:
+        atom.scale *= radius_all      
               
     # Modify atom radius (type, van der Waals, atomic or ionic) 
-    if action_type == "ATOM_RADIUS_TYPE" and "Stick" not in obj.name:
+    if action_type == "ATOM_RADIUS_TYPE" and "Stick" not in atom.name:
         for element in ELEMENTS:                
-            if element.name in obj.name:
+            if element.name in atom.name:
                 # For ionic radii
                 if radius_type == '3':
                     charge_states = element.radii_ionic[::2]
@@ -308,19 +308,19 @@
 
                     # Is there a charge state?                    
                     if index != []:
-                        obj.scale = (charge_radii[index[0]],) * 3
+                        atom.scale = (charge_radii[index[0]],) * 3
                                             
                 # For atomic and van der Waals radii.
                 else:        
-                    obj.scale = (element.radii[int(radius_type)],) * 3
+                    atom.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):
+    if action_type == "STICKS_RADIUS_ALL" and ('Sticks_Cups' in atom.name or 
+                                       'Sticks_Cylinder' in atom.name):
     
-        bpy.context.scene.objects.active = obj
+        bpy.context.scene.objects.active = atom
         bpy.ops.object.mode_set(mode='EDIT', toggle=False)
-        bm = bmesh.from_edit_mesh(obj.data)
+        bm = bmesh.from_edit_mesh(atom.data)
         
         locations = []
         for v in bm.verts:
@@ -341,93 +341,97 @@
         bpy.context.scene.objects.active = None
 
     # Replace atom objects
-    if action_type == "ATOM_REPLACE_OBJ" and "Stick" not in obj.name:
+    if action_type == "ATOM_REPLACE_OBJ" and "Stick" not in atom.name:
 
         scn = bpy.context.scene.atom_blend
         
         new_material = draw_obj_material(scn.replace_objs_material, 
-                                         obj.active_material)
+                                         atom.active_material)
         
         # Special object (like halo, etc.)
         if scn.replace_objs_special != '0':
-            new_atom = draw_obj_special(scn.replace_objs_special, obj)
-            new_atom.parent = obj.parent
+            new_atom = draw_obj_special(scn.replace_objs_special, atom)
+            new_atom.parent = atom.parent
         # Standard geomtrical objects    
         else:
             # If the atom shape shall not be changed, then:
             if scn.replace_objs == '0':
-                obj.active_material = new_material 
-                if "_repl" not in obj.active_material.name:    
-                    obj.active_material.name += "_repl"
+                atom.active_material = new_material 
                 return {'FINISHED'}
             # If the atom shape shall change, then:
             else:
-                new_atom = draw_obj(scn.replace_objs, obj)
+                new_atom = draw_obj(scn.replace_objs, atom)
                 new_atom.active_material = new_material                
-                new_atom.parent = obj.parent
-        
-                if "_repl" not in new_atom.name:
-                    new_atom.name = new_atom.name + "_repl"
-                if "_repl" not in new_atom.active_material.name:    
-                    new_atom.active_material.name += "_repl"
-            
+                new_atom.parent = atom.parent
+                
+                if "_repl" not in atom.name:
+                    new_atom.name = atom.name + "_repl"
+                else:
+                    new_atom.name = atom.name 
+                    
         # Delete the old object.
         bpy.ops.object.select_all(action='DESELECT')
-        obj.select = True
+        atom.select = True
         bpy.ops.object.delete()            
 
     # Default shapes and colors for atoms
-    if action_type == "ATOM_DEFAULT_OBJ" and "Stick" not in obj.name:
+    if action_type == "ATOM_DEFAULT_OBJ" and "Stick" not in atom.name:
 
         scn = bpy.context.scene.atom_blend     
 
-        # Remove the "_repl" if existing
-        name = obj.name
-        if "_repl" in name:
-            name = name[:name.find("_repl")]
-
         # Create new material
-        new_material = bpy.data.materials.new(name)
+        new_material = bpy.data.materials.new("tmp")
         
-        # Create new object
-        new_atom = draw_obj('1b',obj)
+        # Create new object (NURBS sphere = '1b')
+        new_atom = draw_obj('1b', atom)
         new_atom.active_material = new_material
-        new_atom.parent = obj.parent
+        new_atom.parent = atom.parent
 
         # Change size and color of the new object            
         for element in ELEMENTS:

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list