bpy: Getting selected polygon vertices

I've been Maya artist for quite a long time and started to learn how to get infos I need for the i3d tools in Blender.
I will try to leave a note for those Maya script artists learning python scripting in Blender 2.8x. ;)

def gettingSelectedPolyVertsInMayaFormat():
import bpy;
selectedVerts= [];
mode = bpy.context.active_object.mode; # Getting current mode
bpy.ops.object.mode_set(mode='OBJECT'); # Setting object mode to get selected objects
objs= bpy.context.selected_objects # Current selected objects
for obj in objs: # Finding selected vertices of the selected 
if obj.type=="MESH": # if the object is polygon..
  verts= obj.data.vertices; # get all poly verts of the poly object
num= len(verts); 
for i in range(0,num):
  if verts[i].select: # if the vtx is selected..
  mayaVTX= obj.name+".vtx["+str(i)+"]"; # Getting selected vtx in Maya format
selectedVerts.append(mayaVTX);
  bpy.ops.object.mode_set(mode=mode); # Setting back the mode 
  return( selectedVerts );

Comments

Popular posts from this blog

HIK: Getting current character and current source.