Get the object a mesh is connected with

(Jerri) #1

If I create a new mesh with Blender.NMesh.PutRaw (mesh, “Name”, 1), that functions returns an object to which this object is connected. But If the Mesh already exists and I use Blender.NMesh.PutRaw I just get None. So, if the mesh already exists, how do I get the name of the object it is connected to (if the mesh didn’t exists, its name will become mesh.001. But how do I now how much unnamed meshes where already created?)

(eeshlo) #2

This is what I do, I just rename the object to the meshname:

meshname = "whatever"
object = Blender.NMesh.PutRaw(mesh, meshname)
if object:
    # object is new, rename = meshname
    # object already exists, get it using the name assigned to it
    object = Blender.Object.Get(meshname)

(Jerri) #3

Thank you very much for your help. Works like a charm. Now I just need to know how to put a object to another layer with python. Tried object.Layer = 20 but nothing happens. Is this supposed to work? (btw: I am using blender 2.22).

(Schlops) #4

object.Layer is a bitfield (IIRC), so layer1=1, layer2=2, layer3=4, layer4=8 and so on