New and very useful feature: when separating atoms from a dupliverts structure
authorClemens Barth <barth@root-1.de>
Thu, 17 Jan 2013 20:33:48 +0000 (20:33 +0000)
committerClemens Barth <barth@root-1.de>
Thu, 17 Jan 2013 20:33:48 +0000 (20:33 +0000)
same type of objects (NURBS, mesh and meta) were used. Now, one can explicitly
use other type of objects: cube, plane, circle, torus, cylinder, etc.

This new option is quite useful for creating 'defects' in atomic structures,
which shall appear in a different shape.

Blendphys.

io_atomblend_utilities/__init__.py
io_atomblend_utilities/io_atomblend_utilities.py

index 257c3e5b4e0b1d7fbfebac7eee85c3f27c6f22f1..d95214acb8f2f71457edae9ac6984172df0986e0 100644 (file)
@@ -103,8 +103,8 @@ class PreparePanel(Panel):
         col.label(text="3. Radii by scale")
         col.prop(scn, "radius_all")
         row = col.row()
-        row.operator( "atom_blend.radius_all_smaller" )
-        row.operator( "atom_blend.radius_all_bigger" )
+        row.operator("atom_blend.radius_all_smaller")
+        row.operator("atom_blend.radius_all_bigger")
         
         box = layout.box()
         col = box.column(align=True)
@@ -119,7 +119,9 @@ class PreparePanel(Panel):
         col.label(text="Separate atoms")
         col2 = col.column()
         col2.active = (bpy.context.mode == 'EDIT_MESH')
-        col2.operator( "atom_blend.separate_atom" )
+        col2.prop(scn, "separate_objs")
+        col2.operator("atom_blend.separate_atom")
+        
 
 
 # The properties of buttons etc. in the panel.
@@ -201,7 +203,18 @@ class PanelProperties(bpy.types.PropertyGroup):
     sticks_all = FloatProperty(
         name="Scale", default = 1.05, min=1.0, max=5.0,
         description="Put in the scale factor")
-
+    separate_objs = EnumProperty(
+        name="Object",
+        description="Replace ball by another object.",
+        items=(('0',"Unchanged", "Use again a ball"),
+               ('1',"Cube", "Replace with a cube"),
+               ('2',"Plane", "Replace with a plane"),
+               ('3',"Circle", "Replace with a circle"),
+               ('4',"Icosphere", "Replace with a icosphere"),              
+               ('5',"Cylinder", "Replace with a cylinder"),
+               ('6',"Cone", "Replace with a cone"),
+               ('7',"Torus", "Replace with a torus")),
+               default='0',)     
 
 # Button loading a custom data file
 class DatafileApply(Operator):
index 7aa3867b9d29dfef87c07bb17189829bf3b61d52..5583865a219dbd01ce2ce7b96aef25f729b37658 100644 (file)
@@ -437,6 +437,7 @@ def custom_datafile(path_datafile):
     return True
 
 
+
 # Separating atoms from a dupliverts strucutre.
 def separate_atoms(scn):
 
@@ -479,44 +480,146 @@ def separate_atoms(scn):
     # For all selected positions do:
     for location in locations:
         # For any ball do ...
