i'm using the script at the bottom to create some nurbsplanes with clusters to deform them.
i couldn't find a python equivalent to SearchReplaceNames so i decided to pass that command to mel. the only way i could figure how to pass the variable to mel involves using python to run mel to run python, which doesn't strike me as efficient.
but if i cut and paste this code into the script editor, it works fine.
however, if i try to import it i get this error
CODE
import looptest
# Error: name 'wvs' is not defined
# Traceback (most recent call last):
# File "", line 1, in ?
# NameError: name 'wvs' is not defined #
# Error: Error occurred during execution of MEL script
# Traceback (most recent call last):
# File "", line 1, in ?
# File "C:\Documents and Settings\Administrator\My Documents\maya\8.5\pyscripts\looptest.py", line 36, in ?
# maya.mel.eval ( "int $wvs = python \"wvs\"")
# RuntimeError: Error occurred during execution of MEL script #
if i run it from the script editor, then import it in the same maya session, i don't get that error, but the variable doesn't get updated for mel so it renames everything wrong. so the hitch is almost definitely in passing the variable from python to mel.
anyone know what to do so i can import this?
CODE
import maya.cmds as cmds
#loop to create 4 wave planes
for wvs in range ( 1 , 5 ) :
cmds.nurbsPlane( n='wv01_ZZ_XX', p=[ 0,0,0 ], ax=[ 0,1,0 ], w=1, lr=1, d=3, u=400, v=1, ch=1 )
cmds.setAttr ( 'wv01_ZZ_XX.scaleX', 200 )
cmds.setAttr ( 'wv01_ZZ_XX.scaleZ', 40 )
cmds.setAttr ( 'wv01_ZZ_XX.rotateX', 90 )
cmds.makeIdentity( 'wv01_ZZ_XX', apply=True, t=1, r=1, s=1, n=0 )
#loop to create clusters for each plane
for pnts in range ( 0,16 ):
cmds.select ( "wv01_ZZ_XX.cv[" + str(pnts+2) + "][3]", "wv01_ZZ_XX.cv[" + str(pnts+18) + "][3]",
"wv01_ZZ_XX.cv[" + str(pnts+34) + "][3]", "wv01_ZZ_XX.cv[" + str(pnts+50) + "][3]", "wv01_ZZ_XX.cv[" + str(pnts+66) + "][3]",
"wv01_ZZ_XX.cv[" + str(pnts+82) + "][3]", "wv01_ZZ_XX.cv[" + str(pnts+98) + "][3]", "wv01_ZZ_XX.cv[" + str(pnts+114) + "][3]",
"wv01_ZZ_XX.cv[" + str(pnts+130) + "][3]", "wv01_ZZ_XX.cv[" + str(pnts+146) + "][3]", "wv01_ZZ_XX.cv[" + str(pnts+162) + "][3]",
"wv01_ZZ_XX.cv[" + str(pnts+178) + "][3]", "wv01_ZZ_XX.cv[" + str(pnts+194) + "][3]", "wv01_ZZ_XX.cv[" + str(pnts+210) + "][3]",
"wv01_ZZ_XX.cv[" + str(pnts+226) + "][3]", "wv01_ZZ_XX.cv[" + str(pnts+242) + "][3]", "wv01_ZZ_XX.cv[" + str(pnts+258) + "][3]",
"wv01_ZZ_XX.cv[" + str(pnts+274) + "][3]", "wv01_ZZ_XX.cv[" + str(pnts+290) + "][3]", "wv01_ZZ_XX.cv[" + str(pnts+306) + "][3]",
"wv01_ZZ_XX.cv[" + str(pnts+322) + "][3]", "wv01_ZZ_XX.cv[" + str(pnts+338) + "][3]", "wv01_ZZ_XX.cv[" + str(pnts+354) + "][3]",
"wv01_ZZ_XX.cv[" + str(pnts+370) + "][3]", "wv01_ZZ_XX.cv[" + str(pnts+386) + "][3]",r=True )
cmds.cluster ( n="wv01_ZZ_XXcls" + str(pnts), en=1 )
cmds.select ( 'wv01_ZZ_XX.cv[0:402][0:2]', 'wv01_ZZ_XX.cv[0:1][3]', 'wv01_ZZ_XX.cv[402][3]', r=True)
cmds.cluster ( n='wv01_ZZ_XXclsBase', en=1)
cmds.select ( "wv01_ZZ_XXcls*Handle", r=True )
cmds.group ( n='wv01_ZZ_XXclsCRV' )
cmds.group ( 'wv01_ZZ_XXclsCRV', n='wv01_ZZ_XXclsGRP' )
cmds.setAttr ('wv01_ZZ_XXclsGRP.translateZ', ((wvs -1) * 2) )
cmds.select( clear=True )
#pass variable to mel and replace names
import maya.mel
maya.mel.eval ( "int $wvs = python \"wvs\";" )
maya.mel.eval ( "searchReplaceNames \"XX\" (\"0\" + $wvs) \"all\";" )