PDA

View Full Version : Need help learning the basics of scripting.


jimpaw
08-20-2011, 03:50 PM
Hey guys,

I have recently started to work some in Maya again and this time i have decided to really get into scripting. The problem is that work take so much time that i dont have time to learn mel. Does anyone here on Polycount have time for a small script ? A even better solution whould be if someone knows/can create a script that makes it really easy to map a mel file or command to a button on a floating window (when i say window i mean like ninja uv/deos toll etc.) I have made custom hotkeys already wich speed up my workflow alot but i feel i need a extra window with some tools in it. The idea is to hide all UI in maya and only have a box and the shortcuts as help. I really need help with this ! Anyone please ?

haiddasalami
08-20-2011, 04:58 PM
Easiest way would probably be to use QT designer and link the commands to mel commands.

http://www.creativecrash.com/tutorials/using-qt-designer-for-mel-interfaces/page1

http://www.creativecrash.com/tutorials/maya-mel-qt-and-you-interfacing-with-the-qt-designer

jimpaw
08-21-2011, 02:57 AM
thanks alot haiddasalami (http://www.polycount.com/forum/member.php?u=30443) . I will look into this. Just a question. For someone who has no experience at all at scripting is this a good solution ? ,I just saw that the install takes 1,7 GB can this really be true ?

SpeCter
08-21-2011, 03:16 AM
The QT Library is quite big yes. If you compile it yourself itīs even bigger with all the mess it produces :D.

jimpaw
08-21-2011, 03:40 AM
Specter is it worth getting into ?

SpeCter
08-21-2011, 03:59 AM
I love QT to be honest, not sure about maya, because i donīt use maya, but QT is awesome :)

jimpaw
08-21-2011, 04:00 AM
Okay, whould it be hard to make a basic window with some buttons in maya ?

haiddasalami
08-21-2011, 04:59 AM
@jimpaw: Windows aren't that bad in mel. I just recommended QT as you wanted to map a mel command to a button which in QT is pretty easy. Also if you use 2011, QT comes installed with the maya installation. Believe its in ProgramFiles/Autodesk/Maya2012/bin and look for designer.exe Saves the installation.

r_fletch_r
08-21-2011, 05:26 AM
I love QT to be honest, not sure about maya, because i donīt use maya, but QT is awesome :)

+1 Qt is a dream to work with and does a massive amount of the work for you.

if your learning python in maya i would go straight to 'pymel', reason being is that the Autodesk wrapper is a bit crap, it forces you to write python like you would mel.. which is pretty dumb.

http://code.google.com/p/pymel/ it should also be installed in recent versions of maya by default.

haiddasalami
08-21-2011, 05:41 AM
if your learning python in maya i would go straight to 'pymel', reason being is that the Autodesk wrapper is a bit crap, it forces you to write python like you would mel.. which is pretty dumb.

http://code.google.com/p/pymel/ it should also be installed in recent versions of maya by default.

:thumbup: Get Eclipse set up with auto completion and Maya Connection and pretty much get awesome :)

http://www.christianakesson.com/blog/?p=111

r_fletch_r
08-21-2011, 08:10 AM
these are very nice python lessons done by Google.

http://www.youtube.com/watch?v=tKTZoB2Vjuk

+1 to eclipse. its a fantastic piece of software.

jimpaw
08-21-2011, 08:44 AM
Well since i cant even write Mel i cant write Python yet. But the questions is do i have to learn python to do this ? The dream whould be if you guys just could make a couple of buttons in a window and show me what line to copy to get more buttons,what buttons to paste in my mel code and so on. This may be more than enought for me. Its not a super advance script just the stuff i need the most,basic maya stuff and some scripts i downloaded.

jimpaw
08-21-2011, 08:46 AM
@jimpaw: Windows aren't that bad in mel. I just recommended QT as you wanted to map a mel command to a button which in QT is pretty easy. Also if you use 2011, QT comes installed with the maya installation. Believe its in ProgramFiles/Autodesk/Maya2012/bin and look for designer.exe Saves the installation.


Cool man will look for it thanks alot.

jimpaw
08-23-2011, 10:14 AM
:thumbup: Get Eclipse set up with auto completion and Maya Connection and pretty much get awesome :)

http://www.christianakesson.com/blog/?p=111




How can i attach the commands that i need to buttons inside QT designer ?

haiddasalami
08-23-2011, 10:54 AM
http://dl.dropbox.com/u/391285/commands_QT.jpg

