]]>http://www.3danimationartist.com/wp/2018/02/27/see-if-an-object-has-a-specific-attribute-maya-python/feed/0Maya’s Plus Minus Average Node Explained From a Rigging Perspective. Pythonhttp://www.3danimationartist.com/wp/2018/02/16/maya-plus-minus-average-node-explained-from-a-rigging-perspective-python/
http://www.3danimationartist.com/wp/2018/02/16/maya-plus-minus-average-node-explained-from-a-rigging-perspective-python/#respondFri, 16 Feb 2018 03:04:07 +0000http://www.3danimationartist.com/wp/?p=11278
Also, these nodes are frequently used in rigging, probably more than they are used in shading networks, but they are written for shading networks and the documentation assumes that is how you are using them so they can be confusing to look at for their rigging potential. Just for the record I ...]]>The Autodesk documentation on the plus minus average node is atrocious, so I though I would make some notes about it in case somebody else is also confused.

Also, these nodes are frequently used in rigging, probably more than they are used in shading networks, but they are written for shading networks and the documentation assumes that is how you are using them so they can be confusing to look at for their rigging potential. Just for the record I think Autodesk should make another class of math nodes that are not shading-centric but they don’t listen to me.

Sorry in advance for this really long post, but there is a lot to know about how to use this node and in typical Autodesk fashion most of what you need to know is about how flawed the tool is.

First let’s talk about how it works. And then I will walk through the setup.

The input values that you plug into this node can be added, subtracted or averaged and the output can be used for whatever purpose you like. That’s fairly straight forward but knowing how those values get plugged in and how they work once they are there is where the confusion sets in. There are 3 sets of inputs available on this node that offer the ability to process 1 list of numbers, 2 lists of numbers or 3 lists of numbers. All of the numbers in the list will have the operation performed on them. So you might have values in 1D of [1, 2, 3] and the operation is Sum the output would be 6. You may have a 2D list [[1, 2, 3,], [4, 5, 6]] if the operation was Sum then you would have an output of 6 and 15.

So again, it can take either single dimension inputs which appears as (input 1D), double input dimensions (input 2D), or triple input dimensions (input 3D). It could conceivably take all three if you like since each of these inputs whether a single, double or triple are their own distinct lists with their own distinct outputs.

The designations for the different inputs are:

.input1D[num], .input2D[num], .input3D[num] where num is the position of numbers in the list to be added.

So if you wanted to add the number 1 plus the number 2 you would write that like this:

cmds.setAttr(‘plusMinusAverage1’ + ‘.input1D[0]’, 1)
# the way this would read is: set an attribute on the plusMinusAverage1 node, the attribute is the first position in the input list designated with the index position [0] and the value of that entry is 1.

cmds.setAttr(‘plusMinusAverage1’ + ‘.input1D[1]’, 2)
# the way this would read is: set an attribute on the plusMinusAverage1 node, the attribute is the first position in the input list designated with the index position [1] and the value of that entry is 2.

Now lets look at setting up a plusMinusAverageNode manually.

Open the node editor under “Windows” although you can work with this object in the hypershade the node editor works better for utility nodes.

Create a plus minus average node. You can do this by clicking in the Node Editor window and hitting the tab button, then you can type in ‘plus’, it will narrow your search and then you can click the node you want and hit enter to create.

Select that node and view it in your attribute editor. You will see that there are drop down menus. All of the business for this node is under Plus-Minus-Average Attributes. Open that. The first thing you will see is the operation. Its default is “Sum” you can set it to “Subtract” or “Average” and “No operation” That’s fairly self explanatory, you can change the operation of the node by changing that value.

Next set of drop downs are the Input 1D, input 2D and input 3D. Open these up and you will see that there are no inputs available yet. There is also an incongruity between the field for the Input 1D and the other inputs. The Input 1D area is a large inert field with no buttons to interact with it. You can’t drag anything into the field, you can’t enter anything, it’s useless as it is. But the other inputs allow you to click buttons that add new items. Go ahead and add a new item to either the 2D or the 3D. “The Add New Item” creates lists of inputs that can be directly manipulated through the attribute editor, you can also make new connections via the familiar checker button next to the fields and you can make manual connections via the Node Editor, the Hypershade or the Connection editor by middle mouse dragging connections.

Now understand this, there is no functional reason for the 1D field. In fact there is no functional reason for the 2D either. Each channel of the 3D input has a corresponding 3D output. Each of the 3 channels operate independently and don’t effect each other so if you wanted to just calculate a single list of values you could just use one channel of the Input 3D. I don’t know exactly why they have the 1D and 2D inputs. I imagine there is a slight computational savings to use the 1D if you are only calculating a single value. However that doesn’t explain the wildly different treatment of the 1D input. Overall this is a really poorly written tool. What would make this a really smart tool is if you could dynamically assign any number of input dimensions. Why limit it to 3 and why treat any number of dimensions different from any other? Why? because Autodesk… that’s why.

