I'm trying to write a basic rename tool that has specific parameters to choose from and also a name field to type the name of the object, the ui and everything work fine its on button press I get an error saying line 107: Object 'preFlightCheckUI|columnLayout13|frameLayout57|rowColumnLayout27|textField26' not found. #
Not sure what Im doing wrong here? Any help would be greatly appreciated thanks!
def build_asset_def(window, main_layout02):
assetDef = cmds.frameLayout(label='Define Asset Name', width= 300, height= 400, collapsable= True, parent= main_layout02)
baf = cmds.rowColumnLayout(numberOfColumns= 2, columnWidth= [(1,150), (2,150)], columnOffset= [(1, 'both', 5), (2, 'both', 5)], parent= assetDef)
#text labels
cmds.text(label='Define Project Name:', align= 'right', font= 'boldLabelFont', height= 30, parent= baf)
pre_proj_name = cmds.optionMenu()
prefix_menu_items01 = ['DRAGON', 'BATMAN']
for label_01 in prefix_menu_items01:
cmds.menuItem(pre_proj_name, label= label_01)
cmds.text(label='\tDepartment Name:\t', align= 'right', font= 'boldLabelFont', height= 30, parent= baf)
dep_name = cmds.optionMenu(label= 'Prefix:\t')
menu_items02 = ['MOD', 'LookDev','Texture', 'Proxy']
for label_02 in menu_items02:
cmds.menuItem(dep_name, label= label_02)
cmds.text(label='\tAsset Type:\t', align= 'right', font= 'boldLabelFont', height= 30, parent= baf)
asset_type = cmds.optionMenu()
menu_items03 = ['Char', 'Enviro','Prop']
for label_03 in menu_items03:
cmds.menuItem(asset_type, label= label_03)
cmds.text(label='\tAsset Name:\t', align= 'right', font= 'boldLabelFont', height= 30, parent= baf)
asset_name = cmds.textField(text= '')
cmds.text(label='\tMaterial ID:\t', align= 'right', font= 'boldLabelFont', height= 30, parent= baf)
suffix_material_type = cmds.optionMenu()
suffix_menu_material_id = ['Skin', 'Teeth','Gums', 'Dirt']
for label in suffix_menu_material_id:
cmds.menuItem(suffix_material_type, label= label)
applyBttn = cmds.button(label= 'Rename', height= 50, width= 300, command= partial(name_obj, pre_proj_name, dep_name, asset_type, asset_name, suffix_material_type))
def name_obj(prefix_element, suffix_element, depart_element, type_element, asset_name_element, *args):
prefix = cmds.optionMenu(prefix_element, query= True, value= True)
suffix = cmds.optionMenu(suffix_element, query=True, value= True)
department = cmds.optionMenu(depart_element, query=True, value= True)
assetType = cmds.optionMenu(type_element, query= True, value= True)
assetName = cmds.textField(asset_name_element, query= True, text= True)
name_template = '{prefix}_{department}_{type}_{new_name}_{suffix}_{index}'
for i, obj in enumerate(cmds.ls(selection= True)):
new_object_name = name_template.format(prefix=prefix, department= department, type= assetType, new_name= assetName, suffix= suffix, index= i)
cmds.rename(obj, new_object_name)
Your error comes from a inconsistent naming of your variables what leads to confusion. You try to query a text field with the variable asset_name_element
from the last position of your function, but you call the function with suffix_material_type
as last argument what is an option menu. I recommend to use the same variable names, then it becomes obvious what's wrong. Better, use a class with class variables, then it becomes heavier to exchange these values without intention.