import maya.cmds as cmds
import random
from functools import partial
### Window UI ###
def FinalApp():
cmds.window (h=720, t='Maya Toolkit [JoshH_GA40B_Final]', bgc=[0.88,0.98,1.00], s=False)
cmds.columnLayout()
##Seperator
cmds.rowColumnLayout (nc=1, cw=[(1,520)])
cmds.text (l="●―――――――――――――●")
#Creation Function (Currently WIP)
sel_obj = cmds.ls (sl=True)
cmds.rowColumnLayout (nc=1, cw=[(1,520)])
cmds.text (l="Creation Tool") #Title
cmds.rowColumnLayout (nc=6, cw=[(1,50), (2,130), (3,85), (4,80), (5,80), (6,80)])
def DeleteObject (args):
cmds.delete()
cmds.text (l="Create: ")
cr_opt = cmds.optionMenu (l="", bgc=[0.169,0.365,0.169])
cr_list = ['', 'Geo • Sphere','Geo • Cube','Geo • Cylinder','Geo • Cone','Geo • Torus','Geo • Plane',"Nurb • Circle", "Nurb • Square"]
for label in cr_list:
cmds.menuItem (cr_opt, label=label)
def Trans_X(args):
numtx = cmds.intField(tr_inX, q=True, v=True)
return (numtx)
def Trans_Y(args):
numty = cmds.intField(tr_inY, q=True, v=True)
return (numty)
def Trans_Z(args):
numtz = cmds.intField(tr_inZ, q=True, v=True)
return (numtz)
def Rot_X(args):
numrx = cmds.intField(rot_inX, q=True, v=True)
return (numrx)
def Rot_Y(args):
numry = cmds.intField(rot_inY, q=True, v=True)
return (numry)
def Rot_Z(args):
numrz = cmds.intField(rot_inZ, q=True, v=True)
return (numrz)
def Scl_X(args):
numsx = cmds.intField(scl_inX, q=True, v=True)
return (numsx)
def Scl_Y(args):
numsy = cmds.intField(scl_inY, q=True, v=True)
return (numsy)
def Scl_Z(args):
numsz = cmds.intField(scl_inZ, q=True, v=True)
return (numsz)
cmds.text (l="Translation • ")
tr_inX = cmds.intField (cc=Trans_X)
tr_inY = cmds.intField (cc=Trans_Y)
tr_inZ = cmds.intField (cc=Trans_Z)
cmds.text (l='')
cmds.separator ()
cmds.text (l="Rotation • ")
rot_inX = cmds.intField (cc=Rot_X)
rot_inY = cmds.intField (cc=Rot_Y)
rot_inZ = cmds.intField (cc=Rot_Z)
cmds.text (l='')
cmds.separator ()
cmds.text (l="Scale • ")
scl_inX = cmds.intField (cc=Scl_X)
scl_inY = cmds.intField (cc=Scl_Y)
scl_inZ = cmds.intField (cc=Scl_Z)
def ObjectCreation (*args):
current = cmds.optionMenu (cr_opt, q=True, v=True)
if current == "Geo • Sphere":
cmds.polySphere (n="Sphere*")
cmds.setAttr ('.tx', tr_inX)
elif current == "Geo • Cube":
cmds.polyCube (n="Cube*")
elif current == "Geo • Cylinder":
cmds.polyCylinder (n="Cylinder*")
elif current == "Geo • Cone":
cmds.polyCone (n="Cone*")
elif current == "Geo • Torus":
cmds.polyTorus (n="Torus*")
elif current == "Geo • Plane":
cmds.polyPlane (n="Plane*")
elif current == "Nurb • Circle":
cmds.circle (n="nurb.Circle*")
elif current == "Nurb • Square":
cmds.nurbsSquare (n="nurb.Square*")
else:
print ("Nothing Selected")
cmds.button (l='X', ann="Delete Selected Object(s)", w=5, bgc=[1,0,0], c=DeleteObject)
cmds.button (l='Create!', bgc=[0.365,0.365,0.365], c=ObjectCreation)
cmds.text (l='')
cmds.text (l='')
cmds.showWindow()
FinalApp()
PyRaser()
Hey, just wondering if anyone can shed some light on this.
Under “#Creation Function (Currently WIP)” I’m trying to make a creation tool that allows the user to select the object type (Geo for example) then change the Translation, Rotation and/or Scale of the Geo selected before clicking “Create” so it generates the object with the specific int’s the user puts in the intField. I’m aware my code may be a bit all over the place, and I’m also aware that intField (q=True) wouldn’t work without the query going somewhere, but as far as I know q= or query= is the only way I know how to push the user-input to another command. If you know a better way please let me know. ^^;
As you can see above, I’ve tried using defs to pull the value input into maya as a return, but maya isn’t reading it as a valid number, and in turn isn’t using it to change the x/y/z of the t/r/s.
Example of Idea:
User chooses “Geo • Cube” from drop-down.
User inputs the following numbers:
• Translation: 5 | 15 | 24
• Rotation: 1 | 2 | 23
• Scale: 2 | 2 | 2
User clicks “Create!” which generates polyCube* with specified user-input T/R/S attributes (tx 5, ty 15, tz 24, etc)