diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-11-23 01:07:41 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-11-23 01:07:41 +0300 |
commit | b21df550d3a7aaa5925effe4fb7dc38f99592c22 (patch) | |
tree | 2feeccc6c8cd9a257553f6eb8b6f1ded6e7558fe /source/blender/python/api2_2x | |
parent | a8aaec6f210626d2beb2d23f297c1a412b047e8e (diff) |
==Python API==
made it possible to remove curves from python with "del curve[i]"
mesh_edges2curves.py - remove unused function.
Diffstat (limited to 'source/blender/python/api2_2x')
-rw-r--r-- | source/blender/python/api2_2x/Curve.c | 39 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Curve.py | 2 |
2 files changed, 39 insertions, 2 deletions
diff --git a/source/blender/python/api2_2x/Curve.c b/source/blender/python/api2_2x/Curve.c index e849522ef00..e88ab0eeeff 100644 --- a/source/blender/python/api2_2x/Curve.c +++ b/source/blender/python/api2_2x/Curve.c @@ -124,6 +124,7 @@ static PyObject *Curve_getIter( BPy_Curve * self ); 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 @@ PyObject *Curve_getNurb( BPy_Curve * self, int n ) } +/* + * 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 @@ static PySequenceMethods Curve_as_sequence = { ( 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, diff --git a/source/blender/python/api2_2x/doc/Curve.py b/source/blender/python/api2_2x/doc/Curve.py index 5ccf5834ebd..c3760bc2c1d 100644 --- a/source/blender/python/api2_2x/doc/Curve.py +++ b/source/blender/python/api2_2x/doc/Curve.py @@ -10,7 +10,7 @@ This module provides access to B{Curve Data} objects in Blender. 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) |