Whatever, I’ll still tell you how to use the 1D, but the fact that a single channel of the 3D does the same thing as the 1D at least helps illuminate the nature of this node.

So, make another plus minus average node in the Node Editor window.
Now click on the little 3 oblong button icon in the upper right hand corner of each of the nodes. Click 3 times on the button to expand the node completely. Now you will see the channels for the nodes.
MMD the output 1D of one node into the input 1D of the second node. Now look in the attribute editor for the node that is getting the input and you will see that it now has an input that is being generated by a connection (yellow block) and the value is 0. Now look back at the node editor at the node receiving the input. There is now a second value field that magically appeared when you added the first. It can also take an input connection, so you can go on making connections. But what if you wanted a set of values to be static or not derived from a connection? Go ahead and try to figure it out… I’m waiting… still waiting… Ha! You can’t do it without code. Isn’t that bullshit? We’ll get to how you do that in a bit, but lets now use the 2D input/output to manually set up a connection.

Select the firstPlusMinusAverage node and view it in your attribute editor.
Hit the “Add New Item” button under the Input 2D drop down. The fields for the node are made available to you.
Click in the the first channel in the Input2D[0] to 5. BTW this first column is the “x” channel in code but has no decoration here.
Go back to the node editor and middle mouse drag Output 2Dx from the first plus minus average node into the Input 2Dx of the second plus minus average node.
Now select the second plus minus average node and view it in the attribute editor. You will see that the Input 2D has the yellow filed signifying it is connected and the value is 5.
Click the “Add New Item” button and you will get another set of fields.
Select the first plus minus average node and in the attribute editor.
Change the value in the second column of Input to 10 (this second column is the “y” channel in code but has no decoration here)
Go back to the node editor and from the first plus minus average node drag Output 2Dy into the Input 2D[1], Input 2Dx of the second plus minus average node
Select the second plus minus average node receiving the inputs, view it in the attribute editor and you will now see that there are two connected inputs, one with a value of 5, the other 10.
You will see that there is nowhere to view the output for this node which I think is dumb but whatever.
Create a sphere and it will automatically be loaded into your Node Editor. There are 3 nodes to this shape, the shape node itself, the history node and the transform.
Middle mouse drag the Output 2D, Output 2Dx into the Translate Y of the transform node for the sphere you just created and you will now see that shape jump up in your scene.
You can now control this shape’s y position with the first plus minus average node inputs.
Pretty cool hua?

Now lets move on to the code you would use to create these nodes and setup inputs and outputs for them.

#If the node is not named you will have to change the name in this code to whatever the name of the node is

cmds.setAttr(newPlusMinusAverageNode + '.input1D[1]', 5)

The way that this now works is that the operation will be performed on every value in the list of the attribute editor. The values appear as a vertical list in the form:
Input 1D[0]
Input 1D[1]
and so on…

This same logic follows for the 2D and 3D Inputs. 2D inputs are simply two 1D inputs and 3D inputs are three 1D inputs. You can think of them as separate lists in the multi D inputs.

There is an additional input value for the 2D and 3D inputs that designates which “dimension” the value should be entered into.

That’s it! Now you should know the different ways to create and manipulate a plus minus average node and how to use it.!

]]>http://www.3danimationartist.com/wp/2018/02/16/maya-plus-minus-average-node-explained-from-a-rigging-perspective-python/feed/0Get the object type of the selected object, Maya, Pythonhttp://www.3danimationartist.com/wp/2018/02/10/get-the-object-type-of-the-selected-object-maya-python/
http://www.3danimationartist.com/wp/2018/02/10/get-the-object-type-of-the-selected-object-maya-python/#respondSat, 10 Feb 2018 20:55:58 +0000http://www.3danimationartist.com/wp/?p=11276
]]>select and object and run this script to find out the object type of the selected object (according to maya)

]]>http://www.3danimationartist.com/wp/2018/02/10/get-the-object-type-of-the-selected-object-maya-python/feed/0Setup Transform Limits on an Object, Maya, Python Functionhttp://www.3danimationartist.com/wp/2018/02/10/setup-transform-limits-on-an-object-maya-python-function/
http://www.3danimationartist.com/wp/2018/02/10/setup-transform-limits-on-an-object-maya-python-function/#respondSat, 10 Feb 2018 17:15:04 +0000http://www.3danimationartist.com/wp/?p=11267
]]>There is a GUI for this here. but this is a function that can be used in other scripts to do the same thing by passing the limits into the function:

]]>http://www.3danimationartist.com/wp/2018/02/06/code-snippet-for-listing-custom-attributes/feed/0Script for Importing Objects From an Asset Folder, Maya, Pythonhttp://www.3danimationartist.com/wp/2018/01/18/script-for-importing-objects-from-an-asset-folder-maya-python/
http://www.3danimationartist.com/wp/2018/01/18/script-for-importing-objects-from-an-asset-folder-maya-python/#respondThu, 18 Jan 2018 21:59:11 +0000http://www.3danimationartist.com/wp/?p=11262
I have a python function that I use to import those shapes and here it is!:

]]>I implement a rigging workflow such that I frequently reuse a bunch of common shapes. I keep them all in a specific directory (a folder called “assets” in the my documents maya folder).

