Hey guys,
So i want this piece of code to work within my ui that i have created but i just cant get it to work.
This works on its own..
import maya.cmds as cmds
faceSel = cmds.ls(sl=True)
cmds.polyProjection( faceSel, type='Planar', md='x' )
As you can see i have had a crack at it but of course it doesnt work.
faceSel = cmds.ls(sl=True)
def planarxcommand(*args):
cmds.polyProjection( faceSel, type='Planar', md='x' )
bt8 = cmds.checkBox( label='X', command=planarxcommand )
faceSel = cmds.ls(sl=True)
def planarycommand(*args):
cmds.polyProjection( faceSel, type='Planar', md='y' )
bt9 = cmds.checkBox( label='Y', command=planarycommand )
faceSel = cmds.ls(sl=True)
def planarzcommand(*args):
cmds.polyProjection( faceSel, type='Planar', md='z' )
bt10 = cmds.checkBox( label='Z', command=planarycommand )
bt11 = cmds.checkBox( label='Camera')
What i really want is a unwrap tool that works like a checkbox command. The choices you have are:
1.planar button
2. 4 checkboxes, x,y,z and camera
3. You pick what axis you want to do a planar map on (only able to have one checkbox selected)
4. hit planar button to execute the unwrap depending on what checkbox you selected
This is the ui that works:
bt7 = cmds.button( label='Planar', width=55, command=cmds.polyAutoProjection )
bt8 = cmds.checkBox( label='X',)
bt9 = cmds.checkBox( label='Y',)
bt10 = cmds.checkBox( label='Z',)
bt11 = cmds.checkBox( label='Camera',)
which displays this:

Is there anyone out there that can save me from going mad? will love you forever!
Replies
import maya.cmds as cmds myWindow = cmds.window ( title="Ben Cottage Modelling Script - ALPHA", toolbox=2, widthHeight=(218, 800) ) if (cmds.window("myWindows", exists=True)):cmds.deleteUI("myWindows") scrollLayout = cmds.scrollLayout( horizontalScrollBarThickness=0, verticalScrollBarThickness=0 ) value = cmds.scrollLayout(scrollLayout, query=True, scrollAreaValue=True) top = value[0] left = value[1] cmds.columnLayout(adjustableColumn=True ) cmds.frameLayout( label='Test Section', collapsable=True) form1 = cmds.formLayout( numberOfDivisions=100, width=215, height=175) bt7 = cmds.button( label='Planar', width=55, command=cmds.polyAutoProjection ) bt8 = cmds.checkBox( label='X',) bt9 = cmds.checkBox( label='Y',) bt10 = cmds.checkBox( label='Z',) bt11 = cmds.checkBox( label='Camera',) cmds.formLayout ( form1, edit=True, attachForm = [ (bt7, 'top', 143), (bt7, 'left', 5), (bt8, 'top', 146), (bt8, 'left', 65), (bt9, 'top', 146), (bt9, 'left', 95), (bt10, 'top', 146), (bt10, 'left', 125), (bt11, 'top', 146), (bt11, 'left', 155), ] ) cmds.setParent('..') cmds.setParent('..') allowedAreas_var = ['right', 'left'] cmds.dockControl( label='Ben Cottage Modelling Script - ALPHA', area='right', width=245, content=myWindow, allowedArea=allowedAreas_var )Just need the hard bit to work and thats the code
I had a look at your script.
Your check to see if the UI existed in order to delete it didn't work properly. I fixed it for you.
I added a function to make sure that only one checkbox can be checked at any one time by adding a 'onCommand'(onc) to the checkboxes. Also added a function for the Planar button which checks which checkbox is checked and acts on that data.
Hope it helps.
EDIT: Optimized the checked() function a whole lot.
import maya.cmds as cmds from functools import partial if (cmds.dockControl('myDock', exists=True)): cmds.deleteUI('myDock') def planarCommand(*args): x = cmds.checkBox(bt8, q=True, v=True) y = cmds.checkBox(bt9, q=True, v=True) z = cmds.checkBox(bt10, q=True, v=True) camera = cmds.checkBox(bt11, q=True, v=True) if x: print 'x' elif y: print 'y' elif z: print 'z' elif camera: print 'camera' else: print 'Please check a checkbox and try again.' def checked(button, *args): cmds.checkBox('bt8', e=True, v=False) cmds.checkBox('bt9', e=True, v=False) cmds.checkBox('bt10', e=True, v=False) cmds.checkBox('bt11', e=True, v=False) cmds.checkBox(button, e=True, v=True) myWindow = cmds.window(toolbox=2, widthHeight=(218, 800)) scrollLayout = cmds.scrollLayout(horizontalScrollBarThickness=0, verticalScrollBarThickness=0 ) value = cmds.scrollLayout(scrollLayout, query=True, scrollAreaValue=True) top = value[0] left = value[1] cmds.columnLayout(adjustableColumn=True ) cmds.frameLayout(label='Test Section', collapsable=True) form1 = cmds.formLayout(numberOfDivisions=100, width=215, height=175) bt7 = cmds.button('bt7', label='Planar', width=55, c=planarCommand) bt8 = cmds.checkBox('bt8', label='X', onc=partial(checked,'bt8')) bt9 = cmds.checkBox('bt9', label='Y', onc=partial(checked,'bt9')) bt10 = cmds.checkBox('bt10', label='Z', onc=partial(checked,'bt10')) bt11 = cmds.checkBox('bt11', label='Camera', onc=partial(checked,'bt11')) cmds.formLayout(form1, edit=True, attachForm = [ (bt7, 'top', 143), (bt7, 'left', 5), (bt8, 'top', 146), (bt8, 'left', 65), (bt9, 'top', 146), (bt9, 'left', 95), (bt10, 'top', 146), (bt10, 'left', 125), (bt11, 'top', 146), (bt11, 'left', 155), ] ) cmds.setParent('..') cmds.setParent('..') allowedAreas_var = ['right', 'left'] cmds.dockControl('myDock', label='Ben Cottage Modelling Script - ALPHA', area='right', width=245, content=myWindow, allowedArea=allowedAreas_var )