函数中有多个参数。通过函数传递信息<函数save#u snapshots at“###”>not found'

2024-10-04 09:22:29 发布

您现在位置:Python中文网/ 问答频道 /正文

# Error: RuntimeError: file <maya console> line 13: Object '<function save_snapshots at 0x000001757D101EB8>' not found. #

我正在编写一个脚本来创建uv快照。目前,我一直在获取“save\u snapshots”来获取“uv\u snapshots\u res”应该给出的整数

在我的UI中,“save”按钮使用的是partial,我不完全理解它是如何工作的。如果我按命令的顺序将save\u快照移到“texSizeControl”后面,它就不会运行了(我想?)

希望对解释使用函数时传递参数的工作原理,以及“部分”操作的顺序有点帮助。。。 唯一的原因,我到目前为止,是因为这个网站和寻找其他领域的例子。整个单选按钮的事情是一个完全的挑战,我不知道我是否完全正确工作:/sorry

任何你提供的帮助或建议我都洗耳恭听

## UV SNAPSHOTS
## PYTHON
import maya.cmds as mc


def get_snapshot_res(label, *args):
    uv_snap_res = label

def save_snapshots(get_snapshot_res, uv_snap_res, *args):
    get_snapshot_res(uv_snap_res)
    print get_snapshot_res

def passValue(texSizeControl, *args):
    radioCol = mc.radioCollection(texSizeControl, query=True, sl=True)
    getSelectRadioVal = mc.radioButton(radioCol, query=True, label=True)
    get_snapshot_res(getSelectRadioVal)

def save_snapshots_ui(*args):
    myWindow = 'Create UV Snapshots'
    if mc.window(myWindow, exists=True):
        mc.deleteUI(myWindow)
    mc.window(myWindow, title = myWindow)
    mc.columnLayout(adjustableColumn=True)
    mc.text(label='Choose your resolution for UV Snapshots', font='obliqueLabelFont')
    texSizeControl = mc.radioCollection()
    saveRadio1k = mc.radioButton(label='1024')
    saveRadio2k = mc.radioButton(label='2048')
    saveRadio4k = mc.radioButton(label='4096')
    saveRadio8k = mc.radioButton(label='8192')
    texSizeControl = mc.radioCollection(texSizeControl, edit=True, select=saveRadio2k )
    mc.button(label='save', command= partial(passValue, save_snapshots, texSizeControl))
    mc.setParent( '..' )
    mc.showWindow()

save_snapshots_ui()

Tags: truegetsavedefargssnapshotresmc
1条回答
网友
1楼 · 发布于 2024-10-04 09:22:29

尝试删除不需要的*args,您应该这样编写脚本:

  • cmd快照需要(FULLPATH、RES、UVRANGE)
  • ui设置分辨率
  • ui设置png名称
  • ui设置路径
  • ui选择UV范围
  • 快照按钮发送->;分辨率、名称、路径、范围
  • 获取ui资源
  • 获取ui name和ui path以创建FULLPATH
  • 获取UvUI范围
  • 将所有这些集合到一个cmd中以启动快照

你知道吗====================================

import maya.cmds as mc
# GATHER
def ui_save_snapshots(texSizeControl, *args):
    # *args is only used when the def is inside ui
    # here it is gathering information to launch the maya command
    RATIO = get_snapshot_res(texSizeControl)
    path = 'something to get the path'
    save_snapshots(path, RATIO)
# GET RES
def ui_get_snapshot_res(label):
    radioCol = mc.radioCollection(texSizeControl, query=True, sl=True)
    RATIO = mc.radioButton(radioCol, query=True, label=True)
    return RATIO
SNAPSHOT
def save_snapshots(path, resolution, uvRange=[0,1,0,1]):
    # this def is a without any ui
    # path = "/marza/proj/fuji2019/work/Prop/trap/sim/everyone/simRig/images/outUV.jpg"
    uMin, uMax, vMin, vMax = uvRange
    cmds.uvSnapshot(o=True,ff='jpg', xr=resolution, yr=4096, aa=True, r=255, g=255, b=255, n=path, uMin=uMin, uMax=uMax, vMin=vMin, vMax=vMax)

def save_snapshots_ui():
    myWindow = 'Create UV Snapshots'
    if mc.window(myWindow, exists=True):
        mc.deleteUI(myWindow)
    mc.window(myWindow, title = myWindow)
    mc.columnLayout(adjustableColumn=True)
    mc.text(label='Choose your resolution for UV Snapshots', font='obliqueLabelFont')
    texSizeControl = mc.radioCollection()
    saveRadio1k = mc.radioButton(label='1024')
    saveRadio2k = mc.radioButton(label='2048')
    saveRadio4k = mc.radioButton(label='4096')
    saveRadio8k = mc.radioButton(label='8192')
    texSizeControl = mc.radioCollection(texSizeControl, edit=True, select=saveRadio2k )
    # send textSiZeControl to passValue 
    mc.button(label='save', command= partial(passValue, texSizeControl))
    mc.setParent( '..' )
    mc.showWindow()

save_snapshots_ui()

相关问题 更多 >