I have a python function that I use to import those shapes and here it is!:

importedObject = importedObjectList[0]#getting the first object in the list of imported objects. If you had more than one then you would have to deal with this differently

cmds.parent(importedObject, world = True)#unparenting the object from the group

cmds.delete('loadedObjectGroup')#deleting the group

return footControlShape#returning the imported object to the function that called it.

importShape('nameOfFile')#this is just the name of the file in the directory, the path is specified in the method. Also, don't include file type eg. ".ma"

]]>http://www.3danimationartist.com/wp/2018/01/18/script-for-importing-objects-from-an-asset-folder-maya-python/feed/0Use Radio Buttons in a GUI Interface, Maya, Pythonhttp://www.3danimationartist.com/wp/2018/01/16/use-radio-buttons-in-a-gui-interface-maya-python/
http://www.3danimationartist.com/wp/2018/01/16/use-radio-buttons-in-a-gui-interface-maya-python/#respondTue, 16 Jan 2018 18:14:14 +0000http://www.3danimationartist.com/wp/?p=11257
Here is how I used them:
]]>Radio buttons are a bit weird, they don’t have queryable data themselves, but they can run functions that will return values.

]]>http://www.3danimationartist.com/wp/2018/01/16/use-radio-buttons-in-a-gui-interface-maya-python/feed/0Get the locations of points on a curve, pointPosition(), Maya, Pythonhttp://www.3danimationartist.com/wp/2018/01/13/get-the-locations-of-points-on-a-curve-pointposition-maya-python/
http://www.3danimationartist.com/wp/2018/01/13/get-the-locations-of-points-on-a-curve-pointposition-maya-python/#respondSat, 13 Jan 2018 15:02:11 +0000http://www.3danimationartist.com/wp/?p=11185
In order to get this function to work you need to separate out the parameters at the ‘.’ (something I am finding is a common thread among many of maya’s library functions)
This is the way to do it:

Note that this won’t work:
pointA = cmds.pointPosition(str(selectedCurve.cv[1]), world = True)
Because the .cv[1] is not separated out.
This however will work:
pointA = cmds.pointPosition(str(selectedCurve) + ‘.cv[0]’, world = ...]]>So Autodesk documentation on this is sparse and a bit inaccurate.

In order to get this function to work you need to separate out the parameters at the ‘.’ (something I am finding is a common thread among many of maya’s library functions)

#Note that the .cv[0] is separated out from the variable, also note that the .cv index starts at 0, not at 1 as the maya documentation would lead you to believe

pointA = cmds.pointPosition('%s.cv[0]'% selectedObject[0])

pointB = cmds.pointPosition('%s.cv[1]'% selectedObject[0])

print('pointA is: ' + str(pointA))

print('pointB is: ' + str(pointB))

Note that this won’t work:

pointA = cmds.pointPosition(str(selectedCurve.cv[1]), world = True)

Because the .cv[1] is not separated out.

This however will work:

pointA = cmds.pointPosition(str(selectedCurve) + ‘.cv[0]’, world = True)#this is just another way of converting a variable to a string.

Because the .cv[1] is separated out.

Also as mentioned in the code, the index for the cv points starts as [0]. Autodesk documentation indicates that it starts a [1].

]]>http://www.3danimationartist.com/wp/2018/01/13/get-the-locations-of-points-on-a-curve-pointposition-maya-python/feed/0Format for getting text from a textField, Maya, GUI, Pythonhttp://www.3danimationartist.com/wp/2018/01/10/format-for-getting-text-from-a-textfield-maya-gui-python/
http://www.3danimationartist.com/wp/2018/01/10/format-for-getting-text-from-a-textfield-maya-gui-python/#respondWed, 10 Jan 2018 21:20:33 +0000http://www.3danimationartist.com/wp/?p=11169
There are two parts to this, one is in the GUI and the other is in the code that you want to use the info for:
]]>I felt that it wasn’t immediately obvious how you go about doing this and It took a bit of research to figure out how it worked (and how it didn’t — as some tutorials that I followed seemed to maybe not be 100% sure of how it worked either)

There are two parts to this, one is in the GUI and the other is in the code that you want to use the info for:

]]>http://www.3danimationartist.com/wp/2018/01/10/format-for-getting-text-from-a-textfield-maya-gui-python/feed/0Snap an object to the center point of another object, Maya, Script, Pythonhttp://www.3danimationartist.com/wp/2018/01/08/snap-an-object-to-the-center-point-of-another-object-maya-script-python/
http://www.3danimationartist.com/wp/2018/01/08/snap-an-object-to-the-center-point-of-another-object-maya-script-python/#respondMon, 08 Jan 2018 21:31:18 +0000http://www.3danimationartist.com/wp/?p=11163
]]>I often have to snap one object to another and then freeze transforms on the object that I snapped, so I wrote this procedure: