Python Geodesic Voxel bind

Python Geodesic Voxel bind

kerrermanis
Explorer Explorer
3,613 Views
14 Replies
Message 1 of 15

Python Geodesic Voxel bind

kerrermanis
Explorer
Explorer

I'm trying to perform Maya's Geodesic Voxel bind using Python, but I'm having trouble finding the right commands.

In the Maya (2015) application it's done very easily. You move to Skin -> Smooth Bind (Options) -> select all of your settings -> Bind skin. I've tried looking in the Script Editor, but it does not show any commands that are related to a smooth bind, even though it has been executed. Here's what I get for commands:

 

select SpineBaseselect TheBoss:Mesh
#This is where the smooth bind took place
select -r RightHipAnkle

After echoing all of the executed commands again I got the following:

SmoothBindSkinOptions;
performSkinCluster true;

Those are the MEL commands, but don't tell me anything about how to perform a Geodesic Voxel bind. I have looked around the documentation a bit and found the following two that might be of use to me:

  1. skinCluster
  2. bindSkin

The bindSkin command is only used for "rigid" binds, and therefor of no use to me. The skinCluster command seems to be getting close to what I'm looking for, but still does not have the type of options I'm looking for (mainly Geodesic Voxel bind). It does have some options that are also available in the Smooth Bind Options window. For example the skinMethod, but that only indicates the linear, dual quaternion and weight blended options.

Of course I've also looked around on Google, but haven't found anything related to the Python commands I'm looking for. I found some references to PyMel, but would like to avoid that if possible (even that reference was not what I was looking for though).

 

How to perform Maya's Geodesic Voxel smooth bind using Python?

 

Note: I reposted this here from StackOverflow, because I thought I may get more answers here. Original link: http://stackoverflow.com/questions/31581686/mayas-geodesic-voxel-bind-in-python

0 Likes
3,614 Views
14 Replies
Replies (14)
Message 2 of 15

RFlannery1
Collaborator
Collaborator

Here is how to solve this problem, or any other time you are trying to find out what Maya is doing:

 

Step 1: Use the MEL "whatIs" command

whatIs SmoothBindSkinOptions;
// Result: Run Time Command // 

"Run Time Command" doesn't tell us much.  When you see it, generally the next line will tell you what command is actually being run.  So let's try "whatIs" on the next line.

whatIs performSkinCluster;
// Result: Mel procedure found in: C:/Program Files/Autodesk/Maya2015/scripts/others/performSkinCluster.mel // 

Aha!  Here is the path to a file we can look at.

 

Step 2: Examine the MEL script (do not modify it)

Open the file in a text editor, and search for "performSkinCluster".  The procedure is defined down at the bottom, on line 752.  You said it was called with "performSkinCluster true;", and true equates to 1.  So look at case 1.  It is calling "skinClusterOptions".  So search for that function.  It is defined on line 603.  Actually, it looks like this just opens the options box, not performs the actual skinning.  (When I tried skinning, I got the following output:)

skinClusterCallback OptionBoxWindow|formLayout96|tabLayout4|formLayout98|tabLayout5|columnLayout32 1;

(So I think you need to look up "skinClusterCallback" instead of "performSkinCluster".  The following steps will be based on looking up "skinClusterCallback".)

This is where it gets complicated.  You can see that "skinClusterCallback" calls "peformSkinCluster false".  Go look at "performSkinCluster" procedure again.  This time for case 0, because false equates to 0.  It calls "assembleCmd".  Search for that.  Here is the actual commands we want.  Here is a snippet:

$cmd += "newSkinCluster \"";

int $bindTo = `optionVar -q bindTo`;
if ($bindTo == 2)
{
	$cmd = ( $cmd + "-toSelectedBones " );
} else if ($bindTo == 3) {
	$cmd = ( $cmd + "-toSkeletonAndTransforms " );
}

int $bindMethod = `optionVar -q bindMethod`;
$cmd = ( $cmd + "-bindMethod " + ( $bindMethod - 1 ) + " " );

If you run the "optionVar -q bindMethod" on its own, it returns 4 (assuming the last time you skinned something you used the geodesic voxel bind.)  So the actual command you need is:

newSkinCluster -bindMethod 3;

If you continue reading the code, you will see there are other flags that go along with this bind method.  For example "-heatmapFalloff", "-geodesicResolution", "-geodesicPostVoxelCheck".

 

 

