boomstick
boomstick

Reputation: 63

Selecting all vertices of a mesh to access each one separately

I need to select all vertices of a given object and be able to access each vertex separately to manipulate them later

A mesh is spawned with a random number of verts each time. That mesh is evaluated but I cannot select all verts and add them to a list

import maya.cmds as cmds
import functools
import random

sphereList = cmds.ls( 'mySphere*' )
cmds.selectPref(tso=True)
vertices = cmds.ls( sl=True)
if len( sphereList ) > 0:
    cmds.delete( sphereList)

result = cmds.polySphere ( r=50, sx=random.randrange(10, 100), sy=random.randrange(10,100), name='mySphere#' )
cmds.polyEvaluate('mySphere*',vertex=True  )
cmds.select()

In the end I need to be able to choose all the verts, store them and then be able to perform an action on every single one of them separately.

So my assumption is that I would need to somehow select them and then use a for-loop for the number of verts selected with an action described inside the for-loop

Upvotes: 3

Views: 5068

Answers (1)

DrWeeny
DrWeeny

Reputation: 2512

it depends of what type of action you want to do but to select them :

vtx = cmds.ls(sl=True, fl=True)

or if it is not a selection :

obj = 'pSphere1'
vtx = cmds.ls(obj+'.vtx[*]', fl=True)

Upvotes: 3

Related Questions