Featured post

new redirect for blender.org bpy docs.

http://www.blender.org/api/blender_python_api_current/ As of 10/11 november 2015 we can now link to the current api docs and not be worr...

Showing posts with label indices. Show all posts
Showing posts with label indices. Show all posts

March 26, 2013

Painting Vertex Color Map using selected Faces

This script is obsolete, shift+K will fill all selected faces/ verts with the brush colour.

selected faces

During a recent conversation with Jimmy Gunawan of blendersushi I remembered that I wanted to write a script that lets me paint the vertex color map as a function of which faces are selected. Here's a version of this script that runs in vertex paint mode with face masking mode on. i'll leave refactoring this snippet to you.

I've limited some freedom by forcing the user to be in 'VERTEX_PAINT' and Face Masking Active, but it's safer this way (even after some bugfixing by campbell) -- as it is still easy to crash blender in obscure ways otherwise.

May 14, 2011

Blender Python Printing Vertex Coordinates of selected Mesh

Below you will find the necessary code to get vertex information for yourself in a few easy steps. Running Blender in debug mode has index visualizer built in to allow you to see index information in realtime.
import bpy
for item in bpy.data.objects:
    
    print(item.name)
    if item.type == 'MESH':
        for vertex in item.data.vertices:
            print(vertex.co)
or
import bpy
for item in bpy.data.objects:
    
    print(item.name)
    if item.type == 'MESH':
        vert_list = [vertex.co for vertex in item.data.vertices]
        for vert in vert_list:
            print(vert)
we can go even further.. print faces(polygons), vertices, indices, face normals
# blender 2.6x
import bpy

current_obj = bpy.context.active_object

print("="*40) # printing marker
for face in current_obj.data.polygons:
    verts_in_face = face.vertices[:]
    print("face index", face.index)
    print("normal", face.normal)
    for vert in verts_in_face:
        print("vert", vert, " vert co", current_obj.data.vertices[vert].co)
if you need world coordinates, blenderscripting -- matrixworld will be a good place to find information. Compare the following snippet with the previous one.