python api
removed most custom add_*data* wrappers from Main.c removed makeCurrent() from Text.c (was never in a release), use "bpy.texts.active = text" now clamp new image sizes made add_empty_action accept a string rather then a blocktype since the blocktype was only being used to choose one of 3 strings anyway.
This commit is contained in:
@@ -159,7 +159,7 @@ Text *add_empty_text(char *name)
|
||||
Text *ta;
|
||||
TextLine *tmp;
|
||||
|
||||
ta= alloc_libblock(&G.main->text, ID_TXT, "Text");
|
||||
ta= alloc_libblock(&G.main->text, ID_TXT, name);
|
||||
ta->id.us= 1;
|
||||
|
||||
ta->name= NULL;
|
||||
|
||||
@@ -119,7 +119,7 @@ void select_actionchannel_by_name (struct bAction *act, char *name, int select);
|
||||
|
||||
/* Action */
|
||||
struct bActionChannel* get_hilighted_action_channel(struct bAction* action);
|
||||
struct bAction *add_empty_action(int blocktype);
|
||||
struct bAction *add_empty_action(char *name);
|
||||
|
||||
void winqreadactionspace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt);
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
|
||||
/* Use the add_* from BKE_* */
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_utildefines.h" /* clamp */
|
||||
#include "BKE_armature.h"
|
||||
#include "BKE_ipo.h"
|
||||
#include "BKE_image.h"
|
||||
@@ -74,6 +75,7 @@
|
||||
#include "BIF_drawimage.h" /* what image */
|
||||
#include "BIF_drawtext.h" /* unlink_text */
|
||||
#include "BIF_editsound.h" /* sound_new_sound */
|
||||
#include "BIF_editaction.h" /* add_empty_action */
|
||||
|
||||
/* python types */
|
||||
#include "../BPY_extern.h" /* clearing scriptlinks */
|
||||
@@ -91,6 +93,7 @@
|
||||
#include "Mesh.h"
|
||||
#include "Lattice.h"
|
||||
#include "Metaball.h"
|
||||
#include "Text.h"
|
||||
#include "Text3d.h"
|
||||
#include "Font.h"
|
||||
#include "Group.h"
|
||||
@@ -103,6 +106,12 @@
|
||||
#include "Main.h"
|
||||
#include "Scene.h"
|
||||
|
||||
/* used only for texts.active */
|
||||
#include "BIF_screen.h"
|
||||
#include "DNA_space_types.h"
|
||||
#include "DNA_screen_types.h"
|
||||
|
||||
|
||||
static PyObject *MainSeq_CreatePyObject( Link *iter, int type )
|
||||
{
|
||||
BPy_MainSeq *seq = PyObject_NEW( BPy_MainSeq, &MainSeq_Type);
|
||||
@@ -253,6 +262,15 @@ PyObject *MainSeq_getActive(BPy_MainSeq *self)
|
||||
return Image_CreatePyObject( G.sima->image );
|
||||
}
|
||||
break;
|
||||
case ID_TXT: {
|
||||
SpaceText *st= curarea->spacedata.first;
|
||||
|
||||
if (st->spacetype!=SPACE_TEXT || st->text==NULL) {
|
||||
Py_RETURN_NONE;
|
||||
} else {
|
||||
return Text_CreatePyObject( st->text );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
@@ -306,14 +324,29 @@ static int MainSeq_setActive(BPy_MainSeq *self, PyObject *value)
|
||||
G.sima->image= data;
|
||||
}
|
||||
return 0;
|
||||
|
||||
case ID_TXT:
|
||||
if (!BPy_Text_Check(value)) {
|
||||
return EXPP_ReturnIntError(PyExc_TypeError,
|
||||
"Must be a text" );
|
||||
} else {
|
||||
SpaceText *st= curarea->spacedata.first;
|
||||
Text *data = ((BPy_Text *)value)->text;
|
||||
|
||||
if( !data )
|
||||
return EXPP_ReturnIntError( PyExc_RuntimeError,
|
||||
"This object isn't linked to a Blender Text Object" );
|
||||
if(st->spacetype!=SPACE_TEXT)
|
||||
return 0;
|
||||
st->text = data;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"Only Scene and Image types have the active attribute" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* New Data, internal functions */
|
||||
Mesh *add_mesh__internal(char *name)
|
||||
{
|
||||
@@ -325,131 +358,24 @@ Mesh *add_mesh__internal(char *name)
|
||||
when ob.getBoundBox() is called.*/
|
||||
MEM_freeN(mesh->bb);
|
||||
mesh->bb= NULL;
|
||||
mesh->id.us = 0;
|
||||
return mesh;
|
||||
}
|
||||
|
||||
Curve *add_curve__internal(char *name)
|
||||
{
|
||||
Curve *blcurve = NULL; /* for actual Curve Data we create in Blender */
|
||||
|
||||
blcurve = add_curve( name, OB_CURVE ); /* first create the Curve Data in Blender */
|
||||
|
||||
/* null check? */
|
||||
|
||||
/* return user count to zero because add_curve() inc'd it */
|
||||
blcurve->id.us = 0;
|
||||
return blcurve;
|
||||
}
|
||||
|
||||
MetaBall *add_metaball__internal(char *name)
|
||||
{
|
||||
MetaBall *blmball; /* for actual Data we create in Blender */
|
||||
blmball = add_mball( name ); /* first create the MetaBall Data in Blender */
|
||||
blmball->id.us = 0;
|
||||
return blmball;
|
||||
}
|
||||
|
||||
Material *add_material__internal(char *name)
|
||||
{
|
||||
Material *bmat;
|
||||
bmat = add_material( name );
|
||||
bmat->id.us = 0; /* was incref'ed by add_material() above */
|
||||
return bmat;
|
||||
}
|
||||
|
||||
Tex *add_texture__internal(char *name)
|
||||
{
|
||||
Tex *btex;
|
||||
btex= add_texture( name );
|
||||
btex->id.us = 0; /* was incref'ed by add_material() above */
|
||||
return btex;
|
||||
}
|
||||
|
||||
Lattice *add_lattice__internal(char *name)
|
||||
{
|
||||
Lattice *blat;
|
||||
blat= add_lattice(name);
|
||||
blat->id.us = 0; /* was incref'ed by add_material() above */
|
||||
return blat;
|
||||
}
|
||||
|
||||
Lamp *add_lamp__internal(char *name)
|
||||
{
|
||||
Lamp *blam;
|
||||
blam= add_lamp( name );
|
||||
blam->id.us = 0; /* was incref'ed by add_material() above */
|
||||
return blam;
|
||||
}
|
||||
|
||||
Camera *add_camera__internal(char *name)
|
||||
{
|
||||
Camera *bcam;
|
||||
bcam= add_camera( name );
|
||||
bcam->id.us = 0; /* was incref'ed by add_material() above */
|
||||
return bcam;
|
||||
}
|
||||
|
||||
Ipo *add_ipo__internal(char *name, short idcode)
|
||||
{
|
||||
Ipo *blipo;
|
||||
blipo = add_ipo( name, idcode );
|
||||
blipo->id.us = 0;
|
||||
return blipo;
|
||||
}
|
||||
|
||||
World *add_world__internal(char *name)
|
||||
{
|
||||
World *bwor;
|
||||
bwor= add_world( name );
|
||||
bwor->id.us = 0; /* was incref'ed by add_material() above */
|
||||
return bwor;
|
||||
}
|
||||
|
||||
Text *add_text__internal(char *name)
|
||||
{
|
||||
Text *btxt;
|
||||
btxt= add_empty_text( name );
|
||||
return btxt;
|
||||
}
|
||||
|
||||
Group *add_group__internal(char *name)
|
||||
{
|
||||
Group *bgrp;
|
||||
bgrp= add_group( name );
|
||||
bgrp->id.us = 1;
|
||||
return bgrp;
|
||||
}
|
||||
|
||||
bArmature *add_armature__internal(char *name)
|
||||
{
|
||||
bArmature *barm;
|
||||
barm= add_armature( name );
|
||||
barm->id.us = 0;
|
||||
return barm;
|
||||
}
|
||||
|
||||
bAction *add_action__internal(char *name)
|
||||
{
|
||||
bAction *bact;
|
||||
bact = alloc_libblock( &G.main->action, ID_AC, name );
|
||||
bact->id.flag |= LIB_FAKEUSER; /* no need to assign a user because alloc_libblock alredy assigns one */
|
||||
return bact;
|
||||
}
|
||||
|
||||
|
||||
PyObject *MainSeq_new(BPy_MainSeq *self, PyObject * args)
|
||||
{
|
||||
ID *id = NULL;
|
||||
char *name, *ipo_type;
|
||||
int img_width=256, img_height=256;
|
||||
short ipo_code = 0;
|
||||
int user_count = 0;
|
||||
|
||||
if (self->type == ID_IM) {
|
||||
/* Image, accepts width and height*/
|
||||
if( !PyArg_ParseTuple( args, "s|ii", &name, &img_width, &img_height ) )
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"one string and two ints expected as arguments" );
|
||||
CLAMP(img_width, 4, 5000);
|
||||
CLAMP(img_height, 4, 5000);
|
||||
|
||||
} else if (self->type == ID_IP) {
|
||||
/* IPO, needs name and type strings */
|
||||
@@ -493,6 +419,7 @@ PyObject *MainSeq_new(BPy_MainSeq *self, PyObject * args)
|
||||
switch (self->type) {
|
||||
case ID_SCE:
|
||||
id = (ID *)add_scene( name );
|
||||
user_count = 1;
|
||||
break;
|
||||
case ID_OB:
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
@@ -501,16 +428,16 @@ PyObject *MainSeq_new(BPy_MainSeq *self, PyObject * args)
|
||||
id = (ID *)add_mesh__internal( name );
|
||||
break;
|
||||
case ID_CU:
|
||||
id = (ID *)add_curve__internal( name );
|
||||
id = (ID *)add_curve( name, OB_CURVE );
|
||||
break;
|
||||
case ID_MB:
|
||||
id = (ID *)add_metaball__internal( name );
|
||||
id = (ID *)add_mball( name );
|
||||
break;
|
||||
case ID_MA:
|
||||
id = (ID *)add_material__internal( name );
|
||||
id = (ID *)add_material( name );
|
||||
break;
|
||||
case ID_TE:
|
||||
id = (ID *)add_texture__internal( name );
|
||||
id = (ID *)add_texture( name );
|
||||
break;
|
||||
case ID_IM:
|
||||
{
|
||||
@@ -522,44 +449,51 @@ PyObject *MainSeq_new(BPy_MainSeq *self, PyObject * args)
|
||||
break;
|
||||
}
|
||||
case ID_LT:
|
||||
id = (ID *)add_lattice__internal( name );
|
||||
id = (ID *)add_lattice( name );
|
||||
break;
|
||||
case ID_LA:
|
||||
id = (ID *)add_lamp__internal( name );
|
||||
id = (ID *)add_lamp( name );
|
||||
break;
|
||||
case ID_CA:
|
||||
id = (ID *)add_camera__internal( name );
|
||||
id = (ID *)add_camera( name );
|
||||
break;
|
||||
case ID_IP:
|
||||
id = (ID *)add_ipo__internal( name, ipo_code );
|
||||
id = (ID *)add_ipo( name, ipo_code );
|
||||
break;
|
||||
case ID_WO:
|
||||
id = (ID *)add_world__internal( name );
|
||||
id = (ID *)add_world( name );
|
||||
break;
|
||||
case ID_VF:
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"Cannot create new fonts, use the load() function to load from a file" );
|
||||
case ID_TXT:
|
||||
id = (ID *)add_text__internal( name );
|
||||
id = (ID *)add_empty_text( name );
|
||||
user_count = 1;
|
||||
break;
|
||||
case ID_SO:
|
||||
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||
"Cannot create new sounds, use the load() function to load from a file" );
|
||||
case ID_GR:
|
||||
id = (ID *)add_group__internal( name );
|
||||
id = (ID *)add_group( name );
|
||||
user_count = 1;
|
||||
break;
|
||||
case ID_AR:
|
||||
id = (ID *)add_armature__internal( name );
|
||||
id = (ID *)add_armature( name );
|
||||
break;
|
||||
case ID_AC:
|
||||
id = (ID *)add_action__internal( name );
|
||||
id = (ID *)add_empty_action( name );
|
||||
user_count = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (id) return GetPyObjectFromID(id);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
if (!id)
|
||||
Py_RETURN_NONE;
|
||||
|
||||
/* set some types user count to 1, otherwise zero */
|
||||
id->us = user_count;
|
||||
|
||||
return GetPyObjectFromID(id);
|
||||
}
|
||||
|
||||
PyObject *MainSeq_load(BPy_MainSeq *self, PyObject * args)
|
||||
{
|
||||
|
||||
@@ -44,11 +44,6 @@
|
||||
#include "gen_library.h"
|
||||
#include "../BPY_extern.h"
|
||||
|
||||
/* used only for makeCurrent, this may be deprecated when Blender.Base is implimented */
|
||||
#include "BIF_screen.h"
|
||||
#include "DNA_space_types.h"
|
||||
#include "DNA_screen_types.h"
|
||||
|
||||
#define EXPP_TEXT_MODE_FOLLOW TXT_FOLLOW
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -91,7 +86,6 @@ struct PyMethodDef M_Text_methods[] = {
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
static int Text_IsLinked( BPy_Text * self );
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Text methods declarations: */
|
||||
@@ -102,7 +96,6 @@ static PyObject *Text_clear( BPy_Text * self );
|
||||
static PyObject *Text_write( BPy_Text * self, PyObject * args );
|
||||
static PyObject *Text_set( BPy_Text * self, PyObject * args );
|
||||
static PyObject *Text_asLines( BPy_Text * self );
|
||||
static PyObject *Text_makeCurrent( BPy_Text * self );
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Text methods table: */
|
||||
@@ -125,8 +118,6 @@ static PyMethodDef BPy_Text_methods[] = {
|
||||
"(name, val) - Set attribute 'name' to value 'val'"},
|
||||
{"asLines", ( PyCFunction ) Text_asLines, METH_NOARGS,
|
||||
"() - Return text buffer as a list of lines"},
|
||||
{"makeCurrent", ( PyCFunction ) Text_makeCurrent, METH_NOARGS,
|
||||
"() - display this text."},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
@@ -468,21 +459,6 @@ static PyObject *Text_asLines( BPy_Text * self )
|
||||
return list;
|
||||
}
|
||||
|
||||
static PyObject *Text_makeCurrent( BPy_Text * self )
|
||||
{
|
||||
SpaceText *st= curarea->spacedata.first;
|
||||
|
||||
if( !self->text )
|
||||
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||
"This object isn't linked to a Blender Text Object" );
|
||||
|
||||
if(st->spacetype!=SPACE_TEXT)
|
||||
Py_RETURN_NONE;
|
||||
|
||||
st->text = self->text;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: Text_dealloc */
|
||||
/* Description: This is a callback function for the BPy_Text type. It is */
|
||||
@@ -513,32 +489,13 @@ static int Text_compare( BPy_Text * a, BPy_Text * b )
|
||||
/*****************************************************************************/
|
||||
static PyObject *Text_repr( BPy_Text * self )
|
||||
{
|
||||
if( self->text && Text_IsLinked( self ) )
|
||||
if( self->text )
|
||||
return PyString_FromFormat( "[Text \"%s\"]",
|
||||
self->text->id.name + 2 );
|
||||
else
|
||||
return PyString_FromString( "[Text <deleted>]" );
|
||||
}
|
||||
|
||||
/* Internal function to confirm if a Text wasn't unlinked.
|
||||
* This is necessary because without it, if a script writer
|
||||
* referenced an already unlinked Text obj, Blender would crash. */
|
||||
static int Text_IsLinked( BPy_Text * self )
|
||||
{
|
||||
Text *txt_iter = G.main->text.first;
|
||||
|
||||
while( txt_iter ) {
|
||||
if( self->text == txt_iter )
|
||||
return 1; /* ok, still linked */
|
||||
|
||||
txt_iter = txt_iter->id.next;
|
||||
}
|
||||
/* uh-oh, it was already deleted */
|
||||
self->text = NULL; /* so we invalidate the pointer */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python attributes get/set functions: */
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -125,12 +125,5 @@ class Text:
|
||||
@return: A list of strings, one for each line in the buffer
|
||||
"""
|
||||
|
||||
def makeCurrent():
|
||||
"""
|
||||
Display this text in the current 3d view if any
|
||||
@rtype: None
|
||||
@return: None
|
||||
"""
|
||||
|
||||
import id_generics
|
||||
Text.__doc__ += id_generics.attributes
|
||||
@@ -939,17 +939,16 @@ bActionChannel* get_hilighted_action_channel(bAction* action)
|
||||
|
||||
}
|
||||
|
||||
bAction *add_empty_action(int blocktype)
|
||||
bAction *add_empty_action(char *name)
|
||||
{
|
||||
bAction *act;
|
||||
char *str= "Action";
|
||||
|
||||
/*
|
||||
if(blocktype==ID_OB)
|
||||
str= "ObAction";
|
||||
else if(blocktype==ID_KE)
|
||||
str= "ShapeAction";
|
||||
|
||||
act= alloc_libblock(&G.main->action, ID_AC, str);
|
||||
*/
|
||||
act= alloc_libblock(&G.main->action, ID_AC, name);
|
||||
act->id.flag |= LIB_FAKEUSER;
|
||||
act->id.us++;
|
||||
return act;
|
||||
@@ -3514,7 +3513,7 @@ bAction* bake_action_with_client (bAction *act, Object *armob, float tolerance)
|
||||
}
|
||||
|
||||
/* Get a new action */
|
||||
result = add_empty_action(ID_PO);
|
||||
result = add_empty_action("Action");
|
||||
id= (ID *)armob;
|
||||
|
||||
/* Assign the new action a unique name */
|
||||
@@ -3599,7 +3598,7 @@ bAction* bake_obIPO_to_action (Object *ob)
|
||||
if (arm) {
|
||||
|
||||
oldframe = CFRA;
|
||||
result = add_empty_action(ID_PO);
|
||||
result = add_empty_action("Action");
|
||||
id = (ID *)ob;
|
||||
|
||||
sprintf (newname, "TESTOBBAKE");
|
||||
@@ -3671,7 +3670,7 @@ bAction* bake_everything_to_action (Object *ob)
|
||||
if (arm) {
|
||||
|
||||
oldframe = CFRA;
|
||||
result = add_empty_action(ID_PO);
|
||||
result = add_empty_action("Action");
|
||||
id = (ID *)ob;
|
||||
|
||||
sprintf (newname, "TESTOBBAKE");
|
||||
|
||||
@@ -90,7 +90,7 @@ ListBase *get_active_constraint_channels (Object *ob, int forcevalid)
|
||||
if (!forcevalid)
|
||||
return NULL;
|
||||
|
||||
ob->action=add_empty_action(ID_PO);
|
||||
ob->action=add_empty_action("Action");
|
||||
}
|
||||
|
||||
/* Make sure we have an actionchannel */
|
||||
|
||||
@@ -1684,7 +1684,7 @@ Ipo *verify_ipo(ID *from, short blocktype, char *actname, char *constname)
|
||||
}
|
||||
|
||||
if(ob->action==NULL)
|
||||
ob->action= add_empty_action(blocktype);
|
||||
ob->action= add_empty_action("Action");
|
||||
|
||||
achan= verify_action_channel(ob->action, actname);
|
||||
|
||||
|
||||
@@ -492,9 +492,9 @@ void add_empty_nlablock(void)
|
||||
|
||||
/* make new action */
|
||||
if ((ob->type == OB_ARMATURE) && (ob->flag & OB_POSEMODE))
|
||||
act= add_empty_action(ID_AR);
|
||||
act= add_empty_action("ObAction");
|
||||
else
|
||||
act= add_empty_action(ID_OB);
|
||||
act= add_empty_action("Action");
|
||||
|
||||
/* make a new strip for it */
|
||||
add_nla_block_by_name(act->id.name, ob, 0, 1, 1.0f);
|
||||
|
||||
@@ -1067,7 +1067,7 @@ void do_ipo_buttons(short event)
|
||||
notice("Note: Layer Ipo doesn't work in Actions");
|
||||
|
||||
if(ob->action==NULL)
|
||||
ob->action= add_empty_action(ID_OB);
|
||||
ob->action= add_empty_action("ObAction");
|
||||
achan= verify_action_channel(ob->action, "Object");
|
||||
if(achan->ipo==NULL && ob->ipo) {
|
||||
achan->ipo= ob->ipo;
|
||||
@@ -1114,7 +1114,7 @@ void do_ipo_buttons(short event)
|
||||
bActionChannel *achan;
|
||||
|
||||
if(ob->action==NULL)
|
||||
ob->action= add_empty_action(ID_KE);
|
||||
ob->action= add_empty_action("ShapeAction");
|
||||
achan= verify_action_channel(ob->action, "Shape");
|
||||
if(achan->ipo==NULL && key->ipo) {
|
||||
achan->ipo= key->ipo;
|
||||
|
||||
@@ -942,10 +942,15 @@ void do_global_buttons(unsigned short event)
|
||||
|
||||
/* Store current action */
|
||||
if (!idtest){
|
||||
if (act)
|
||||
if (act) {
|
||||
idtest= (ID *)copy_action(act);
|
||||
else
|
||||
idtest=(ID *)add_empty_action(ob->type==OB_ARMATURE?ID_PO:ID_OB);
|
||||
} else {
|
||||
if (ID_OB==ob->type) {
|
||||
idtest=(ID *)add_empty_action("ObAction");
|
||||
} else {
|
||||
idtest=(ID *)add_empty_action("Action");
|
||||
}
|
||||
}
|
||||
idtest->us--;
|
||||
}
|
||||
|
||||
|
||||
@@ -2224,7 +2224,7 @@ void special_aftertrans_update(TransInfo *t)
|
||||
act= ob->action;
|
||||
|
||||
if (!act)
|
||||
act= ob->action= add_empty_action(ID_PO);
|
||||
act= ob->action= add_empty_action("Action");
|
||||
|
||||
for (pchan=pose->chanbase.first; pchan; pchan=pchan->next){
|
||||
if (pchan->bone->flag & BONE_TRANSFORM){
|
||||
|
||||
Reference in New Issue
Block a user