Simply Maya User Community

Simply Maya User Community (https://simplymaya.com/forum/index.php)
-   Programming (https://simplymaya.com/forum/forumdisplay.php?f=32)
-   -   Maya GUI? (https://simplymaya.com/forum/showthread.php?t=40019)

acid2k1 20-12-2013 04:14 AM

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

Theatis 10-02-2014 07:41 PM

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!


All times are GMT. The time now is 10:54 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Simply Maya 2018