-        if "Vacancy" not in name:
-            # NURBS ball
-            if obj.children[0].type == "SURFACE":
-                bpy.ops.surface.primitive_nurbs_surface_sphere_add(
+        
+        # Draw same object
+        if scn.separate_objs in {'0'}:
+            separate_draw_regular(
+                                name, 
+                                obj.children[0], 
+                                location,
+                                scale, 
+                                material)
+        if scn.separate_objs in {'1','2','3','4','5','6','7'}:       
+            separate_draw_other_standard(
+                                scn.separate_objs, 
+                                name, 
+                                location, 
+                                scale, 
+                                material)                   
+
+    bpy.context.scene.objects.active = obj
+    #bpy.ops.object.select_all(action='DESELECT')
+    
+
+def separate_draw_other_standard(obj_type, name, location, scale, material):
+
+    current_layers=bpy.context.scene.layers
+
+    if obj_type =='1': #Cube
+        bpy.ops.mesh.primitive_cube_add(
+            view_align=False, 
+            enter_editmode=False,
+            location=location,
+            rotation=(0.0, 0.0, 0.0),
+            layers=current_layers)
+    if obj_type =='2': #Plane       
+        bpy.ops.mesh.primitive_plane_add(
+            view_align=False, 
+            enter_editmode=False, 
+            location=location, 
+            rotation=(0.0, 0.0, 0.0), 
+            layers=current_layers)
+    if obj_type =='3': #Circle
+        bpy.ops.mesh.primitive_circle_add(
+            vertices=32, 
+            radius=1, 
+            fill_type='NOTHING', 
+            view_align=False, 
+            enter_editmode=False, 
+            location=location, 
+            rotation=(0, 0, 0), 
+            layers=current_layers)      
+    if obj_type =='4': #Icosphere         
+        bpy.ops.mesh.primitive_ico_sphere_add(
+            subdivisions=2, 
+            size=1, 
+            view_align=False, 
+            enter_editmode=False, 
+            location=location, 
+            rotation=(0, 0, 0), 
+            layers=current_layers)                
+    if obj_type =='5': #Cylinder
+        bpy.ops.mesh.primitive_cylinder_add(
+            vertices=32, 
+            radius=1, 
+            depth=2, 
+            end_fill_type='NGON', 
+            view_align=False, 
+            enter_editmode=False, 
+            location=location, 
+            rotation=(0, 0, 0), 
+            layers=current_layers)
+    if obj_type =='6': #Cone
+        bpy.ops.mesh.primitive_cone_add(
+            vertices=32, 
+            radius1=1, 
+            radius2=0, 
+            depth=2, 
+            end_fill_type='NGON', 
+            view_align=False, 
+            enter_editmode=False, 
+            location=location, 
+            rotation=(0, 0, 0), 
+            layers=current_layers)
+    if obj_type =='7': #Torus
+        bpy.ops.mesh.primitive_torus_add(
+            rotation=(0, 0, 0), 
+            location=location, 
+            view_align=False, 
+            major_radius=1, 
+            minor_radius=0.25, 
+            major_segments=48, 
+            minor_segments=12, 
+            use_abso=False, 
+            abso_major_rad=1, 
+            abso_minor_rad=0.5)     
+
+    new_atom = bpy.context.scene.objects.active
+    # Scale, material and name it.
+    new_atom.scale = scale
+    new_atom.active_material = material
+    new_atom.name = name + "_sep"
+    new_atom.select = True        
+
+
+
+def separate_draw_regular(name, child, location, scale, material):
+
+    current_layers=bpy.context.scene.layers
+    if "Vacancy" not in name:
+        # NURBS ball
+        if child.type == "SURFACE":
+            bpy.ops.surface.primitive_nurbs_surface_sphere_add(
                                     view_align=False, enter_editmode=False,
                                     location=location,
                                     rotation=(0.0, 0.0, 0.0),
                                     layers=current_layers)
-                # Mesh ball                    
-            elif obj.children[0].type == "MESH":
-                bpy.ops.mesh.primitive_uv_sphere_add(
+        # Mesh ball                    
+        elif child.type == "MESH":
+            bpy.ops.mesh.primitive_uv_sphere_add(
                                 segments=32,
                                 ring_count=32,                    
-                                #segments=scn.mesh_azimuth,
-                                #ring_count=scn.mesh_zenith,
                                 size=1, view_align=False, enter_editmode=False,
                                 location=location,
                                 rotation=(0, 0, 0),
                                 layers=current_layers)
-                # Metaball
-            elif obj.children[0].type == "META":
-                bpy.ops.object.metaball_add(type='BALL', view_align=False, 
+        # Metaball
+        elif child.type == "META":
+            bpy.ops.object.metaball_add(type='BALL', view_align=False, 
                             enter_editmode=False, location=location, 
                             rotation=(0, 0, 0), layers=current_layers)
-        # If it is a vacancy create a cube ...                    
-        else:
-            bpy.ops.mesh.primitive_cube_add(
+    # If it is a vacancy create a cube ...                    
+    else:
+        bpy.ops.mesh.primitive_cube_add(
                            view_align=False, enter_editmode=False,
                            location=location,
                            rotation=(0.0, 0.0, 0.0),
                            layers=current_layers)
-                               
-        new_atom = bpy.context.scene.objects.active
-        # Scale, material and name it.
-        new_atom.scale = scale
-        new_atom.active_material = material
-        new_atom.name = name + "_sep"
-        new_atom.select = True
-
-    bpy.context.scene.objects.active = obj
-    #bpy.ops.object.select_all(action='DESELECT')
+                           
+    new_atom = bpy.context.scene.objects.active
+    # Scale, material and name it.
+    new_atom.scale = scale
+    new_atom.active_material = material
+    new_atom.name = name + "_sep"
+    new_atom.select = True
+