Accessing mesh users ?

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
u3dreal
Posts: 0
Joined: Tue May 08, 2007 4:49 pm
Location: Germany

Accessing mesh users ?

Post by u3dreal » Tue May 08, 2007 5:02 pm

Hi all,

since this is my first post i'd like to say hello to everybody. ;)

Hello !!!!

I'm about to help Ian with the blender exporter for
radium ( www.radiumrenderer.com ). So he can concentrate on the core.

Radium is a very exciting renderer using MLT to get excellent photrealistic
Images. Since i fell in love with blender not long ago
it was an ease to fall in love with Radium.

Ok so here my question.

During implementing instancing i found some unclear
part that i couldn't find anything on the net.

Is it possible to get the following data from the Blender.Mesh obj.
I would like to know the names of all users (objects) of the mesh.
I found that i could read out the total number of users by
Blender.Mesh.users but i couldn't find anything on how
to get the names of the users.

Any help would be apprechiated.

greetz

u3dreal ;)

reD_Fox
Posts: 0
Joined: Sat Mar 12, 2005 2:56 pm
Location: Abilene, KS

Post by reD_Fox » Wed May 09, 2007 3:11 pm

Boy, this may not be the right answer, but it's the only way I can think to do it:

Loop through all objects, comparing ob.getData(name_only=True) to the mesh's name.

I don't think the mesh is even aware of who all has its data (but I could be wrong).

Levi
A three-legged stool never wobbles.

revans
Posts: 0
Joined: Tue May 08, 2007 10:09 pm

Post by revans » Wed May 09, 2007 5:48 pm

I believe reD_Fox is correct. Here's a function that I wrote that may suit your needs:

Code: Select all

def getUsers(mesh):
  toReturn = []
  scene = Scene.GetCurrent()
  meshes = filter(lambda x: x.getType() == "Mesh", scene.getChildren())
  for mesh_obj in meshes:
     if mesh_obj.getData(False, True).name == mesh.name:
       toReturn.append(mesh_obj.getName())
  return toReturn
Hope this helps!
Ryan

revans
Posts: 0
Joined: Tue May 08, 2007 10:09 pm

Post by revans » Wed May 09, 2007 6:15 pm

Or, if you prefer list comprehensions:

Code: Select all

def getUsers(mesh):
  scene = Scene.GetCurrent()
  meshes = [obj for obj in scene.getChildren() if obj.getType() == "Mesh"]
  return [mesh_obj.getName() for mesh_obj in meshes if mesh_obj.getData(False, True).name == mesh.name]

reD_Fox
Posts: 0
Joined: Sat Mar 12, 2005 2:56 pm
Location: Abilene, KS

Post by reD_Fox » Thu May 10, 2007 4:14 am

Yes, revans got it right, with one small exception:
mesh_obj.getData(False,True).name
should be changed to
mesh_obj.getData(name_only=True)
for performance reasons.
The former loads the mesh into memory, then gets its name, when all you need is the mesh's name.

Levi
A three-legged stool never wobbles.

Post Reply