Syntax Error on Function Call....?

def process_all_textures(**kwargs):
pre = kwargs.setdefault(‘prefix’, ‘my_’)
texture = kwargs.setdefault(‘texture_node’)
return cmds.rename(texture,’%s%s’% (pre, texture)

texture = process_all_textures(texture_node = texture)
print(texture)

missing a final end parenthesis

Thank you, you were right about the parenthesis.
Charcoal now says, error Line5: texture is not defined:

def process_all_textures( **kwargs):
pre = kwargs.setdefault(‘prefix’, ‘my_’)
texture = kwargs.setdefault(‘texture_node’)
return cmds.rename(texture,’%s%s’% (pre, texture))
texture = process_all_textures(texture_node = texture)
print(texture)

It would be helpful if you post code with proper formatting

def process_all_textures( **kwargs):

   pre = kwargs.setdefault(‘prefix’, ‘my_’)
   texture = kwargs.setdefault(‘texture_node’)
   return cmds.rename(texture,’%s%s’% (pre, texture))

texture = process_all_textures(texture_node = texture)

print(texture)

This makes it easier to notice that when you run process_all_textures on line five, you use [texture] as input, but it has not been defined in this example.

Yes. I am sorry. I hit send prematurely without formatting.
I will be more diligent next time. And thanks for the response.
This is a code snipet out of the book ‘Maya Python for Games and Film’
I’m just following along with the exercises.
So in other words, I need to have an actual texture loaded into maya
named ‘texture’ ?

yes you likely need a file node present, then give that file node path as the argument.
btw file node = node that samples a texture…strange naming in my opinion.

So if the file node is called my_texture, the input will be “|my_texture”
(can’t confirm because I currently don’t have a maya license)

This is a code snipet out of the book ‘Maya Python for Games and Film’

I thought it looked familiar

The code which defines the texture variable is on page 67, section 5:

import maya.cmds
texture  = maya.cmds.shadingNode('file',asTexture=True)  # << here
process_all_textures(texture)

It creates a Maya shadingNode and assigns its name to the variable texture

The snippet you cite is from page 73 section 19, and it assumes that texture still exists as a defined variable which would only happen if you were doing these exercises one after the other in a single Maya session.

you probably need to combine sections:

import maya.cmds 

def process_all_textures( **kwargs):

   pre = kwargs.setdefault('prefix', 'my_')
   texture = kwargs.setdefault('texture_node')
   return cmds.rename(texture,'%s%s' % (pre, texture))

texture  = maya.cmds.shadingNode('file',asTexture=True)  # define 'texture'
texture = process_all_textures(texture_node = texture) # process 'texture'
print(texture)

@ricgreen1 our code example uses non-ascii ‘curly quotes’ , watch out for that.

1 Like

Oh, that is what I thought, Very good. Its working.
thanks again !