SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.


SM Forums / Maya Questions / Programming / Maya GUI?

Programming MEL Scripts, Expressions & Programming Related Topics

Join the conversation. Reply to post
 
Thread Tools
20-12-2013, 04:14 AM   #1
acid2k1
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
  Reply with quote
10-02-2014, 07:41 PM   #2
Theatis
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!
  Reply with quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Maya 2015 Error loading scene Awad96 Maya Technical Issues 5 05-09-2015 03:24 PM
Separating a Polygon into pieces NishantBalgovind Maya Modeling 7 18-08-2015 12:36 PM
I install Maya 8.0 Mac not compleate...Cause Maya Core 8.0 can't choose be install.. likhi1 Maya Basics & Newbie Lounge 3 23-01-2007 11:36 AM
I need the Maya gui in all my apps!!! rich Maya Basics & Newbie Lounge 10 31-01-2004 01:26 PM
Maya vs. 3DS, Light Wave, Rhino ino ect... THX1138 Maya Basics & Newbie Lounge 45 17-09-2003 02:09 PM