[Bf-blender-cvs] [30d3fae] particles_refactor: Added a __dir__ method for particles to return the list of available attributes.

Lukas Tönne noreply at git.blender.org
Tue Apr 22 12:06:23 CEST 2014


Commit: 30d3fae8b7084544bdccf98c15ec3dbacd65157e
Author: Lukas Tönne
Date:   Sat Dec 21 10:12:00 2013 +0100
https://developer.blender.org/rB30d3fae8b7084544bdccf98c15ec3dbacd65157e

Added a __dir__ method for particles to return the list of available
attributes.

===================================================================

M	source/blender/python/bparticles/bparticles_py_types.c

===================================================================

diff --git a/source/blender/python/bparticles/bparticles_py_types.c b/source/blender/python/bparticles/bparticles_py_types.c
index 34f1cc1..8920e70 100644
--- a/source/blender/python/bparticles/bparticles_py_types.c
+++ b/source/blender/python/bparticles/bparticles_py_types.c
@@ -98,6 +98,27 @@ static PyObject *bpy_bpar_attrstate_name_get(BPy_NParticleAttributeState *self)
 	return PyUnicode_FromString(self->attrstate->desc.name);
 }
 
+static PyObject *bpy_bpar_particle_dir(BPy_NParticleParticle *self)
+{
+	NParticleAttributeStateIterator iter;
+	PyObject *ret;
+	PyObject *pystring;
+
+//	PYRNA_STRUCT_CHECK_OBJ(self);
+
+	ret = PyList_New(0);
+
+	for (BKE_nparticle_state_attributes_begin(self->state, &iter);
+	     BKE_nparticle_state_attribute_iter_valid(&iter);
+	     BKE_nparticle_state_attribute_iter_next(&iter)) {
+		pystring = PyUnicode_FromString(iter.attrstate->desc.name);
+		PyList_Append(ret, pystring);
+		Py_DECREF(pystring);
+	}
+
+	return ret;
+}
+
 static PyObject *bpy_bpar_state_repr(BPy_NParticleState *self)
 {
 	NParticleState *state = self->state;
@@ -156,6 +177,11 @@ static struct PyMethodDef bpy_bpar_attrstate_methods[] = {
 	{NULL, NULL, 0, NULL}
 };
 
+static struct PyMethodDef bpy_bpar_particle_methods[] = {
+	{"__dir__", (PyCFunction)bpy_bpar_particle_dir, METH_NOARGS, NULL},
+	{NULL, NULL, 0, NULL}
+};
+
 static Py_hash_t bpy_bpar_state_hash(PyObject *self)
 {
 	return _Py_HashPointer(((BPy_NParticleState *)self)->state);
@@ -687,7 +713,7 @@ void BPy_BPAR_init_types(void)
 	BPy_NParticleAttributeState_Type.tp_methods         = bpy_bpar_attrstate_methods;
 	BPy_NParticleAttributeStateSeq_Type.tp_methods      = NULL;
 	BPy_NParticleAttributeStateIter_Type.tp_methods     = NULL;
-	BPy_NParticleParticle_Type.tp_methods               = NULL;
+	BPy_NParticleParticle_Type.tp_methods               = bpy_bpar_particle_methods;
 	BPy_NParticleParticleSeq_Type.tp_methods            = NULL;
 	BPy_NParticleParticleIter_Type.tp_methods           = NULL;




More information about the Bf-blender-cvs mailing list