===Python API===
authorKen Hughes <khughes@pacific.edu>
Tue, 6 Jun 2006 18:14:31 +0000 (18:14 +0000)
committerKen Hughes <khughes@pacific.edu>
Tue, 6 Jun 2006 18:14:31 +0000 (18:14 +0000)
added len() operator for MFaces, which returns number of MVerts.

source/blender/python/api2_2x/Mesh.c
source/blender/python/api2_2x/doc/Mesh.py

index 1a93f2c8c6e93c4f63ada5d7516cc758fd2a0150..c1f19d8541d665c9ca526990ea0f8ada663db1cd 100644 (file)
@@ -4409,6 +4409,24 @@ static long MFace_hash( BPy_MFace *self )
        return (long)self->index;
 }
 
+static int MFace_len( BPy_MFace * self )
+{
+       if( self->index >= self->mesh->totface )
+               return 0;
+       return self->mesh->mface[self->index].v4 ? 4 : 3;
+}
+
+static PySequenceMethods MFace_as_sequence = {
+       ( inquiry ) MFace_len,         /* sq_length */
+       ( binaryfunc ) 0,                  /* sq_concat */
+       ( intargfunc ) 0,                  /* sq_repeat */
+       ( intargfunc ) 0,              /* sq_item */
+       ( intintargfunc ) 0,           /* sq_slice */
+       ( intobjargproc ) 0,           /* sq_ass_item */
+       ( intintobjargproc ) 0,        /* sq_ass_slice */
+       0,0,0,
+};
+
 /************************************************************************
  *
  * Python MFace_Type structure definition
@@ -4435,7 +4453,7 @@ PyTypeObject MFace_Type = {
        /* Method suites for standard classes */
 
        NULL,                       /* PyNumberMethods *tp_as_number; */
-       NULL,                                   /* PySequenceMethods *tp_as_sequence; */
+       &MFace_as_sequence,         /* PySequenceMethods *tp_as_sequence; */
        NULL,                       /* PyMappingMethods *tp_as_mapping; */
 
        /* More standard operations (here for binary compatibility) */
index 8bfadd1ba3b4582c9d90b1e0d759fae3285dfbc9..5ae0d2a1e73ef8dc8ae3567db834734392faab7c 100644 (file)
@@ -567,6 +567,12 @@ class MFace:
     @rtype: MVert
     """
 
+  def __len__():
+    """
+    len for MVert.  It returns the number of vertices in the face.
+    @rtype: int
+    """
+
 class MFaceSeq:
   """
   The MFaceSeq object