Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--release/scripts/3ds_import.py3
-rw-r--r--release/scripts/animation_trajectory.py5
-rw-r--r--release/scripts/bvh_import.py11
-rw-r--r--release/scripts/import_obj.py2
-rw-r--r--release/scripts/lightwave_import.py3
-rw-r--r--release/scripts/mesh_edges2curves.py4
-rw-r--r--source/blender/python/api2_2x/Scene.c140
-rw-r--r--source/blender/python/api2_2x/Scene.h4
-rw-r--r--source/blender/python/api2_2x/doc/Scene.py21
9 files changed, 141 insertions, 52 deletions
diff --git a/release/scripts/3ds_import.py b/release/scripts/3ds_import.py
index 4c37b75b02a..8014186b637 100644
--- a/release/scripts/3ds_import.py
+++ b/release/scripts/3ds_import.py
@@ -794,8 +794,7 @@ def load_3ds(filename, PREF_UI= True):
scn= Scene.GetCurrent()
SCN_OBJECTS = scn.objects
- for ob in SCN_OBJECTS:
- ob.sel= 0
+ SCN_OBJECTS.selected = [] # de select all
importedObjects= [] # Fill this list with objects
process_next_chunk(file, current_chunk, importedObjects)
diff --git a/release/scripts/animation_trajectory.py b/release/scripts/animation_trajectory.py
index ba20ee68a97..0bdcd719c06 100644
--- a/release/scripts/animation_trajectory.py
+++ b/release/scripts/animation_trajectory.py
@@ -548,9 +548,8 @@ Blender.Text.unlink(scripting)
#Go to frame that correspond to selected "vertex"
Blender.Set('curframe', TestFRAME[k])
- #un select all objects
- for _ob in Blender.Object.GetSelected():
- _ob.sel= False
+ scene.objects.selected = [] #un select all objects
+
#FIXED TestLIST[j][0].sel=0, but no j. So ob.sel and above variable changed in obj
ob.sel= True
Blender.Run('Edit_Trajectory')
diff --git a/release/scripts/bvh_import.py b/release/scripts/bvh_import.py
index 2993cd088a7..30e42095d24 100644
--- a/release/scripts/bvh_import.py
+++ b/release/scripts/bvh_import.py
@@ -311,8 +311,7 @@ def bvh_node_dict2objects(bvh_nodes, IMPORT_START_FRAME= 1):
IMPORT_START_FRAME= 1
scn= Blender.Scene.GetCurrent()
- for ob in scn.objects:
- ob.sel= 0
+ scn.objects.selected = []
objects= []
@@ -444,14 +443,10 @@ def bvh_node_dict2armature(bvh_nodes, IMPORT_START_FRAME= 1):
scn= Blender.Scene.GetCurrent()
- for ob in scn.objects:
- ob.sel= 0
+ scn.objects.selected = []
scn.link(arm_ob)
- arm_ob.sel= 1
- arm_ob.Layers= scn.Layers
-
-
+ scn.objects.context = [arm_ob]
# Now Apply the animation to the armature
diff --git a/release/scripts/import_obj.py b/release/scripts/import_obj.py
index ed379ac52ab..e611669d1c9 100644
--- a/release/scripts/import_obj.py
+++ b/release/scripts/import_obj.py
@@ -672,7 +672,7 @@ def load_obj(filepath, CLAMP_SIZE= 0.0, CREATE_FGONS= True, CREATE_SMOOTH_GROUPS
# deselect all
- for ob in Scene.GetCurrent().objects: ob.sel= False
+ Scene.GetCurrent().objects.selected = []
new_objects= [] # put new objects here
print '\tbuilding geometry;\n\tverts:%i faces:%i materials: %i smoothgroups:%i ...' % ( len(verts_loc), len(faces), len(unique_materials), len(unique_smooth_groups) ),
diff --git a/release/scripts/lightwave_import.py b/release/scripts/lightwave_import.py
index b80498d455b..0cf544e1744 100644
--- a/release/scripts/lightwave_import.py
+++ b/release/scripts/lightwave_import.py
@@ -222,8 +222,7 @@ def read(filename):
tobj.logcon ("Importing file:")
tobj.logcon (filename)
- for ob in Blender.Scene.GetCurrent().objects:
- ob.sel= 0
+ Blender.Scene.GetCurrent().objects.selected = []
start = Blender.sys.time()
file = open(filename, "rb")
diff --git a/release/scripts/mesh_edges2curves.py b/release/scripts/mesh_edges2curves.py
index 9c8007b0054..70be7524b5c 100644
--- a/release/scripts/mesh_edges2curves.py
+++ b/release/scripts/mesh_edges2curves.py
@@ -118,8 +118,8 @@ def polysFromMesh(me):
def mesh2polys():
scn= Scene.GetCurrent()
- for ob in scn.objects:
- ob.sel= 0
+ scn.objects.selected = []
+
meshOb= scn.objects.active
if meshOb==None or meshOb.type != 'Mesh':
Draw.PupMenu( 'ERROR: No Active Mesh Selected, Aborting' )
diff --git a/source/blender/python/api2_2x/Scene.c b/source/blender/python/api2_2x/Scene.c
index ee254df8bc1..8e737f1f496 100644
--- a/source/blender/python/api2_2x/Scene.c
+++ b/source/blender/python/api2_2x/Scene.c
@@ -83,6 +83,14 @@ PyObject *M_Object_Get( PyObject * self, PyObject * args ); /* from Object.c */
#define SCENE_DEL_CHECK_PY(bpy_scene) if (!(bpy_scene->scene)) return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "Scene has been removed" ) )
#define SCENE_DEL_CHECK_INT(bpy_scene) if (!(bpy_scene->scene)) return ( EXPP_ReturnIntError( PyExc_RuntimeError, "Scene has been removed" ) )
+
+enum obj_consts {
+ EXPP_OBSEQ_NORMAL = 0,
+ EXPP_OBSEQ_SELECTED,
+ EXPP_OBSEQ_CONTEXT,
+};
+
+
/*-----------------------Python API function prototypes for the Scene module--*/
static PyObject *M_Scene_New( PyObject * self, PyObject * args,
PyObject * keywords );
@@ -1118,6 +1126,71 @@ static PyObject *SceneObSeq_getObjects( BPy_SceneObSeq *self, void *mode)
return SceneObSeq_CreatePyObject(self->bpyscene, NULL, (int)((long)mode));
}
+int SceneObSeq_setObjects( BPy_SceneObSeq *self, PyObject *value, void *_mode_)
+{
+ /*
+ ONLY SUPPORTS scn.objects.selected and scn.objects.context
+ cannot assign to scn.objects yet!!!
+ */
+ PyObject *item;
+ Scene *scene= self->bpyscene->scene;
+ Object *blen_ob;
+ Base *base;
+ int size, mode = (int)_mode_;
+
+ SCENE_DEL_CHECK_INT(self->bpyscene);
+
+ /* scn.objects.selected = scn.objects - shortcut to select all */
+ if (BPy_SceneObSeq_Check(value)) {
+ BPy_SceneObSeq *bpy_sceneseq = (BPy_SceneObSeq *)value;
+ if (self->bpyscene->scene != bpy_sceneseq->bpyscene->scene)
+ return EXPP_ReturnIntError( PyExc_ValueError,
+ "Cannot assign a SceneObSeq type from another scene" );
+ if (bpy_sceneseq->mode != EXPP_OBSEQ_NORMAL)
+ return EXPP_ReturnIntError( PyExc_ValueError,
+ "Can only assign scn.objects to scn.objects.context or scn.objects.selected" );
+
+ for (base= scene->base.first; base; base= base->next) {
+ base->flag |= SELECT;
+ base->object->flag |= SELECT;
+
+ if (mode==EXPP_OBSEQ_CONTEXT && G.vd) {
+ base->object->lay= base->lay= G.vd->lay;
+ }
+ }
+ return 0;
+ }
+
+ if (!PySequence_Check(value))
+ return EXPP_ReturnIntError( PyExc_ValueError,
+ "Error, must assign a sequence of objects to scn.objects.selected" );
+
+ /* for context and selected, just deselect, dont remove */
+ for (base= scene->base.first; base; base= base->next) {
+ base->flag &= ~SELECT;
+ base->object->flag &= ~SELECT;
+ }
+
+ size = PySequence_Length(value);
+ while (size) {
+ size--;
+ item = PySequence_GetItem(value, size);
+ if ( PyObject_TypeCheck(item, &Object_Type) ) {
+ blen_ob= ((BPy_Object *)item)->object;
+ base = object_in_scene( blen_ob, scene );
+ if (base) {
+ blen_ob->flag |= SELECT;
+ base->flag |= SELECT;
+ if (mode==EXPP_OBSEQ_CONTEXT && G.vd) {
+ blen_ob->lay= base->lay= G.vd->lay;
+ }
+ }
+ }
+ Py_DECREF(item);
+ }
+ return 0;
+}
+
static PyObject *SceneObSeq_CreatePyObject( BPy_Scene *self, Base *iter, int mode )
{
@@ -1133,9 +1206,9 @@ static int SceneObSeq_len( BPy_SceneObSeq * self )
Scene *scene= self->bpyscene->scene;
SCENE_DEL_CHECK_INT(self->bpyscene);
- if (self->mode == 0) /* all obejcts */
+ if (self->mode == EXPP_OBSEQ_NORMAL)
return BLI_countlist( &( scene->base ) );
- else if (self->mode == 1) { /* selected obejcts */
+ else if (self->mode == EXPP_OBSEQ_SELECTED) {
int len=0;
Base *base;
for (base= scene->base.first; base; base= base->next) {
@@ -1144,7 +1217,7 @@ static int SceneObSeq_len( BPy_SceneObSeq * self )
}
}
return len;
- } else if (self->mode == 2) { /* user context */
+ } else if (self->mode == EXPP_OBSEQ_CONTEXT) {
int len=0;
Base *base;
@@ -1176,15 +1249,15 @@ static PyObject *SceneObSeq_item( BPy_SceneObSeq * self, int i )
SCENE_DEL_CHECK_PY(self->bpyscene);
/* objects */
- if (self->mode==0)
+ if (self->mode==EXPP_OBSEQ_NORMAL)
for (base= scene->base.first; base && i!=index; base= base->next, index++) {}
/* selected */
- else if (self->mode==1)
+ else if (self->mode==EXPP_OBSEQ_SELECTED)
for (base= scene->base.first; base && i!=index; base= base->next)
if (base->flag & SELECT)
index++;
/* context */
- else if (self->mode==2)
+ else if (self->mode==EXPP_OBSEQ_CONTEXT)
if (G.vd)
for (base= scene->base.first; base && i!=index; base= base->next)
if ((base->flag & SELECT) && (base->lay & G.vd->lay))
@@ -1233,10 +1306,10 @@ static PyObject *SceneObSeq_getIter( BPy_SceneObSeq * self )
SCENE_DEL_CHECK_PY(self->bpyscene);
- if (self->mode==1) /* selected */
+ if (self->mode==EXPP_OBSEQ_SELECTED)
while (base && !(base->flag & SELECT))
base= base->next;
- else if (self->mode==2) { /* context */
+ else if (self->mode==EXPP_OBSEQ_CONTEXT) {
if (!G.vd)
base= NULL; /* will never iterate if we have no */
else
@@ -1269,10 +1342,10 @@ static PyObject *SceneObSeq_nextIter( BPy_SceneObSeq * self )
object= Object_CreatePyObject( self->iter->object );
base= self->iter->next;
- if (self->mode==1) /* selected */
+ if (self->mode==EXPP_OBSEQ_SELECTED)
while (base && !(base->flag & SELECT))
base= base->next;
- else if (self->mode==2) { /* context */
+ else if (self->mode==EXPP_OBSEQ_CONTEXT) {
if (!G.vd)
base= NULL; /* will never iterate if we have no */
else
@@ -1280,7 +1353,6 @@ static PyObject *SceneObSeq_nextIter( BPy_SceneObSeq * self )
base= base->next;
}
self->iter= base;
-
return object;
}
@@ -1290,7 +1362,7 @@ static PyObject *SceneObSeq_link( BPy_SceneObSeq * self, PyObject *pyobj )
SCENE_DEL_CHECK_PY(self->bpyscene);
/* this shold eventually replace Scene_link */
- if (self->mode != 0)
+ if (self->mode != EXPP_OBSEQ_NORMAL)
return (EXPP_ReturnPyObjError( PyExc_TypeError,
"Cannot link to objects.selection or objects.context!" ));
@@ -1317,7 +1389,7 @@ static PyObject *SceneObSeq_new( BPy_SceneObSeq * self, PyObject *args )
SCENE_DEL_CHECK_PY(self->bpyscene);
- if (self->mode != 0)
+ if (self->mode != EXPP_OBSEQ_NORMAL)
return EXPP_ReturnPyObjError( PyExc_TypeError,
"Cannot add new to objects.selection or objects.context!" );
@@ -1455,16 +1527,16 @@ typeError:
}
-
static PyObject *SceneObSeq_unlink( BPy_SceneObSeq * self, PyObject *args )
{
PyObject *pyobj;
Object *blen_ob;
+ Scene *scene;
Base *base= NULL;
SCENE_DEL_CHECK_PY(self->bpyscene);
- if (self->mode != 0)
+ if (self->mode != EXPP_OBSEQ_NORMAL)
return (EXPP_ReturnPyObjError( PyExc_TypeError,
"Cannot add new to objects.selection or objects.context!" ));
@@ -1473,23 +1545,25 @@ static PyObject *SceneObSeq_unlink( BPy_SceneObSeq * self, PyObject *args )
"expected a python object as an argument" ) );
blen_ob = ( ( BPy_Object * ) pyobj )->object;
-
+
+ scene = self->bpyscene->scene;
+
/* is the object really in the scene? */
- base = object_in_scene( blen_ob, self->bpyscene->scene );
+ base = object_in_scene( blen_ob, scene);
- if( base ) { /* if it is, remove it */
+ if( base ) { /* if it is, remove it */
/* check that there is a data block before decrementing refcount */
- if( (ID *)blen_ob->data )
- ((ID *)blen_ob->data)->us--;
+ if( (ID *)base->object->data )
+ ((ID *)base->object->data)->us--;
else if( blen_ob->type != OB_EMPTY )
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "Object has no data!" );
+ "Object has no data!" );
- if (self->bpyscene->scene->basact==base)
- self->bpyscene->scene->basact= NULL; /* in case the object was selected */
+ if (scene->basact==base)
+ scene->basact= NULL; /* in case the object was selected */
- BLI_remlink( &(self->bpyscene->scene)->base, base );
- blen_ob->id.us--;
+ BLI_remlink( &scene->base, base );
+ base->object->id.us--;
MEM_freeN( base );
}
Py_RETURN_NONE;
@@ -1503,7 +1577,7 @@ PyObject *SceneObSeq_getActive(BPy_SceneObSeq *self)
SCENE_DEL_CHECK_PY(self->bpyscene);
- if (self->mode!=0)
+ if (self->mode!=EXPP_OBSEQ_NORMAL)
return (EXPP_ReturnPyObjError( PyExc_TypeError,
"cannot get active from objects.selected or objects.context" ));
@@ -1526,7 +1600,7 @@ static int SceneObSeq_setActive(BPy_SceneObSeq *self, PyObject *value)
SCENE_DEL_CHECK_INT(self->bpyscene);
- if (self->mode!=0)
+ if (self->mode!=EXPP_OBSEQ_NORMAL)
return (EXPP_ReturnIntError( PyExc_TypeError,
"cannot set active from objects.selected or objects.context" ));
@@ -1586,10 +1660,10 @@ static PyObject *SceneObSeq_repr( BPy_SceneObSeq * self )
{
if( !(self->bpyscene->scene) )
return PyString_FromFormat( "[Scene ObjectSeq Removed]" );
- else if (self->mode==1)
+ else if (self->mode==EXPP_OBSEQ_SELECTED)
return PyString_FromFormat( "[Scene ObjectSeq Selected \"%s\"]",
self->bpyscene->scene->id.name + 2 );
- else if (self->mode==2)
+ else if (self->mode==EXPP_OBSEQ_CONTEXT)
return PyString_FromFormat( "[Scene ObjectSeq Context \"%s\"]",
self->bpyscene->scene->id.name + 2 );
@@ -1600,13 +1674,13 @@ static PyObject *SceneObSeq_repr( BPy_SceneObSeq * self )
static PyGetSetDef SceneObSeq_getseters[] = {
{"selected",
- (getter)SceneObSeq_getObjects, (setter)NULL,
+ (getter)SceneObSeq_getObjects, (setter)SceneObSeq_setObjects,
"sequence of selected objects",
- (void *)1},
+ (void *)EXPP_OBSEQ_SELECTED},
{"context",
- (getter)SceneObSeq_getObjects, (setter)NULL,
+ (getter)SceneObSeq_getObjects, (setter)SceneObSeq_setObjects,
"sequence of user context objects",
- (void *)2},
+ (void *)EXPP_OBSEQ_CONTEXT},
{"active",
(getter)SceneObSeq_getActive, (setter)SceneObSeq_setActive,
"active object",
diff --git a/source/blender/python/api2_2x/Scene.h b/source/blender/python/api2_2x/Scene.h
index ee4c4573983..4d294700c63 100644
--- a/source/blender/python/api2_2x/Scene.h
+++ b/source/blender/python/api2_2x/Scene.h
@@ -42,6 +42,8 @@ extern PyTypeObject SceneObSeq_Type;
#define BPy_Scene_Check(v) \
((v)->ob_type == &Scene_Type)
+#define BPy_SceneObSeq_Check(v) \
+ ((v)->ob_type == &SceneObSeq_Type)
/*---------------------------Python BPy_Scene structure definition----------*/
typedef struct {
@@ -63,7 +65,7 @@ typedef struct {
PyObject *Scene_Init( void );
PyObject *Scene_CreatePyObject( Scene * cam );
-Scene *Scene_FromPyObject( PyObject * pyobj );
+/*Scene *Scene_FromPyObject( PyObject * pyobj );*/ /* not used yet */
int Scene_CheckPyObject( PyObject * pyobj );
Scene *GetSceneByName( char *name );
diff --git a/source/blender/python/api2_2x/doc/Scene.py b/source/blender/python/api2_2x/doc/Scene.py
index 2ada3062826..4fd9f896edc 100644
--- a/source/blender/python/api2_2x/doc/Scene.py
+++ b/source/blender/python/api2_2x/doc/Scene.py
@@ -315,6 +315,27 @@ class SceneObjects:
=========================================
This object gives access to the Objects in a Scene in Blender.
+ Example::
+ from Blender import Scene
+ scn = Scene.GetCurrent()
+
+ scn.objects.selected = [] # select none
+ scn.objects.selected = scn.objects # select all
+ scn.objects.context = scn.objects # select all and move into the scenes display layer
+
+ # get a list of mesh objects
+ obs = [ob for ob in scn.objects if ob.type == 'Mesh']
+
+ # Select only these mesh objects
+ scn.objects.selected = obs
+
+ # print all object names
+ for ob in scn.objects: print ob.name
+
+ # make a list of objects that you can add and remove to
+ # will not affect the current scene
+ scene_obs = list(scn.objects)
+
@ivar selected: an iterator over all the selected objects in a scene.
@type selected: sequence of L{Object}
@ivar context: an iterator over all the visible selected objects in a scene.