Mech cleanup use new edge_keys
authorCampbell Barton <ideasman42@gmail.com>
Thu, 28 Dec 2006 05:00:35 +0000 (05:00 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 28 Dec 2006 05:00:35 +0000 (05:00 +0000)
continual script stuff, minor stuff..

fix for bad return in group.
Added back group.objects.append/remove but print deprectaed warning. also some epydoc changes.

13 files changed:
release/scripts/3ds_import.py
release/scripts/armature_symetry.py
release/scripts/bevel_center.py
release/scripts/bpymodules/BPyMesh.py
release/scripts/export-iv-0.1.py
release/scripts/faceselect_same_weights.py
release/scripts/flt_export.py
release/scripts/flt_import.py
release/scripts/image_auto_layout.py
release/scripts/mesh_boneweight_copy.py
release/scripts/mesh_cleanup.py
source/blender/python/api2_2x/Group.c
source/blender/python/api2_2x/doc/Group.py

index 65e189511761e59ae8a6ab76b09320ad4147998b..4c37b75b02a07ce733d0946a407e83db633cadac 100644 (file)
@@ -808,7 +808,7 @@ def load_3ds(filename, PREF_UI= True):
        
        '''
        for ob in importedObjects:
-               if ob.getType()=='Mesh':
+               if ob.type=='Mesh':
                        me= ob.getData(mesh=1)
                        me.verts.delete([me.verts[0],])
        '''
index 2d740077d2296298d4f713dddf835e38437e1d95..4caf028631a623bb9b4a69265bcffd94400bea86 100644 (file)
@@ -246,9 +246,9 @@ def main():
        '''
        
        scn= Scene.GetCurrent()
-       arm_ob= scn.getActiveObject()
+       arm_ob= scn.objects.active
        
-       if not arm_ob or arm_ob.getType()!='Armature':
+       if not arm_ob or arm_ob.type!='Armature':
                Blender.Draw.PupMenu('No Armature object selected.')
                return
        
index 9e01d37455e12955fa97673752e595b5b99dba99..e390709039ec1948a2e58b5af6b071896b604e4a 100644 (file)
@@ -70,8 +70,8 @@ old_dist = None
 
 def act_mesh_ob():
        scn = Scene.GetCurrent()
-       ob = scn.getActiveObject()
-       if ob == None or ob.getType() != 'Mesh': 
+       ob = scn.objects.active
+       if ob == None or ob.type != 'Mesh': 
                PupMenu('ERROR%t|Select a mesh object.')
                return
        return ob
index 28ba3a2701e02dd7f10b980936209e0e2cd42cfb..fe34120bbafc0351a12ed4e60e6e49e8e0b40931 100644 (file)
@@ -394,7 +394,7 @@ def getMeshFromObject(ob, container_mesh=None, apply_modifiers=True, vgroups=Tru
                mesh.verts= None
        
        
-       type = ob.getType()
+       type = ob.type
        dataname = ob.getData(1)
        tempob= None
        if apply_modifiers or type != 'Mesh':
index 86842a96dd38e0574b9ac08d550619009d4604b9..17b3d4cb72809ad865b25f300985728e6fe2275f 100644 (file)
@@ -279,7 +279,7 @@ def ExportToIv(file_name):
                #elif obtype == "Camera":
                #       cameras.append(object);
                #else:
-               #       print "Exporting %s objects isn't supported!" % object.getType()
+               #       print "Exporting %s objects isn't supported!" % object.type
 
        # write header, footer and groups of object types
        WriteHeader(file);
index 10ba1b6c7ac7d6611d7984f331abf1096b684c73..0aa9d2ffb6d810f764df4950dd350fac456ea53f 100644 (file)
@@ -89,9 +89,9 @@ def selSameWeights(me, PREF_TOLERENCE):
 
 def main():
        scn= Scene.GetCurrent()
-       ob= scn.getActiveObject()
+       ob= scn.objects.active
        
-       if not ob or ob.getType() != 'Mesh':
+       if not ob or ob.type != 'Mesh':
                Draw.PupMenu('Error, no active mesh object, aborting.')
                return
        
@@ -99,7 +99,6 @@ def main():
        
        PREF_TOLERENCE= Draw.Create(0.1)
        
-       
        pup_block= [\
        ('Tolerence:', PREF_TOLERENCE, 0.01, 1.0, 'Tolerence for selecting faces of the same weight.'),\
        ]
index f85fa91ca9562183be7652d51ae59769d94981cf..f377d6fbc5e1cff626e5569a418e9cb1bc27977e 100755 (executable)
@@ -253,7 +253,7 @@ class Node:
        def blender_export(self, level=[0]):
                if self.object:
                        if options.verbose >= 2:
-                               print '\t' * level[0], self.name, self.object.getType()
+                               print '\t' * level[0], self.name, self.object.type
 
                level[0] += 1
                
@@ -294,7 +294,7 @@ class Node:
                self.header = header
                self.object = object
                if object:
-                       self.name = self.object.getName()
+                       self.name = self.object.name
                        self.matrix = self.object.getMatrix('localspace')
                else:
                        self.name = 'no name'
@@ -320,7 +320,7 @@ class Node:
                # Spawn children.
                self.has_object_child = False # For Database class.
                for child in self.child_objects:                        
-                       if child.getType() == 'Mesh':
+                       if child.type == 'Mesh':
                                BlenderMesh(self, header, child, left_over)
                                self.has_object_child = True
                        else: # Treat all non meshes as emptys
@@ -371,7 +371,7 @@ class BlenderMesh(Node):
 
                        # Gather Material
                        mat_desc = MaterialDesc()
-                       mat_desc.name = mat.getName()
+                       mat_desc.name = mat.name
                        mat_desc.alpha = mat.getAlpha()
                        mat_desc.shininess = mat.getSpec() * 64.0   # 2.0 => 128.0
                        if options.use_mat_color:
index be9f4742ac0ce26fb1944bd2ece9d4662cba24a9..18b1d0a4b8a6c085d0edfb0ce6abef5ea4ccce0b 100755 (executable)
@@ -1835,8 +1835,8 @@ def select_file(filename):
        
        # FIX UP AFTER DUMMY VERT AND REMOVE DOUBLES
        Blender.Mesh.Mode(Blender.Mesh.SelectModes['VERTEX'])
-       for ob in Blender.Object.GetSelected():
-               if ob.getType()=='Mesh':
+       for ob in scene.objects.context:
+               if ob.type=='Mesh':
                        me=ob.getData(mesh=1)
                        me.verts.delete(0) # remove the dummy vert
                        me.sel= 1
index 89fd91ef0e739d6733bb51f9689a611ffa99bc74..178524a18447c767aa0bae13a39ede3627b2114c 100644 (file)
@@ -384,9 +384,9 @@ def auto_layout_tex(mesh_list, scn, PREF_IMAGE_PATH, PREF_IMAGE_SIZE, PREF_KEEP_
 
 def main():
        scn= B.Scene.GetCurrent()
-       ob= scn.getActiveObject()
+       ob= scn.objects.active
        
-       if not ob or ob.getType() != 'Mesh':
+       if not ob or ob.type != 'Mesh':
                B.Draw.PupMenu('Error, no active mesh object, aborting.')
                return
        
index 32caa52f831b49fd7e497280259a97315d1bb544..11e9efcf0b74ef8f0234df97363531505108a270 100755 (executable)
@@ -216,17 +216,16 @@ def main():
        PREF_NO_XCROSS= PREF_NO_XCROSS.val
        quality=  PREF_QUALITY.val
        
-       act_ob= scn.getActiveObject()
+       act_ob= scn.objects.active
        if PREF_SEL_ONLY and act_ob==None:
                Blender.Draw.PupMenu('Error%t|When dealing with 2 or more meshes with vgroups|There must be an active object|to be used as a source|aborting.')
                return
 
        sel=[]
        from_data= None
-       act_ob= scn.getActiveObject()
+       
        for ob in contextSel:
-               
-               if ob.getType()=='Mesh':
+               if ob.type=='Mesh':
                        me= ob.getData(mesh=1)
                        groups= me.getVertGroupNames()
                        
@@ -242,7 +241,7 @@ def main():
                                                        _ob.sel=0
                                                ob.sel=1
                                                Object.Duplicate(mesh=1)
-                                               ob= scn.getActiveObject()
+                                               ob= scn.objects.active
                                                me= ob.getData(mesh=1)
                                                # groups will be the same
                                                print '\tGenerating higher %ix quality weights.' % quality
@@ -262,7 +261,6 @@ def main():
        t= Blender.sys.time()
        Window.WaitCursor(1)
        
-       
        # Now do the copy.
        print '\tCopying from "%s" to %i other mesh(es).' % (from_data[0].name, len(sel))
        for data in sel:
index 7abd64c255ea83ed799426b752b9aa0a351c70da..f0f1409bd881052ad20b3b3c3195828e02c82bd5 100644 (file)
@@ -64,26 +64,20 @@ def rem_free_verts(me):
        
 def rem_free_edges(me, limit=None):
        ''' Only remove based on limit if a limit is set, else remove all '''
-       def sortPair(a,b):
-               if a>b:
-                       return b,a
-               else:
-                       return a,b
        
        edgeDict= {} # will use a set when python 2.4 is standard.
        
        for f in me.faces:
-               fidxs= [v.index for v in f.v]
-               for i in xrange(len(fidxs)):
-                       edgeDict[sortPair(fidxs[i], fidxs[i-1])]= None
+               for edkey in f.edge_keys:
+                       edgeDict[edkey] = None
        
        edges_free= []
        for e in me.edges:
-               if not edgeDict.has_key(sortPair(e.v1.index, e.v2.index)):
+               if not edgeDict.has_key(e.key):
                        edges_free.append(e)
        
        if limit != None:
-               edges_free= [e for e in edges_free if (e.v1.co-e.v2.co).length <= limit]
+               edges_free= [e for e in edges_free if e.length <= limit]
        
        me.edges.delete(edges_free)
        return len(edges_free)
@@ -196,8 +190,8 @@ def normalize_vweight(me, groupNames, vWeightDict):
 
 def main():    
        scn= Scene.GetCurrent()
-       obsel= Object.GetSelected()
-       actob= scn.getActiveObject()
+       obsel= list(scn.objects.context)
+       actob= scn.objects.active
        
        is_editmode= Window.EditMode()
        
@@ -262,11 +256,11 @@ def main():
        if CLEAN_ALL_DATA:
                if CLEAN_GROUP or CLEAN_VWEIGHT or CLEAN_WEIGHT_NORMALIZE:
                        # For groups we need the objects linked to the mesh
-                       meshes= [ob.getData(mesh=1) for ob in Object.Get() if ob.getType() == 'Mesh']
+                       meshes= [ob.getData(mesh=1) for ob in Object.Get() if ob.type == 'Mesh']
                else:
                        meshes= Mesh.Get()
        else:
-               meshes= [ob.getData(mesh=1) for ob in obsel if ob.getType() == 'Mesh']
+               meshes= [ob.getData(mesh=1) for ob in obsel if ob.type == 'Mesh']
        
        rem_face_count= rem_edge_count= rem_vert_count= rem_material_count= rem_group_count= rem_vweight_count= 0
        
index 25c6dba8c6ea59ae579ef2de9291560f1eceb532..33465574f7953de60cefddfc19bb7d3328ce6248 100755 (executable)
@@ -262,7 +262,7 @@ static PyObject *Group_getFakeUser( BPy_Group * self )
 
 static int Group_setFakeUser( BPy_Group * self, PyObject * value )
 {
-       GROUP_DEL_CHECK_PY(self);
+       GROUP_DEL_CHECK_INT(self);
        return SetIdFakeUser(&self->group->id, value);
 }
 
@@ -803,6 +803,11 @@ static PyObject *GroupObSeq_link( BPy_GroupObSeq * self, PyObject *args )
        Py_RETURN_NONE;
 }
 
+static PyObject *GroupObSeq_append( BPy_GroupObSeq * self, PyObject *args )
+{
+       printf("WARNING: grp.objects.append() has been deprecated, use grp.objects.link() instead.\nBlender releases after 2.43 will not support .append()");
+       return GroupObSeq_link(self, args);
+}
 
 
 static PyObject *GroupObSeq_unlink( BPy_GroupObSeq * self, PyObject *args )
@@ -833,13 +838,26 @@ static PyObject *GroupObSeq_unlink( BPy_GroupObSeq * self, PyObject *args )
        Py_RETURN_NONE;
 }
 
+static PyObject *GroupObSeq_remove( BPy_GroupObSeq * self, PyObject *args )
+{
+       printf("WARNING: grp.objects.remove() has been deprecated, use grp.objects.unlink() instead.\nBlender releases after 2.43 will not support .remove()");
+       return GroupObSeq_unlink(self, args);
+}
+
 
 static struct PyMethodDef BPy_GroupObSeq_methods[] = {
        {"link", (PyCFunction)GroupObSeq_link, METH_VARARGS,
                "make the object a part of this group"},
-       {"remove", (PyCFunction)GroupObSeq_unlink, METH_VARARGS,
-               "remove object from this group"},
-       {NULL, NULL, 0, NULL}
+       {"unlink", (PyCFunction)GroupObSeq_unlink, METH_VARARGS,
+               "unlink an object from this group"},
+               
+       /* Deprecated! use the above functions */
+       {"append", (PyCFunction)GroupObSeq_append, METH_VARARGS,
+               "make the object a part of this group - deprecated, use link"},
+       {"remove", (PyCFunction)GroupObSeq_remove, METH_VARARGS,
+               "remove an object from this group - deprecated, use unlink"},
+               
+       {NULL, NULL, 0, NULL}   
 };
 
 /************************************************************************
index d7862f12e3708535e576ca2a010e5570e5feba2b..6500df54f2c954df4647eea28d44597ddc91b71e 100644 (file)
@@ -52,6 +52,21 @@ Example::
   ob.enableDupGroup= True
   ob.DupGroup= grp
   Window.RedrawAll()
+  
+  
+Example::
+
+  # Remove all non mesh objects from a group.
+
+  from Blender import *
+  
+  scn= Scene.GetCurrent()
+  
+  # New Group
+  grp= Group.Get('mygroup')
+  for ob in list(grp.objects): # Convert to a list before looping because we are removing items
+    if ob.type != 'Mesh':
+      grp.objects.unlink(ob)
 """
 
 def New (name = None):
@@ -77,6 +92,7 @@ def Get (name = None):
 def Unlink (group):
   """
   Unlink (delete) this group from Blender.
+  @Note: No objects will be removed, just the group that references them.
   @type group: group
   @param group: A group to remove from this blend file, does not remove objects that this group uses.
   """
@@ -97,9 +113,12 @@ class Group:
   @ivar layers: Layer bitmask for this group.
   @type layers: int
   @ivar objects: Objects that this group uses.
-  This is a sequence with-list like access so use list(grp.objects) if you need to use a list (where grp is a group).
-  The groups objects can be set by assigning a list or iterator of objects to the groups objects.
-  objects.link() and objects.unlink() also work with the the objects iterator just like with lists.
+    This is a sequence with-list like access so use list(grp.objects) if you need to use a list (where grp is a group).
+    The groups objects can be set by assigning a list or iterator of objects to the groups objects.
+    objects.link() and objects.unlink() also work with the the objects iterator just like with lists.
+
+    B{Note}: append() and remove() have been deprecated and replaced by link() and unlink(),
+    after Blender 2.43 append() and remove() will not be available.
   @type objects: custom object sequence
   """