0

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

I am working on a script to create uv snapshots. Currently, I'm stuck on getting "save_snapshots" to get the integer that "uv_snap_res" is supposed to give.

In my UI, the 'save' button is using partial and I don't fully understand how that works. If I move save_snapshots behind 'texSizeControl' in the order of commands, it just simply doesn't run (I think?).

Was hoping to have a little help explaining how passing arguments works when using functions, and the order of operations when it comes to the "partial" thing... The only reason I'm this far is because of this site and finding examples in other areas. The whole radio buttons thing is a total challenge and I don't know if I fully have it working correctly :/ sorry.

any help or advice you have to offer I am all ears!!

## 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()

1 Answers1

0

Try to remove the *args where there is no need, you should write your script like this :

  • cmd SNAPSHOT need(FULLPATH, RES, UVRANGE)
  • ui set resolution
  • ui set png name
  • ui set path
  • ui select the uvRange
  • snapshot button send -> res, name, path, uvRange
  • get ui RES
  • get ui name and get ui path to create FULLPATH
  • get ui UVRANGE
  • gather all this get into one cmd to launch SNAPSHOT

====================================

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()
DrWeeny
  • 2,487
  • 1
  • 14
  • 17