So that's it.  This script is pretty complicated.  Many times tracking down what Maya is doing is easer, but not this time.  It helps a lot if you are familiar with MEL and scripting.  I didn't know how much scripting experience you had, but hopefully this is useful.

Message 3 of 15

RFlannery1
Collaborator
Collaborator

P.S.  Also, if you do "whatIs newSkinCluster", you will find that it is not a MEL command but another procedure in another script.  C:/Program Files/Autodesk/Maya2015/scripts/others/newSkinCluster.mel //
Then that procedure calls "createSkinCluster".  Doing "whatIs createSkinCluster" points towards yet another MEL file, C:/Program Files/Autodesk/Maya2015/scripts/others/createSkinCluster.mel //

You can drill down into these to find out the actual MEL commands to use, but I think it will be better for you to use the "newSkinCluster" procedure.  That way it will automatically handle some of that lower level stuff for you.

Message 4 of 15

kerrermanis
Explorer
Explorer

Hey thanks for your response, it's quite a lot more than I had hoped for. I do have one little question however. Since I'm specifically working with Python, is there any way this applicable for Python? I have quite some experience in programming so it's not too bad for me to follow. But I have almost no experience with MEL or Maya whatsoever. If you would be able to tell me if this is applicable for Python without MEL? I could probably find it out myself, but wondering if this would be easy before I go all crazy with it to find out it doesn't work the way I planned 😉 

0 Likes
Message 5 of 15

RFlannery1
Collaborator
Collaborator

You can use it in Python.  Generally, if you see a MEL command, you can just translate it into the Python equivalent.  For example:

// MEL version
listAttr -keyable "pCube1";

# Python version
cmds.listAttr('pCube1', keyable=True)

 

However, since "newSkinCluster" is a MEL procedure, not a command, the approach is a bit different.  To call a MEL procedure, you can wrap it in "mel.eval".

First, I should back up and note that I got the syntax wrong for the "newSkinCluster" procedure.  It should actually be called like the following:

newSkinCluster("-bindMethod 3");

Thus, to call it in Python, you can use this bit of code:

mel.eval('newSkinCluster("-bindMethod 3")')

One final note.  Running the code shown above will successfully bind the geo, but you will see an error about "invalid arguments".  I suspect if you want the error message to go away, you will need to specify the other flags as well; like "-heatmapFalloff", "-geodesicResolution", and "-geodesicPostVoxelCheck".  There may be more.  You'll have to read through the MEL code to be sure.

Message 6 of 15

kerrermanis
Explorer
Explorer

Hey man, thanks! Exactly what I was looking for, and a lot more than I had hoped for. I usually kind of stay away from eval because people say it's "evil", but in this case it shouldn't be too bad.

 

If you have a StackOverflow account and want some points on there post it as an answer there too and I'll accept it, otherwise I'll post my own answer up there during the weekend. Thanks again!

0 Likes
Message 7 of 15

kerrermanis
Explorer
Explorer

I found all the correct arguments. Since the script would crash and therefor stop my entire program I decided to find them. But now that I've got it all going it gives me the following error:

 

QWidget: Cannot create a QWidget when no GUI is being used

In my own code I use the following:

mel.eval('newSkinCluster("-bindMethod 3 -geodesicResolution 256 -geodesicPostVoxelCheck true -heatmapFalloff 0.70 -mi 5")')

Which eventually leads me to createSkinCluster.mel line 534, where it tries to eval/execute the following command:

geomBind -bm 3 -gvp 256 true -fo 0.70 -mi 5 skinCluster1

