# randomly moving an objects verticies with python

 10 October 2012 blurgh curve fiddler   portfolio Toby Winder Animator London, GB randomly moving an objects verticies with python im trying to write a script in python that will select all the verts and randomly move them, so that I can add some randomness to the topology of objects Ive managed to write it in mel, so im trying to convert it - for practice more than anything else Ml: \$mySelection = `ls- sl`; \$myVerts = `getVerts`; for (\$vert in \$myVerts) { float \$min = -0.04; float \$max = 0.04; float \$randNumX = rand( \$min , \$max ); float \$randNumY = rand( \$min , \$max ); float \$randNumZ = rand( \$min , \$max ); select -r \$vert ; move -r \$randNumX \$randNumY \$randNumZ ; } select -r \$mySelection; Heres my attempt in python so far: import random import maya.cmds as mc minRand = -30 maxRand = 30 randMoveX = random.uniform ( minRand , maxRand ) randMoveY = random.uniform ( minRand , maxRand ) randMoveZ = random.uniform ( minRand , maxRand ) selectedMesh = mc.ls(selection=True, dag=True, type='mesh', long=True) for mesh in selectedMesh: vtxCount = mc.polyEvaluate(v=True) mc.select(cl=True) mc.select(mesh+'.vtx[0:'+str(vtxCount)+']', add=True) mc.move( randMoveX, randMoveY, randMoveZ, relative=True ) Im struggling making the verts actually move, I can get them selected. Is there a command similar to getVerts for python? thanks! B __________________ Walk without rhythm and you wont attract the worm... =>Reel & Portfolio<= Linkedin share quote
 10 October 2012 blurgh curve fiddler   portfolio Toby Winder Animator London, GB woops lost some formatting there! __________________ Walk without rhythm and you wont attract the worm... =>Reel & Portfolio<= Linkedin share quote
 10 October 2012 NaughtyNathan HighEnd3D deserter   Naughty Nathan Technical Artist Sony SCEE Liverpool Manchester, United Kingdom you shouldn't rely on selection when scripting, it's not explicit enough and is a completely unnecessary overhead. `getVerts` is a MEL script and not a very good way to actually return selected verts as it performs conversion and selection (both usually undesirable in any situation where you simply want to "get" the selected verts) to get selected verts (or any other component type) use the filterExpand command. When you want to perform an operation on something, don't select it first then perform an action - perform the action ON the item: ``````selVerts = mc.filterExpand(sm=31) mc.polyMoveVertex(selVerts, t=(randMoveX, randMoveY, randMoveZ), random=1)`````` I've used polyMoveVertex instead of plain move because then you get it as a history state, don't need to iterate over vertices and it also has a random flag built in so you may be able to just use that instead of using random numbers... share quote
 10 October 2012 blurgh curve fiddler   portfolio Toby Winder Animator London, GB Hey Nathan, Thanks for the reply, Does the polyMoveVertex command move all the verts in the selVerts list the same?, I need the script to move each vert separately and randomly. When I try it using the lines you wrote, it just moved my whole object (by moving the verts) To do this would I need to iterate through my string of verts and run the command on each one? thanks! __________________ Walk without rhythm and you wont attract the worm... =>Reel & Portfolio<= Linkedin share quote
 10 October 2012 CGTalk Moderation Expert Thread automatically closed This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum. __________________ CGTalk Policy/Legalities Note that as CGTalk Members, you agree to the terms and conditions of using this website. share quote

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off CGSociety Society of Digital Artists www.cgsociety.org Powered by vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.