[Bf-python] mesh block selection

models at paposo.com models at paposo.com
Sat Oct 4 04:56:57 CEST 2003


(This is not really a python module thing but i found the bug by looking at
object.link().)
I sorta figured out what is happening.  This button's action is called
through headerbuttons.c here:

void do_global_buttons(unsigned short event)
{
....
case B_MESHBROWSE:
   if(ob==0) return;
  if(ob->id.lib) return;

  id= ob->data;
  if(id==0) id= G.main->mesh.first;
  if(id==0) return;

  if(G.buts->menunr== -2) {
   activate_databrowse((ID *)G.buts->lockpoin, GS(id->name), 0,
B_MESHBROWSE, &G.buts->menunr, do_global_buttons);
   return;
  }
  if(G.buts->menunr < 0) return;

  idtest= G.main->mesh.first;
  while(idtest) {
   if(nr==G.buts->menunr) {

    set_mesh(ob, (Mesh *)idtest);

    allqueue(REDRAWBUTSEDIT, 0);
    allqueue(REDRAWVIEW3D, 0);
    allqueue(REDRAWACTION,0);
    allqueue(REDRAWIPO, 0);

    break;
   }
   nr++;
   idtest= idtest->next;
  }
  break;

The key here is the set_mesh(ob, (Mesh*)idtest).
This function attempts to change the active object's mesh to the mesh
datablock you choose in the menu.  This explains why the active object is
changing shapes.
It would seem to me that it would be better to select the all the objects in
the scene that the mesh datablocks are linked to rather than calling
set_mesh on the OBACT.
With this in mind I added this to the case statement:

case B_MESHBROWSE:

....
    basedeselect= G.scene->base.first;
    while(basedeselect)
    {
     if (basedeselect->flag & SELECT)
     {
      basedeselect->flag &= ~SELECT;

     }
     if(basedeselect->flag & ACTIVE)
     {
      basedeselect->flag &= ~ACTIVE;
     }
     basedeselect->object->flag= basedeselect->flag;
     basedeselect= basedeselect->next;
    }

    obtest= G.main->object.first;
    while(obtest)
    {
     if(obtest->data==idtest)
     {
      for(basetest= G.scene->base.first; basetest; basetest= basetest->next)
      {
       if(basetest->object->data == idtest)
       {
        countall();
        basetest->flag |= SELECT;
        basetest->flag |= ACTIVE;
        draw_object_ext(basetest);
       }
      }
     }
     obtest= obtest->id.next;
    }

.....

This will select all the objects in the scene that are linked to the mesh
datablock selected from the browse button. The problem is the ACTIVE flag
sorta hangs around until you get rid of it so I in mouse_select I just
duplicated the code for deselecting everything before selecting.

void mouse_select(void)
{
...
basedeselect= G.scene->base.first;
 while(basedeselect)
 {
  if (basedeselect->flag & SELECT)
  {
   basedeselect->flag &= ~SELECT;

  }
  if(basedeselect->flag & ACTIVE)
  {
   basedeselect->flag &= ~ACTIVE;
  }
  basedeselect->object->flag= basedeselect->flag;
  basedeselect= basedeselect->next;
 }
......

Anyway it does the job. If you like to see what it does I have the .c files
and a script to test sent.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: meshbrowse.zip
Type: application/x-zip-compressed
Size: 46610 bytes
Desc: not available
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20031003/c9045fb0/attachment.bin>


More information about the Bf-python mailing list