Python reload all. Well … kind of

Do you also hate adding a

while developing a new tool.
If yes then here is the solution:

This removes all initilised modules from the memory. Even the ones that are loaded using the

method.

This means python will have to reload all modules. So put those few lines at the top of your project and you dont have to worry about reloading your modules while you are developing them. 😀

(Yes i know hacky as hell, but then again thats why we are tech artists :D)

QT and Maya. How to use a QT Designer UI with Maya. No PyQt

I had several people ask me this and usually I say. Install PyQt … on every machine that needs it and voilla. However this can not always be done and if you want to share your tools online then you just want your tools to work out of the box.

So hereby a short tutorial on how to build a QT interface with Designer that work in Maya. Since maya 2012 QT Designer is shipped with the installation of maya. You can find it here “C:\Program Files\Autodesk\<maya version>\bin\designer.exe”. This opens QT designer default interface and you can start creating your own UI’s with simple drag and drop actions. I will not go in depth on how to actually use QT designer in itself as I’ll leave that for a later time.

There are a few standard QT widgets(buttons, sliders etc) that Maya recognizes. As soon as you load the UI in maya, maya will detect these and will replace the widgets with maya’s own version. This means that you can edit, query and delete most of these detectable widgets just by using maya mel or python or pymel. No need for pyqt (even though that does make it a 100 times easier).

Someone on the creative crash website wrote a great introduction to using the QT interface. http://www.creativecrash.com/tutorials/using-qt-designer-for-mel-interfaces Especially the list of controls is very useful to keep handy when you are getting started with QT. Now I will try to skip most of the things that are covered there but some stuff might overlap.

1) Giving commands to button:

In QT Designer you can add a Dynamic Property that gets called every time the button is clicked. You can do this by going into the properties , click the plus icon and click “other… ”
Then in the “Create Dynamic Property” window, write  “-c” without the quotes in the property name section. “-c” resembles the maya mel command for a button. You can add almost all commands like this. But most of the time you will only need “-c” or “-cc” for sliders etc. (*Note if you want to use python commands use a + instead of – )

Now in your property list you will see a new dynamic property at the end of the list. Here you can type any Maya Mel !!! command. However make sure its encapsulated in a string like this.

As you can see the command in itself needs to be in a string. This might cause some confusion as you will have to “escape” any other quotation marks by using a \. Do a search on escaping strings and you will find loads of information on this. As for python code just encapsulate it in a

command.

or use a +c instead of -c.
If you have multiple lines of python code you want to put in one line use the always dreaded and nightmarish ; (semi colon).
They still give me nightmares from the time I was using mel. haha

for example:

 

2) Loading the UI in maya.

This is as straightforward as it can get.  Make ourselves a simple window. Also added a dock control to it so its dock able everywhere.

 

3) Getting values from widgets that are not supported by maya.

Now lets do something that we are not supposed to. Now this is where it starts to get interesting for me. Every time I tried to use QT I always ran into this problem. HOW THE HECK DO YOU GET A VALUE FROM A SPINBOX or a DIAL or any other cool custom downloaded widget etc. It always bugged the hell out of me for not being able to find a stable way. But now I seem to have found a solution and the answer is “signals and hidden line edits”.

You can connect any widget to a line edit. To do this create a “line edit” anywhere in the UI. Preferably where it does not edit your layout but you can easily access it.
Go into “Edit Signal / Slots” Mode (F4) and click and drag from your widget to the “line edit”. This opens up a new window that allows you to link a value to the text field (providing the widget support exporting a Qstring)

Now on change of the original widget (a double spin box in this case) the “line edit ” in itself will be updated with the value. However if the user does not change the value the line edit will be empty. Which is why its a good idea to give it the same default value as the widget.

 

4) interacting with the UI from within maya WITHOUT USING PYQT.

So now when we load our QT Ui inside of maya we can query the text of our line edit every time we want to by using the following line of code:

 

Joint hierarchy viewer

Yay found a chart viewer for wordpress:

Now it should be easier to show joint chains and explain the hierarchy.

 

Script: Saving shader information

A while ago I was asked to make a example script of how you could save out shader data. The main reason for this was to find out which textures are used for which channel. This way you do not have to use naming conventions but just have the script grab all the info you need.

 

A different way of printing, its the comma that makes it easy.

When I start debugging I usually fill up my entire code with prints to get some info out of it.
Now I used to write something like this

or

However I started to get annoyed by it as I would forget converting ints to str etc.

So I started writing it like this:

This first of all saves a lot of time typing, because of the comma, but also python will not try to combine the data and will just print whatever is provided without adding a new line in between.

Geometry influence on skin cluster explodes, the devil is in the details.

A while ago I tried to deform one geometrical object with another. The source object would deform by using the blend shapes and the target object should deform accordingly. Unfortunately as soon as I would activate the blendshape the target mesh completely exploded.

After a while I figured out that Maya doesn’t like small faces very much an creates floating point errors in the calculation. Seeing as I dint have any access to the code with the Maya api I decided to look for a simple workaround.
Simply up scaling the model solved the problem. But as long as you either have a lamina face or a face that has a surface of a decimal number the geometry influence will explode.