Next to the dyanamic property is a text label that you can enter you enter your commands in. Also wondering why merge vertices, delete history are checkboxes? Would be better to make them buttons

jimpaw
08-23-2011, 11:10 AM
Thanks man ,i actually tried this (didnt work before) lets see if it work now. The reason i have checkboxes for delete history and merge vertecies is becouse they are a part of a clean option wich does alot of operations at the same time (if you want to). I am gonna try right away if this work ;)

jimpaw
08-23-2011, 11:47 AM
Next to the dyanamic property is a text label that you can enter you enter your commands in. Also wondering why merge vertices, delete history are checkboxes? Would be better to make them buttons[/QUOTE]

"
No Command works. I have copied the command directly from Maya so it should work. When i press the button nothing happends (nothing comes up in the script window even with echo turned on. what am i doing wrong here ? "

haiddasalami
08-23-2011, 12:10 PM
put the command to "polyUnite".

jimpaw
08-23-2011, 12:34 PM
put the command to "polyUnite".

Like this ? , still doesnt work nothing comes up in the maya script window,nothing happens.

haiddasalami
08-23-2011, 12:43 PM
type rehash then re-execute the script that brings up your window ie


string $scriptsDirectory = `internalVar -usd`;
//load the ui file
string $testwindow = `loadUI -uiFile ($scriptsDirectory+"/test.ui")`;
//show the window
showWindow $testwindow;


Maya sources the ui's at startup I believe so if you've changed the ui and save it then it wont recognize it, so rehash helps there. I have it exactly laid out like that and works on my side.

Also is your ui stored in your scripts directory/ie where you saved it to?

jimpaw
08-23-2011, 12:57 PM
type rehash then re-execute the script that brings up your window ie


string $scriptsDirectory = `internalVar -usd`;
//load the ui file
string $testwindow = `loadUI -uiFile ($scriptsDirectory+"/test.ui")`;
//show the window
showWindow $testwindow;
Maya sources the ui's at startup I believe so if you've changed the ui and save it then it wont recognize it, so rehash helps there. I have it exactly laid out like that and works on my side.

Also is your ui stored in your scripts directory/ie where you saved it to?


This message show up when i run the script the first time:

string $scriptsDirectory = `internalVar -usd`; //load the ui file
string $testwindow = `loadUI -uiFile ($scriptsDirectory+"/test.ui")`;
//show the window
showWindow $testwindow;
button -e -c "TabWidget14|Tab|pushButton_27";
// Error: No object name specified. //

My Script is saved here: C:\Users\jimmy\Documents\maya\2012-x64\scripts

you wanna take a look at the file ? can i send it to you ?

haiddasalami
08-23-2011, 03:17 PM
Theres your problem. button -e -c its not needed. Send me the stuff if you dont get it to work.


string $scriptsDirectory = `internalVar -usd`; //load the ui file
string $testwindow = `loadUI -uiFile ($scriptsDirectory+"/test.ui")`;
//show the window
showWindow $testwindow;

jimpaw
08-24-2011, 10:06 AM
Theres your problem. button -e -c its not needed. Send me the stuff if you dont get it to work.


string $scriptsDirectory = `internalVar -usd`; //load the ui file
string $testwindow = `loadUI -uiFile ($scriptsDirectory+"/test.ui")`;
//show the window
showWindow $testwindow;


Thanks man i got i to work now !!! , Just a few more:

1. How to i make a small button with an icon ? I have tried the "Tool button"
but cant find where to select iconfile. Also it doesnt work.

2. Is it possible to change colors on the buttons ?

3. How can link another script to a button (another file)

Thanks alot man !

SpeCter
08-24-2011, 10:34 AM
1. over the QPushbutton panel is the QAbstractButton, you can add your icon there(you have to put the image into your ressoures first

2.Stylesheet ->background-color

3.no clue, Maya+QT is not my speciality,sorry

jimpaw
08-24-2011, 10:52 AM
Thanks alot man !! , awsome. It ask for .crt file when i try to load png icons as resources, how do i get my icons to become that ? Ohh never mind i solved it, you rock man ! , you have any idea what the mel code is for center pivot to selected object ?

SpeCter
08-24-2011, 12:09 PM
Just take a look at the listener and do it by hand i guess, i did that myself back when i had to work with mel ;)

haiddasalami
08-24-2011, 12:25 PM
command for center pivot is


CenterPivot;


need to turn on echo all commands to see it.

The way I know QT works for mel is that it looks within the functions created in the script as mel but you might be able to link stuff if you know the path. Sorry I didnt reply to your message, been busy at work.