Reassigning an Object's Mesh

(aayers) #1


I was wondering if it’s possible to reassign an object’s mesh from python script?
It’s easy to this in the Blender window.
select an object
go to edit mode
select a Mesh

I know that it’s possible to replace an objects raw mesh from script by doing the following.

Python> import Blender as B
Python> OBJ1 = B.Object.Get(“Object_1”)
Python> OBJ2 = B.Object.New(1)    #Makes a Mesh Object
Python> = “Object_2”
Python> H_mesh = B.Nmesh.GetRawFromObject(“Object_1”)
Python> B.Nmesh.PutRaw(H_mesh,”Object_2”)

But this only changes the geometry of Object_2’s mesh to that of Object_1’s. I want to link Object_2’s mesh to that of Object_1’s
(i.e. by looking in the OOPS window, I should see the following…
before: Object_1 and Object_2 are linked to their own mesh
after: Object_2 is linked with Object_1’s mesh)

Any insight would be appreciated.


(eeshlo) #2

If I understand you correctly, you only would have to append the vertices and faces of one mesh to the other mesh. But that still would be a single mesh, it wouldn’t show up as two different meshes in the OOPS window.

(aayers) #3

Here we go, a friend of mine told me how to do it. So I’ll share it with everyone now.
There is function in the Blender210 module called ‘connect()’ that can connect objects with meshes (and scenes with objects).

Just so ppl can see for themselves, type these lines in the python interpreter window and look at your OOPS window

import Blender
import Blender210

#Creating Mesh Objects
Blender.Object.New(1)  #Default name: "Mesh"
Blender.Object.New(1)  #Default name: "Mesh.001"

#Extracting useful info
OBJ = Blender210.getObject('Mesh')
MSH = Blender210.getMesh('Mesh.001')
#Voila, object 'Mesh' has the mesh of object 'Mesh.001'.

Compare this code with that provided in the original post, I think you’ll see what I was asking for.


(eeshlo) #4

I see, so what you want is multiple objects sharing a single mesh?
You can do that with the regular Blender module too:

object = Blender.Object.Get(object_name)
new_linked_object = object.clone()

This will link a new object, it will only work correctly if the object data is a mesh. Otherwise you get a new object with no data.

(aayers) #5

Yes that’s right!
I appolgize if I made my original message too complicated.

Thanks for your insight,