enter image description here

i wanna calculate the valence for each vertex of this cube.


Here is a script to collect the valence of all vertices of an object:

import bpy

def CalcValences( verts, edges ):
    #Initialize the valences with all vertices indexes
    result = {v.index: 0 for v in verts}
    #Add the valences for the vertices of each edge
    for e in edges:
        result[e.vertices[0]] += 1
        result[e.vertices[1]] += 1
    return result

# Get the selected object
obj = bpy.context.object

if ( obj ): # If it exists
    valences = CalcValences( obj.data.vertices, obj.data.edges )
    print( valences )

obj.data.vertices corresponds to the vertices, which each as an index as identifier.

obj.data.edges get the... edges and each edge stores a vertex index pair in vertices[0] and [1].

Concerning min, max and average, this is Python aspect, not Blender...

If more information is needed, please ask in comments.

| improve this answer | |

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.