I couldn't really test it, since I've never used Yeti. Therefore I don't know how to set up a scene that I can test this in.
But I'm assuming the Yeti part of your code works and from the looks of your script you just need the dropdown menu to do some string formatting.
If you just need to get the value in the dropdown menu,you can do it like this, no additional readout function needed:
import maya.cmds as cmds
import maya.mel as mel
import os
import shutil
def get_texture_node(graph_node):
mel_cmd = 'pgYetiGraph -listNodes -type "texture" %s' % str(graph_node)
texture_nodes = mel.eval(mel_cmd)
return texture_nodes
def get_texture_path(texture, graph):
mel_cmd = 'pgYetiGraph -node "%s" -param "file_name" -getParamValue %s' % (str(texture), str(graph))
path = mel.eval(mel_cmd)
return path
def set_texture_path(path, node, graph):
mel_cmd = '''pgYetiGraph -node "{node_name}" -param "file_name" -setParamValueString "{path}" "{graph}"'''.format(node_name=str(node), path=str(path), graph=str(graph))
print(mel.eval(mel_cmd))
#################################################
def set_yeti_texture_image():
all_yeti_nodes = cmds.ls(sl=1, s=1, dag=1)
image_format = cmds.optionMenu(imgFormat, query=True, value=True)
for node_name in all_yeti_nodes:
tnodes = get_texture_node(node_name)
if tnodes:
for node in tnodes:
texs = get_texture_path(node, node_name)
tex_path = texs.split('.')[0]
set_texture_path(tex_path + '.' + image_format, node, node_name)
print ("Set scucessful: %s" % (tex_path + image_format))
############################################
if cmds.window("YetiTool", exists=True):
cmds.deleteUI("YetiTool")
cmds.window("YetiTool", t="YetiTool",
w=460, h=600, sizeable=True, mnb=True, mxb=False)
cmds.scrollLayout('scrollLayout')
cmds.columnLayout(adj=True)
##############################################
cmds.rowLayout(nc=4)
imgFormat = cmds.optionMenu("image_Format", w = 140, label = "Select format")
cmds.menuItem( label='png' )
cmds.menuItem( label='exr' )
cmds.menuItem( label='tif' )
cmds.menuItem( label='iff' )
cmds.menuItem( label='<UDIM>.png' )
cmds.menuItem( label='<UDIM>.tif' )
cmds.menuItem( label='<UDIM>.exr' )
cmds.menuItem( label='<UDIM>.iff' )
cmds.button(l='Replacement format', c="set_yeti_texture_image()", bgc=(0.2, 0.4, 0.2), width=100)
cmds.showWindow("YetiTool")
In your code, you for some reason referenced a textfield in your function "ObjectCreation" but you did not have any textfields in your UI. Also the way the textfield command works in edit mode is:
cmds.textField("Name of Textfield", tx = "Text you want to insert", e = True)
So your script was looking for the textfield with the name "png" (or whatever imageformat your dropdown menu had selected) instead of inserting the imageformat into a textfield. So if for some reason while running you also wanted to store your imageformat parameter in a textfield (I don't quite see the point since the dropdown Menu already is a clear indicator)
You would have to first create a textfield in your UI and then store the value to it correctly.
Something like this:
import maya.cmds as cmds
import maya.mel as mel
import os
import shutil
def get_texture_node(graph_node):
mel_cmd = 'pgYetiGraph -listNodes -type "texture" %s' % str(graph_node)
texture_nodes = mel.eval(mel_cmd)
return texture_nodes
def get_texture_path(texture, graph):
mel_cmd = 'pgYetiGraph -node "%s" -param "file_name" -getParamValue %s' % (str(texture), str(graph))
path = mel.eval(mel_cmd)
return path
def set_texture_path(path, node, graph):
mel_cmd = '''pgYetiGraph -node "{node_name}" -param "file_name" -setParamValueString "{path}" "{graph}"'''.format(node_name=str(node), path=str(path), graph=str(graph))
print(mel.eval(mel_cmd))
#################################################
def ObjectCreation():
currentValue = cmds.optionMenu("image_Format", query=True, value=True)
cmds.textField(txtField, tx = currentValue, e=True)
return currentValue
def set_yeti_texture_image():
all_yeti_nodes = cmds.ls(sl=1, s=1, dag=1)
image_format = ObjectCreation()
for node_name in all_yeti_nodes:
tnodes = get_texture_node(node_name)
if tnodes:
for node in tnodes:
texs = get_texture_path(node, node_name)
tex_path = texs.split('.')[0]
set_texture_path(tex_path + '.' + image_format, node, node_name)
print ("Set scucessful: %s" % (tex_path + image_format))
############################################
if cmds.window("YetiTool", exists=True):
cmds.deleteUI("YetiTool")
cmds.window("YetiTool", t="YetiTool",
w=460, h=600, sizeable=True, mnb=True, mxb=False)
cmds.scrollLayout('scrollLayout')
cmds.columnLayout(adj=True)
##############################################
cmds.rowLayout(nc=4)
cmds.optionMenu("image_Format", w = 140, label = "Select format")
cmds.menuItem( label='png' )
cmds.menuItem( label='exr' )
cmds.menuItem( label='tif' )
cmds.menuItem( label='iff' )
cmds.menuItem( label='<UDIM>.png' )
cmds.menuItem( label='<UDIM>.tif' )
cmds.menuItem( label='<UDIM>.exr' )
cmds.menuItem( label='<UDIM>.iff' )
cmds.button(l='Replacement format', c="set_yeti_texture_image()", bgc=(0.2, 0.4, 0.2), width=100)
txtField = cmds.textField()
cmds.showWindow("YetiTool")
I hope it helps!