Home Technical Talk

exporting in Maya using Python?

Hi all

I'm working on a group project where we need to create a tool using python in Maya 2012. We've decided to create a tool that creates a polyCube based on several input fields (name, height, width, depth) and which features an "export" button that can be used instead of having to click on the "file" dropdown menu.

Unfortunately I'm a scripting noob (not to mention that for me, scripting is even more abstract than math), and I have no idea where to even look in order to accomplish this task.

Does anyone have any suggestions? I have tried various google searches but haven't come up with anything. :\

Thanks in advance!

SOLVED: This is it. one stinking line of code, haha:

cmds.button(label='Export', command=cmds.ExportSelection)

Replies

  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Do you need to create a user interface in Maya or is the user providing inputs? Just as a side question.

    Creating a script like this in Maya is pretty simple. You want to create a polycube so lets look at the documentation for a cube.

    http://download.autodesk.com/us/maya/2011help/CommandsPython/polyCube.html

    So if you have maya open. Run this:
    import maya.cmds //importing maya commands
    
    maya.cmds.polyCube()
    

    A polycube should appear in Maya. If you look at the documentation, you can provide inputs so replacing maya.cmds.polyCube() with
    maya.cmds.polyCube(name = "Awesome Cube", height = 10, width = 10, depth = 10 )
    

    That should give you a box that has its height as 10 width as 10 and depth as 10. Where did I get these attributes? By looking at the documentation and the associated flags and also you can see this from watching the script editor listener. This should be your two spots for constant reference. One thing to note, maya spews all its info out as mel commands so you're gonna have to convert it to python equivalent. There is maya2py script but I haven't messed with it.

    This is in bare essence what you're making. All you need to do is make variables that co-relate to the attributes and assign them to the attributes instead of hard-coded values.

    As an example
    import maya.cmds
    objectName = "AwesomeName"
    maya.cmds.polyCube(name = objectName )
    
    

    Hopefully gives you enough to go on. Good luck and don't be scared of code :)
  • kfsps83
    Whoops, I should have specified...

    We've already got the part of the script that creates the cube running. We've got a button on our GUI that is labelled "Export" and we need that button, when pressed, to open up the "export selection..." dialogue box. That's what we're currently trying to figure out.

    But thanks all the same for your quick response :)
  • haiddasalami
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Ah what you're looking for is fileBrowserDialog. Documentation says that you the command is deprecated but works anyway. Havent tried fileDialog2 but I know fileBrowserDialog should do the trick.

    Did some looking into fileDialog2 and pretty simple.
    filename = cmds.fileDialog2(fileMode=0, caption="Save As") 
    

    and filename will be returned as the path to where it needs to be saved.
  • kfsps83
    I will try this out when I meet with my group tonight! thanks!
  • kfsps83
    It seems I don't know enough python to implement this, but at least now I know where to poke around..thanks again
Sign In or Register to comment.