Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# python
#
# Author: Jeff LeRoy (extol) www.leroyfx.com
#
# Ex_PrintPosOfSelectedVerts.py v1.0
#
#------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------
# This is a exercise I did to understand working on a mesh when multiple mesh layers are selected.
# If you have vertices selected it will print the xyz position of every vertex. If you have multiple
# mesh layers selected it will still work and print out the info for each mesh layer.
#------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------
#
sel_meshes = lx.eval ('query sceneservice selection ? mesh') #how many mesh items selected
#
#------------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------------
sel_meshesType = type(sel_meshes) #check for the type of sel_meshes (string or tuple ?)
def printVertPos ():
layerName = lx.eval ('query layerservice layer.name ?') #get the name of the layer
sel_layerVertCount = lx.eval ('query layerservice verts ? selected')#get the list of INDIVIDUAL verts selected
num_verts = lx.eval ('query layerservice vert.N ?') #how many TOTAL verts are selected
lx.out ("on layer ",layerName) #print the layer name in event log
lx.out ("selected verts :",sel_layerVertCount) #print a list of every vertex selected
if num_verts > 0: #make sure something is selected
if num_verts > 1: #if more than one vert selected
for v in sel_layerVertCount:
vPosition = lx.eval ('query layerservice vert.wpos ? %s,' % v)
lx.out ("Vertex ",v)
lx.out ("X ", vPosition[0])
lx.out ("Y ", vPosition[1])
lx.out ("Z ", vPosition[2])
else: # if only one vert selected
lx.out ("Vertex ",sel_layerVertCount)
vPosition = lx.eval ('query layerservice vert.wpos ? %s,' % sel_layerVertCount)
lx.out ("X ", vPosition[0])
lx.out ("Y ", vPosition[1])
lx.out ("Z ", vPosition[2])
if sel_meshesType is str: #if string (one mesh selected)
printVertPos ()
elif sel_meshesType is tuple: #if tuple (multiple meshes selcted) so we need to loop through them
for sel_mesh in sel_meshes:
sel_MeshID = lx.eval ('query layerservice layer.index ? %s' % sel_mesh) #get/select current mesh layer to work on
printVertPos ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment