It has some issues... I thought I'd post up the code and see if anyone has ideas... I'm finding it difficult to connect the floatFields to the value of the functions... and the selected vert mode doesn't work... Here it is.
It's mostly an exercise in scripting
#Import Necessary Modules
import maya.cmds as mc
import random
# Shape Copy Function
def copyShape(*args):
# Having Trouble Multiplying the Values in the list by the floatField,
# Returns Error: "TypeError: can't multiply sequence by non-int of type 'float'"
# Amount values are Disabled in Functions
#amountCopyShape = mc.floatField( 'AmountC', query = True, value = True)
sel = mc.ls( sl = True )
selObj = mc.listRelatives( mc.listRelatives( parent = True ), parent = True )
if mc.objectType( mc.listRelatives( sel[0] ) ) == 'mesh':
if len(sel) == 2:
sizeS = mc.ls( sel[0] + '.vtx[*]', flatten = True )
sizeT = mc.ls( sel[1] + '.vtx[*]', flatten = True )
# Test for Compatable Object Types
if mc.objectType( mc.listRelatives( sel[0] ) ) != mc.objectType( mc.listRelatives( sel[1] ) ):
print "Error: Selected Objects are Not of Compatable, Please Select 2 Objects of the Same Type."
# Test for Compatable Vert Counts
elif len( sizeS ) != len( sizeT ):
print "Error: Selected Objects have different Point Counts, Please Select Objects with Equal Counts."
# Check if "selected" or "all" verts
elif mc.radioButtonGrp( 'VertMode', query = True, en2 = True): # Check for All Verts Radio Button
# Copy the Shape
for v in mc.ls( sel[0] + '.vtx[*]', flatten = True ):
pos = mc.xform( v, query = True, objectSpace = True, translation = True )
mc.xform( v.replace( sel[0], sel[1] ), objectSpace = True, translation = pos)#*amountCopyShape )
elif mc.radioButtonGrp( 'VertMode', query = True, en1 = True ): #Test for Selected Verts Mode
selV = mc.ls( sl = True )
T = len( selV )
selObj = mc.listRelatives( mc.listRelatives( parent = True ), parent = True )
for v in range( len(selV) ):
posv = mc.xform( v, query = True, objectSpace = True, translation = True )
mc.xform( v.replace( selObj[0], selV[-1] ), objectSpace = True, translation = posv)#*amountCopyShape )
elif mc.objectType( mc.listRelatives( sel[0] ) ) == 'subdiv':
if len(sel) == 2:
sizeS = mc.ls( sel[0] + '.smp[*]', flatten = True )
sizeT = mc.ls( sel[1] + '.smp[*]', flatten = True )
# Test for Compatable Object Types
if mc.objectType( mc.listRelatives( sel[0] ) ) != mc.objectType( mc.listRelatives( sel[1] ) ):
print "Error: Selected Objects are Not of Compatable, Please Select 2 Objects of the Same Type."
# Test for Compatable Vert Counts
elif len( sizeS ) != len( sizeT ):
print "Error: Selected Objects have different Point Counts, Please Select Objects with Equal Counts."
# Check if "selected" or "all" verts
elif mc.radioButtonGrp( 'VertMode', query = True, en2 = True): # Check for All Verts Radio Button
# Copy the Shape
for v in mc.ls( sel[0] + '.smp[*]', flatten = True ):
pos = mc.xform( v, query = True, objectSpace = True, translation = True )
mc.xform( v.replace( sel[0], sel[1] ), objectSpace = True, translation = pos)#*amountCopyShape )
elif mc.radioButtonGrp( 'VertMode', query = True, en1 = True ): #Test for Selected Verts Mode
selV = mc.ls( sl = True )
T = len( selV )
selObj = mc.listRelatives( mc.listRelatives( parent = True ), parent = True )
for v in range( len(selV) ):
posv = mc.xform( v, query = True, objectSpace = True, translation = True )
mc.xform( v.replace( selObj[0], selV[-1] ), objectSpace = True, translation = posv)#*amountCopyShape )
elif mc.objectType( mc.listRelatives( sel[0] ) ) == 'nurbsSurface':
if len(sel) == 2:
sizeS = mc.ls( sel[0] + '.cv[*]', flatten = True )
sizeT = mc.ls( sel[1] + '.cv[*]', flatten = True )
# Test for Compatable Object Types
if mc.objectType( mc.listRelatives( sel[0] ) ) != mc.objectType( mc.listRelatives( sel[1] ) ):
print "Error: Selected Objects are Not of Compatable, Please Select 2 Objects of the Same Type."
# Test for Compatable Vert Counts
elif len( sizeS ) != len( sizeT ):
print "Error: Selected Objects have different Point Counts, Please Select Objects with Equal Counts."
# Check if "selected" or "all" verts
elif mc.radioButtonGrp( 'VertMode', query = True, en2 = True): # Check for All Verts Radio Button
# Copy the Shape
for v in mc.ls( sel[0] + '.cv[*]', flatten = True ):
pos = mc.xform( v, query = True, objectSpace = True, translation = True )
mc.xform( v.replace( sel[0], sel[1] ), objectSpace = True, translation = pos)#*amountCopyShape )
elif mc.radioButtonGrp( 'VertMode', query = True, en1 = True ): #Test for Selected Verts Mode
selV = mc.ls( sl = True )
T = len( selV )
selObj = mc.listRelatives( mc.listRelatives( parent = True ), parent = True )
for v in range( len(selV) ):
posv = mc.xform( v, query = True, objectSpace = True, translation = True )
mc.xform( v.replace( selObj[0], selV[-1] ), objectSpace = True, translation = posv)#*amountCopyShape )
else:
print "Error: No Valid Selections"
# Randomize Shape Function
def randomizeShape(*args):
# Having Trouble Multiplying the Values in the list by the floatField,
# Returns Error: "TypeError: can't multiply sequence by non-int of type 'float'"
# Amount values are Disabled in Functions
#amountRandomize = mc.floatField( 'rFloat', query=True, value=True )
sel = mc.ls( sl = True )
if mc.objectType( mc.listRelatives( sel[0] ) ) == 'mesh':
vertList = mc.ls( sel[0] + '.vtx[*]', flatten = True )
# Randomize the Shape
for v in vertList:
x = random.uniform( -1, 1 )#*amountRandomize
y = random.uniform( -1, 1 )#*amountRandomize
z = random.uniform( -1, 1 )#*amountRandomize
mc.xform( v, objectSpace = True, translation = (x, y, z) )
elif mc.objectType( mc.listRelatives( sel[0] ) ) == 'subdiv':
vertList = mc.ls( sel[0] + '.smp[*]', flatten = True )
# Randomize the Shape
for v in vertList:
x = random.uniform( -1, 1 )#*amountRandomize
y = random.uniform( -1, 1 )#*amountRandomize
z = random.uniform( -1, 1 )#*amountRandomize
mc.xform( v, objectSpace = True, translation = (x, y, z) )
elif mc.objectType( mc.listRelatives( sel[0] ) ) == 'nurbsSurface':
vertList = mc.ls( sel[0] + '.cv[*]', flatten = True )
# Randomize the Shape
for v in vertList:
x = random.uniform( -1, 1 )#*amountRandomize
y = random.uniform( -1, 1 )#*amountRandomize
z = random.uniform( -1, 1 )#*amountRandomize
mc.xform( v, objectSpace = True, translation = (x, y, z) )
else:
print "Error: No Valid Selections"
# Function to Call UI
def toolUI():
if mc.window( 'Vert Tools', exists = True ):
mc.deleteUI( 'Vert Tools', window = True )
window = mc.window( 'Vert Tools' )
mc.columnLayout( 'baseColumn', adjustableColumn = False, height=180, width=360 )
mc.frameLayout( 'Copy Shape', label='Copy Shape', parent='baseColumn', collapsable=True )
mc.rowLayout( numberOfColumns=4 )
mc.button( label='Copy Shape', command=copyShape )
mc.radioButtonGrp( 'VertMode', numberOfRadioButtons=2, labelArray2=['Selected', 'All'] )
mc.text( 'Amount' )
mc.floatField( 'AmountC', minValue=-1, maxValue=1, value=1, precision=2, step=.01 )
mc.setParent( '..' )
mc.setParent( '..' )
mc.frameLayout( 'Randomize', label='Randomize Shape', parent='baseColumn', collapsable=True )
mc.columnLayout( adjustableColumn=False, numberOfChildren=3 )
mc.button( label='Randomize', command=randomizeShape )
mc.text( 'Amount' )
mc.floatField( 'rFloat', minValue=-1, maxValue=2, value=1, precision=2, step=.01 )
mc.setParent( '..' )
mc.setParent( '..' )
mc.showWindow( window )