[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12657] trunk/blender: ==Python API==

Campbell Barton ideasman42 at gmail.com
Thu Nov 22 23:07:41 CET 2007


Revision: 12657
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12657
Author:   campbellbarton
Date:     2007-11-22 23:07:41 +0100 (Thu, 22 Nov 2007)

Log Message:
-----------
==Python API==
made it possible to remove curves from python with "del curve[i]"
mesh_edges2curves.py - remove unused function.

Modified Paths:
--------------
    trunk/blender/release/scripts/mesh_edges2curves.py
    trunk/blender/source/blender/python/api2_2x/Curve.c
    trunk/blender/source/blender/python/api2_2x/doc/Curve.py

Modified: trunk/blender/release/scripts/mesh_edges2curves.py
===================================================================
--- trunk/blender/release/scripts/mesh_edges2curves.py	2007-11-22 22:04:46 UTC (rev 12656)
+++ trunk/blender/release/scripts/mesh_edges2curves.py	2007-11-22 22:07:41 UTC (rev 12657)
@@ -39,17 +39,8 @@
 # ***** END GPL LICENCE BLOCK *****
 # --------------------------------------------------------------------------
 
-
 from Blender import *
 
-def edkey(ed):
-	i1 = ed.v1.index
-	i2 = ed.v2.index
-	if i1>i2:
-		return (i2,i1), ed
-	else:
-		return (i1,i2), ed
-
 def polysFromMesh(me):
 	# a polyline is 2 
 	#polylines are a list

Modified: trunk/blender/source/blender/python/api2_2x/Curve.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Curve.c	2007-11-22 22:04:46 UTC (rev 12656)
+++ trunk/blender/source/blender/python/api2_2x/Curve.c	2007-11-22 22:07:41 UTC (rev 12657)
@@ -124,6 +124,7 @@
 static PyObject *Curve_iterNext( BPy_Curve * self );
 
 PyObject *Curve_getNurb( BPy_Curve * self, int n );
+static int Curve_setNurb( BPy_Curve * self, int n, PyObject * value );
 static int Curve_length( PyInstanceObject * inst );
 
 
@@ -1111,6 +1112,42 @@
 
 }
 
+/*
+ * Curve_setNurb
+ * In this case only remove the item, we could allow adding later.
+ */
+static int Curve_setNurb( BPy_Curve * self, int n, PyObject * value )
+{
+	Nurb *pNurb;
+	int i;
+
+	/* bail if index < 0 */
+	if( n < 0 )
+		return ( EXPP_ReturnIntError( PyExc_IndexError,
+				 "index less than 0" ) );
+	/* bail if no Nurbs in Curve */
+	if( self->curve->nurb.first == 0 )
+		return ( EXPP_ReturnIntError( PyExc_IndexError,
+				 "no Nurbs in this Curve" ) );
+	/* set pointer to nth Nurb */
+	for( pNurb = self->curve->nurb.first, i = 0;
+			pNurb != 0 && i < n; pNurb = pNurb->next, ++i )
+		/**/;
+
+	if( !pNurb )		/* we came to the end of the list */
+		return ( EXPP_ReturnIntError( PyExc_IndexError,
+				 "index out of range" ) );
+	
+	if (value) {
+		return ( EXPP_ReturnIntError( PyExc_RuntimeError,
+				 "assigning curves is not yet supported" ) );
+	} else {
+		BLI_remlink(&self->curve->nurb, pNurb);
+		freeNurb(pNurb);
+	}
+	return 0;
+}
+
 /*****************************************************************************/
 /* Function:    Curve_compare		                                         */
 /* Description: This compares 2 curve python types, == or != only.			 */
@@ -1430,7 +1467,7 @@
 	( intargfunc ) 0,	/* sq_repeat */
 	( intargfunc ) Curve_getNurb,	/* sq_item */
 	( intintargfunc ) 0,	/* sq_slice */
-	0,			/* sq_ass_item */
+	( intobjargproc ) Curve_setNurb,	/* sq_ass_item - only so you can do del curve[i] */
 	0,			/* sq_ass_slice */
 	( objobjproc ) 0,	/* sq_contains */
 	0,

Modified: trunk/blender/source/blender/python/api2_2x/doc/Curve.py
===================================================================
--- trunk/blender/source/blender/python/api2_2x/doc/Curve.py	2007-11-22 22:04:46 UTC (rev 12656)
+++ trunk/blender/source/blender/python/api2_2x/doc/Curve.py	2007-11-22 22:07:41 UTC (rev 12657)
@@ -10,7 +10,7 @@
 
 A Blender Curve Data consists of multiple L{CurNurb}(s). Try converting a Text object to a Curve to see an example of this.   Each curve is of
 type Bezier or Nurb.  The underlying L{CurNurb}(s) can be accessed with
-the [] operator.  Operator [] returns an object of type L{CurNurb}.
+the [] operator.  Operator [] returns an object of type L{CurNurb}. Removing a L{CurNurb} can be done this way too. del curve[0] removes the first curve.
 
 Note that L{CurNurb} can be used to acces a curve of any type (Poly, Bezier or Nurb)
 





More information about the Bf-blender-cvs mailing list