Я не уверен, что не работает, я улучшил ваш код с комментариями. Я надеюсь, что это поможет, это работает здесь:
import maya.cmds as cmds
import pymel.core as pmc
# if you dont know classes, you can create a dict to store all main controls
UI_DIC = {}
# for function used in ui, you need *args because maya will try to parse a default True
# argument as last argument
def picker(*args):
sel = cmds.ls(sl=True)[0]
cmds.textField(UI_DIC['textField00'], edit=True, text=sel )
# use lower case for functions, you can use camel casing like maya : uvTilesChange
# but keep the first letter lower case as uppercase for the first is used for Class
def uv_tile_change(*args):
# we parse fields with the value captured in the dictionnary
textField_obj_name = cmds.textField(UI_DIC['textField00'], query=True, text=True )
textField_obj = cmds.textField(UI_DIC['textField01'], query=True, text=True )
textField_obj2 = cmds.textField(UI_DIC['textField02'], query=True, text=True )
# if there is nothing in the ui, dont execute anything
if not textField_obj_name:
return
# we are using few funcitons to find the place2dTexture of an object
shape_mesh = cmds.ls(textField_obj_name, dag=True, type='shape', ni=True)
if not shape_mesh:
# if the object doesnt exists, stop here
return
# we look for the shading engine of the object
hist = cmds.listHistory(shape_mesh, future=True)
sgs = cmds.ls(hist, type="shadingEngine")
# from the sgs, we look for the place2dTexture
place2dTextures = [i for i in cmds.listHistory(sgs) if cmds.ls(i, type='place2dTexture')]
# instead of a while, just use a python for loop
for p2t in place2dTextures:
cmds.setAttr(p2t + ".repeatU", float(textField_obj))
cmds.setAttr(p2t + ".repeatV", float(textField_obj2))
def make_window():
width = 180
height = 150
if (pmc.window('flattenVertwindow', exists=True)):
pmc.deleteUI('flattenVertwindow')
# sizeable works for me
pmc.window('flattenVertwindow', title="TEST",widthHeight=(width,height), sizeable=False)
main_layout = pmc.columnLayout(adjustableColumn=True)
# use the flag parent, it is more clear
pmc.text("Choisir nom de l'objet", parent=main_layout)
# choose either cmds or pymel, do not use both
pmc.separator(h=10, parent=main_layout)
# here is an example on how parent flag is useful
# we create a sub layout and parent it to the main one
# we parent all the controls to the sub layout
picker_layout = pmc.rowLayout(nc=3, parent=main_layout, width=width, ad1=True)
# we capture the name of the control on creation inside the dict
UI_DIC['textField00'] = pmc.textField(parent=picker_layout, w=width)
# take the habit to not put string in the command flag
pmc.button(label='<', command= picker, parent=picker_layout)
pmc.separator(h=10, parent=main_layout)
pmc.text("Taille des Tiles", parent=main_layout)
pmc.separator(h=10)
UI_DIC['textField01'] = pmc.textField(parent=main_layout)
UI_DIC['textField02'] = pmc.textField(parent=main_layout)
red= pmc.button(label='Change UV TILE ', command= uv_tile_change, parent=main_layout)
pmc.showWindow('flattenVertwindow')
make_window()