Integrating 3D models with photography
Interested in integrating your 3D work with the real world? This might help
# 1 20-12-2013 , 04:14 AM
Registered User
Join Date: Dec 2013
Posts: 1

Maya GUI?

Hello guys

I am trying to create a small GUI in maya basically what I want it to do is create a image button that will create a tree and edit its attributes.... like move the tree in any direction, change it colour etc...

I have this so far..

Code:
import maya.cmds as cmds
import maya.mel as mel

cmds.window( title='Tree Maker Version 1.0' )
cmds.columnLayout()
cmds.button(label="Create a tree", command="treeGen()")
cmds.button(label="Create a second tree", command="treeGen1()")


def treeGen():
    cmds.circle(nr =(0, 1, 0), c =(0, 0, 0))
    cmds.spaceLocator( p=(0, 0, 0) )
    cmds.select("nurbsCircle1", r=True)
    cmds.select("locator1", add=True)
    cmds.parent()
    cmds.setAttr( "nurbsCircle1.rotateX", -90)
    cmds.setAttr( "nurbsCircle1.scaleZ", .1)
    cmds.setAttr( "nurbsCircle1.scaleX", .1)
    cmds.setAttr( "nurbsCircle1.scaleY", .1)
    mel.eval('source "C:/Program Files/Autodesk/Maya2014/brushes/treesMesh/oakAutumn.mel"')
    cmds.select("nurbsCircle1", r=True)
    cmds.AttachBrushToCurves()
    cmds.attrFieldSliderGrp( min=-1.0, max=3.0, at="oakAutumn1.numBranches"  )
    cmds.attrFieldSliderGrp( min=-10.0, max=10.0, at="oakAutumn1.numTwigClusters"  )
    cmds.attrFieldSliderGrp( min=-11.0, max=20.0, at="oakAutumn1.numLeafClusters"  )


cmds.showWindow()

That code is able to create a tree and edit some of its attributes. How would I be able to click the same button but creates a new tree but at a different position? Also it needs to have a function where it only allows a certain amount of trees so it cant be pressed so many times f How do I add an image to the button or make an image a button?

Any help would be appreciated

Thank you

# 2 10-02-2014 , 07:41 PM
Registered User
Join Date: Feb 2014
Location: Winter Park, Fl.
Posts: 1
Are you looking to create the trees in a random position or define where you would like to put them when the button is pressed?

If you want to limit the number of trees than you could use a "count." You can set this in the code or have it changeable in a cmds.intFeild. So when you press the button it should increase the "count" value by one.
You can establish it simply at the top:

count = 0

Then in side of the code have an if statement that checks if the count is greater than or equal to the number you want it to stop at:

Code:
if count >= <some_value>:
     print "max tree limit"
else:
     <run the rest of the code>
     count += 1
For the button image you may want to use the "symbolButton" command which will let you use the "image=" flag and you can link the image from your directory. I hope some of this helps. Let me know about the placement and I'll see what I can do!


Last edited by Theatis; 10-02-2014 at 07:43 PM. Reason: Forgot to add code tags!
Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads