PDA

View Full Version : Python function defines


Aikiman
12-13-2011, 01:35 AM
I keep getting this error when executing the code below...

# NameError: global name 'create_meshCopy_JR' is not defined #

I dont understand why the function 'create_meshCopy_JR' is not being defined and is being referred as a global name. I tried changing the order of the functions inside the class by putting them above the doit() method but nadaaa.



import maya.cmds as mc
from functools import partial

class MeshCopyWindow:

def __init__(self):
self.name = 'w_meshCopy_JR'
self.title = 'Mesh Copy!'

#----------------------------------------------------------------------
# UI Wrapper
#----------------------------------------------------------------------

def create_meshCopyUI_JR ( self, arg=None ):

nFrame = mc.intFieldGrp("ifg_evryFrame_meshCopy_JR", q=True, v=1)
nMin = mc.intFieldGrp("ifg_minmaxVal_meshCopy_JR", q=True, v=1)
nMax = mc.intFieldGrp("ifg_minmaxVal_meshCopy_JR", q=True, v=2)

create_meshCopy_JR ( self, nFrame, nMin, nMax )


#----------------------------------------------------------------------
# Build Asset
#----------------------------------------------------------------------

def create_meshCopy_JR ( self, nFrame, nMin, nMax ):

print "You are inside create"

#mesh = mc.ls ( selection=True, dag=True, shapes=True )
#start = mc.playbackOptions ( query=True, min=True )
#end = mc.playbackOptions ( query=True, max=True )

#for i in range ( nMin, nMax+1, 1 ) :

#mc.currentTime ( i*nFrame )
#mc.select ( mesh[0], replace=True )
#mc.duplicate()
#mc.pickWalk ( direction="up" )
#mc.move ( i*20, 0, 0 )

def doit(self):

# check for existing window
if ( mc.window(self.name, q=1, exists=1) ) : mc.deleteUI ( self.name )
mc.window ( self.name, title=self.title, s=1 )

# UI components

mc.rowColumnLayout ( nc=1, cw=[1, 430] )
mc.intFieldGrp ( "ifg_evryFrame_meshCopy_JR", numberOfFields=1, l="Every Frame", cw3=[160, 40, 40], value1=1)
mc.intFieldGrp ( "ifg_minmaxVal_meshCopy_JR", numberOfFields=2, l="Timeline min/max", cw3=[160, 40, 40], value1=1, value2=24 )
mc.button ( l="create", c=partial(self.create_meshCopyUI_JR) )
mc.setParent ( '..' )

# set window width/height
mc.showWindow(self.name)
mc.window(self.name, e=1, wh=[420, 210])



meshCopy = MeshCopyWindow()
meshCopy.doit()

FraserRobertson
12-13-2011, 03:49 AM
# UI Wrapper
#----------------------------------------------------------------------

def create_meshCopyUI_JR ( self, arg=None ):

nFrame = mc.intFieldGrp("ifg_evryFrame_meshCopy_JR", q=True, v=1)
nMin = mc.intFieldGrp("ifg_minmaxVal_meshCopy_JR", q=True, v=1)
nMax = mc.intFieldGrp("ifg_minmaxVal_meshCopy_JR", q=True, v=2)

self.create_meshCopy_JR (nFrame, nMin, nMax )

This will fix your error, This is because the def "create_meshCopy_JR" is apart of the class so you have to refer to the class (self) when using it inside the class.

self.create_meshCopy_JR

This fix your problem?

Aikiman
12-13-2011, 04:16 AM
Ah thankyou, that makes sense. Instead I passed self inside the function parameter as an argument which is wrong.

CGTalk Moderation
12-13-2011, 04:16 AM
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.