new mesh module - mesh.getVertGroupNames()

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

new mesh module - mesh.getVertGroupNames()

Post by kakapo »

if i use

mesh.getVertGroupNames()

i get the error message:

"AttributeError: mesh must be linked to an object first"

what does this mean?



since there is no getvertexinfluences method in the new mesh module (and this function seems to be broken in nmesh) i try to do this:

Code: Select all

    # build vertex influences dictionary
    vertexinfluences = {}
    for i in range(len(mesh.verts)):
        vertexinfluences[i] = []
    for groupname in mesh.getVertGroupNames(): # doesn't work with mesh only with nmesh?
        for vertex in mesh.getVertsFromGroup(groupname, 1):
            index, weight = vertex[0], vertex[1]
            vertexinfluences[index].append((groupname, weight))

Ben
Posts: 9
Joined: Wed Oct 23, 2002 8:32 pm

Post by Ben »

How did you get that mesh in your script?

kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

Post by kakapo »

mesh = Mesh.New()
mesh.getFromObject(obj.name, 1)

Ben
Posts: 9
Joined: Wed Oct 23, 2002 8:32 pm

Post by Ben »

so it's not linked to any object.You have to link it with an object first:

Code: Select all

object.link(mesh)
and to link the object to the scene if it's a new one:

Code: Select all

scene = Blender.Scene.getCurrent()
scene.link(object)

kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

Post by kakapo »

but i get it from an object of the scene with getfromobject so shouldn't it already be linked?

Ben
Posts: 9
Joined: Wed Oct 23, 2002 8:32 pm

Post by Ben »

with "mesh.getFromObject(obj.name, 1)" I think you get only
the mesh data from the object, not the object.

kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

Post by kakapo »

but if i link it like in your example wouldn't the object have links to two meshes then? couldn't that cause problems?

Ben
Posts: 9
Joined: Wed Oct 23, 2002 8:32 pm

Post by Ben »

sorry,if you need the mesh data of that object,
isn't better to get the mesh:

Code: Select all

mesh = obj.getData()
instead of creating a new mesh.This way it's the mesh
linked to the object.

kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

Post by kakapo »

thanks, i will try that. in the docs i saw that obj.getData() can also return a mesh instead of a nmesh now.

Post Reply