7
$\begingroup$

I have always had a unique mesh for every MESH type object in blender, to easily access them together in a python script (Iterate through objects and do something with an object and a mesh with the same name).


Now I want to have a mesh for several objects. I want to export the meshes and the objects separately but for every object, export the mesh it is connected to (its name, index or some identifier) to later connect them in an external program. I already found mesh.users which shows how many objects are using this mesh, but I want to reference all of those objects. I am exporting to a text file. So how could I do this in Blender?

$\endgroup$
  • $\begingroup$ I have found the answer, and will answer my question when I can if noone asnwers it until then. $\endgroup$ – János Turánszki Feb 20 '14 at 23:36
  • $\begingroup$ it is Ok to answer own questions see:stackoverflow.com/help/self-answer $\endgroup$ – stacker Feb 21 '14 at 6:38
15
$\begingroup$

I'm not sure what you're asking, but you can retrieve the mesh datablock associated with an object like

ob = bpy.context.object # get the active object for example
mesh = ob.data

The reverse is not directly possible. A mesh can be used by many objects, and the mesh doesn't know/store who its "owners" are. You can build a reverse index however:

mesh_owners = {}
for ob in bpy.data.objects:
    if ob.type == 'MESH':
        mesh_owners.setdefault(ob.data, []).append(ob)

print(mesh_owners[mesh])
# Example output - mesh is used by a one object:
#[bpy.data.objects['Cube.003']]
$\endgroup$
  • $\begingroup$ I have found the same solution, thank you for answering. $\endgroup$ – János Turánszki Feb 21 '14 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.