From b21df550d3a7aaa5925effe4fb7dc38f99592c22 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 22 Nov 2007 22:07:41 +0000 Subject: [PATCH] ==Python API== made it possible to remove curves from python with "del curve[i]" mesh_edges2curves.py - remove unused function. --- release/scripts/mesh_edges2curves.py | 9 ----- source/blender/python/api2_2x/Curve.c | 39 +++++++++++++++++++++- source/blender/python/api2_2x/doc/Curve.py | 2 +- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/release/scripts/mesh_edges2curves.py b/release/scripts/mesh_edges2curves.py index fdf61298ebc..84f3cc41779 100644 --- a/release/scripts/mesh_edges2curves.py +++ b/release/scripts/mesh_edges2curves.py @@ -39,17 +39,8 @@ Supported:
# ***** 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 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)