[Bf-python] setSel patch

Joseph Gilbert models at paposo.com
Sun May 30 18:00:17 CEST 2004


Hi,
	Just a few comments:
Could this be called isSelected() and Select(TRUE/FALSE)? instead of
getSel/setSel?
Also you - careful not to define variable before you done declaring them in
C. ie.
+  Base *base;
+  base= FIRSTBASE;
+
+  PyObject *sel;

i believe it's better to do this:
+  Base *base;
+  PyObject *sel;
+
+  base= FIRSTBASE;

There is a warning maybe here that this only applies to the current scene
because FIRSTBASE and countall() use the G.scene variable.

I made a few mods to the functions but you can see if you like them.
static PyObject *Object_isSelected (BPy_Object *self)
{
	Base *base;

	base= FIRSTBASE;
	while (base) {
		if (base->object == self->object)	{
			if (base->flag & SELECT) {
				Py_INCREF (Py_True);
				return Py_True;
			} else {
				Py_INCREF (Py_False);
				return Py_False;
			}
		}
		base= base->next;
	}

	Py_INCREF (Py_None);
    return (Py_None);
}

static PyObject *Object_Select (BPy_Object *self, PyObject *args)
{
  Base *base;
  int sel;

  base= FIRSTBASE;
  if (!PyArg_ParseTuple (args, "i", &sel))
		return EXPP_ReturnPyObjError
		   (PyExc_TypeError, "expected an int, 0 or 1");

    while (base) {
		if (base->object == self->object){
			if (sel){
				base->flag |= SELECT;
				self->object->flag= base->flag;
			} else {
				base->flag &= ~SELECT;
				self->object->flag= base->flag;
			}
			break;
		}
		base= base->next;
    }
	countall();

    Py_INCREF (Py_None);
    return (Py_None);
}

Just a suggestion :) Anyway's I was looking at the apply_object() function.
This definately looks scary. My suggestion is to not change the /src code
and just take what you need for python. BASEACT/TESTBASELIB will only work
on the active selected base/object - careful with these.

Another way to do this is instead of calling a monster function (and it look
like there could be a few :) in the object module you could test the object
and call non-static visible functions from the other Datatype modules:
static PyObject *Object_appyRotation(PyObject *self)
{
	if(object->type = mesh)
 		success = NMesh_applyRot(self->object)
	if(object->type = armature)
		success = Armature_applyRot(self->object)
	return PyNone
}

and in Armature...
int Armature_applyRot(PyObject *object)
{
	success = do the armature specific code....
	return success
}

This would be a matter of cut/pase from the different CASE: statements in
the /src code. Just another idea :)





More information about the Bf-python mailing list