geomBind is a command, but it doesn't tell me much more than that. It actually looks more like a storage data structure than a command to me, but I'm probably wrong. There is no file to follow or go to (unless you can find something I can't? :)). In any case my guess is that here is where all the magic happens, but it can't happen because I'm not using the GUI. I wouldn't mind opening/starting the/a GUI for a few seconds so this thing can get executed, but now I'm wondering if that is possible. Or maybe there are better solutions?

 

Thanks again in advance.

 

0 Likes
Message 8 of 15

RFlannery1
Collaborator
Collaborator

Are you running this in standalone Maya?  I tried it in standalone Maya, but I didn't run into any errors.  Is there any chance it is a different command causing the problem?

 

Also, it would be helpful if you could get a line number on the QWidget error message.  I know you can turn line numbers on in Script Editor > History > Line numbers in errors.  Maybe setting that in the GUI version of Maya will carry over to standalone maya, though I'm not sure.

Message 9 of 15

kerrermanis
Explorer
Explorer

Oh yeah, it would have been worth mentioning that I'm running this on the command line, without opening the Maya GUI itself. Basically I'm using mayapy to execute a Python script I'm using for batch processing. Not sure if that's what you meant by "standalone Maya"?

 

The script editor does have line number activated, so I guess it doesn't transfer over to the command line.

 

I tried running the same command using the GUI version of Maya, and it certainly did something. It didn't give me any errors as far as I could see, but when I looked at the scene the mesh was gone, but the skeleton was still there. So that's also kind of weird.

0 Likes
Message 10 of 15

RFlannery1
Collaborator
Collaborator

By standalone maya, I just mean that at the top of your script, you have something like this:

import maya.standalone
maya.standalone.initialize(name='python')

I am assuming you do because you would be getting different errors if you didn't.

 

Anyways, I've been looking into it a bit more, and it is strange.  If I make a simple Python script with that "geomBind" command and run it from the command line, I get the same error you are getting.  However, we also have a tool that lets us run a script on many files.  If I put the same command into that tool, I don't get the error.  I will do a bit of digging to see what the difference between the two environments is.

Message 11 of 15

RFlannery1
Collaborator
Collaborator

Well, I'm stumped.  I don't know why the command breaks from the command line but works in our tool.  The only thing I can think of is that our tool uses a PySide GUI, so maybe the standalone process is latching onto that.  But really that's just a guess.

 

In any case, it probably shouldn't be throwing that error.  Maybe you found a bug.  You could try sending a bug report to Autodesk, and see what they say about it.

Message 12 of 15

kerrermanis
Explorer
Explorer

Hey rflannery,

 

I think I found that some commands don't actually work on the standalone version of maya (yeah, I am running that by the way). This article specifies (for the maya prompt mode):

 

"Some commands that require the graphical user interface are either unavailable or have no effect."

 

So I'm guessing that's what I'm running in to here.

 

I've done some research and it seems that PySide is using Qt, so that would explain why it's still able to run the command (since a QT window needs to be created I guess).

 

I came up with an alternative solution that might work, which is using the commandPort function. Basically I would be able to open a connection to Maya and send commands to it that way. The only trouble I'm having now is how to open Maya with a default port opened. Since everything I'm doing is automated I can't manually insert the command to open up a port in Maya, and unfortunately opening the port can't be done via the standalone version. Is there any way to start up Maya and give it a command to execute as well (or maybe change a user setting in a file somewhere)? That would be ideal in my case. Any other tips or suggestions are also welcome.

 

In short, what needs to happen is the following:

 

In Maya gui:

 

cmds.commandPort(n="localhost:1234")

 

In Python script:

 

import maya.standalone
maya.standalone.initialize()
import maya.cmds as cmds
import socket

HOST = '127.0.0.1';
PORT = 1234;
ADDRESS = (HOST,PORT);
maya = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
maya.connect(ADDRESS)
maya.send("""maya.cmds.polySphere( radius=4 )""")  # test command

Without opening the port in Maya GUI first the connection gets refused 😕

0 Likes
Message 13 of 15

RFlannery1
Collaborator
Collaborator

It is true that some commands are not available without the GUI.  But in my mind, these would be things like "showWindow", "checkbox", and "gridLayout"; stuff that is directly related to the GUI.  It would surprise me if "geomBind" required graphical stuff.  That's just my intuition, though.  No hard facts or anything.

 

As far as "commandPort" is concerned, I have no idea.  I've never used it before.  You may want to start a new thread for that question.

0 Likes
Message 14 of 15

kerrermanis
Explorer
Explorer

Alright thanks for all the help you've provided, it was very useful. Too bad I didn't get it fixed though! I've files a bug report so maybe they'll fix it, or maybe they won't. In the mean time I'll probably start looking at the commandPort command. Thanks again!

0 Likes
Message 15 of 15

louis.sica4WKF3
Community Visitor
Community Visitor

Found this doc which seems to cut to the quick of it:  geomBind command (autodesk.com)

0 Likes