tag:blogger.com,1999:blog-75686117458521427592024-03-08T09:55:05.945-08:00Chris DeVito: Technical TidbitsAll Content © Chris DeVitoChris Devitohttp://www.blogger.com/profile/16878156216065769373noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-7568611745852142759.post-71926061632419904442014-04-04T14:05:00.002-07:002014-04-04T14:05:41.941-07:00Setting the correct Pixel Aspect in MayaI just recently ran into the issue of setting the pixelAspectRatio of the defaultResolution to a value that wasn't what maya was setting based on the width and height. I couldn't really find any answers on the net so I figure i'd put my answer up.<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">maya.cmds</span> <span style="color: #008800; font-weight: bold;">as</span> <span style="color: #0e84b5; font-weight: bold;">cmds</span>
<span style="color: #008800; font-weight: bold;">def</span> <span style="color: #0066bb; font-weight: bold;">setResolution</span>(width<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">1920</span>, height<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">1080</span>, pixelAspect<span style="color: #333333;">=</span><span style="color: #6600ee; font-weight: bold;">1.0</span>):
<span style="color: #dd4422;">'''</span>
<span style="color: #dd4422;"> Sets render resolution properly.</span>
<span style="color: #dd4422;"> @param width- The width of the resolution.</span>
<span style="color: #dd4422;"> @param height- The width of the resolution.</span>
<span style="color: #dd4422;"> @param pixelAspect- The pixel aspect to set the defaultResolution to.</span>
<span style="color: #dd4422;"> Returns None</span>
<span style="color: #dd4422;"> '''</span>
<span style="color: #888888;">#Calculates the device aspect since pixel aspect isn't an actual attribute.</span>
device_aspect <span style="color: #333333;">=</span> <span style="color: #007020;">float</span>(width <span style="color: #333333;">*</span> pixelAspect)<span style="color: #333333;">/</span><span style="color: #007020;">float</span>(height)
<span style="color: #888888;">#Set the Lock Device Aspect Ratio. IMPORTANT!</span>
<span style="color: #888888;">#If you don't do this it won't work.</span>
cmds<span style="color: #333333;">.</span>setAttr(<span style="background-color: #fff0f0;">"defaultResolution.lockDeviceAspectRatio"</span>, <span style="color: #0000dd; font-weight: bold;">1</span>)
<span style="color: #888888;">#Set width, height, and aspect ratio.</span>
cmds<span style="color: #333333;">.</span>setAttr(<span style="background-color: #fff0f0;">"defaultResolution.width"</span>, width)
cmds<span style="color: #333333;">.</span>setAttr(<span style="background-color: #fff0f0;">"defaultResolution.height"</span>, height)
cmds<span style="color: #333333;">.</span>setAttr(<span style="background-color: #fff0f0;">"defaultResolution.deviceAspectRatio"</span>, device_aspect)
<span style="color: #008800; font-weight: bold;">if</span> __name__ <span style="color: #333333;">==</span> <span style="background-color: #fff0f0;">"__main__"</span>:
setResolution(width<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">3168</span>, height<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">2376</span>, pixelAspect<span style="color: #333333;">=</span><span style="color: #6600ee; font-weight: bold;">2.0</span>)</pre>
</td></tr>
</tbody></table>
</div>
<br />
Hope this saves someone the time it took me to figure this out!<br />
<br />
-Chris<br />
<br />Chris Devitohttp://www.blogger.com/profile/16878156216065769373noreply@blogger.com0tag:blogger.com,1999:blog-7568611745852142759.post-28932015379261817682013-05-20T11:53:00.000-07:002016-04-28T18:42:45.091-07:00cdSnap: PyQt style<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
So I learned some pyqt and voila, here's cdSnap. It should handle most of your ikfk snapping/space switching/rotation order snapping needs. I really like how it can bake keys in multiple ways depending on your needs. Let me know if it works or doesn't work for you!</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
You'll first want to install pyqt, I recommend <a href="http://nathanhorne.com/?p=451">Nathan Horne's</a> site to download his installers for windows.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Second, either run it the script in the python script editor or type after installing it your maya scripts directory:</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<table style="-qt-table-type: root; margin-bottom: 4px; margin-left: 4px; margin-right: 4px; margin-top: 4px;">
<tbody>
<tr>
<td style="border: none;"><div style="-qt-block-indent: 0; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;">
<!--StartFragment-->import cdSnapUI</div>
<div style="-qt-block-indent: 0; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;">
reload(cdSnapUI)</div>
<div style="-qt-block-indent: 0; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;">
cdSnap = cdSnapUI.cdSnapUI()</div>
<div style="-qt-block-indent: 0; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: 0px;">
cdSnap.show()<!--EndFragment--></div>
</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.chribis.com/scripts/rotOrderSwitch.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://www.chribis.com/scripts/rotOrderSwitch.jpg" height="180" width="200" /></a><a href="http://www.chribis.com/scripts/FKIKSnap.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://www.chribis.com/scripts/FKIKSnap.jpg" height="320" width="187" /></a><a href="http://www.chribis.com/scripts/spaceSwitch.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://www.chribis.com/scripts/spaceSwitch.jpg" height="200" width="181" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<a href="http://www.chribis.com/scripts/cdSnapUI.py">Download it!</a>Chris Devitohttp://www.blogger.com/profile/16878156216065769373noreply@blogger.com1tag:blogger.com,1999:blog-7568611745852142759.post-9707588556635215652013-04-10T15:19:00.000-07:002016-04-28T18:43:29.010-07:00Getting dat Matrix: Maya Python API 2.0So I've been delving in the Maya Python API lately and having lots of fun with matrices. I couldn't find a lot of info for using API 2.0 with matrices. <br />
<br />
In this script example, there are two functions, one that gets a worldMatrix of an object and one that decomposes a matrix into translation, rotation, and scale. I think I've annotated it pretty well, but a big thing to note is that if you freeze translation on an object, it won't return the correct world values for the object you input.<br />
<br />
Just change the nodeName to your object name and run the script.<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .5em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0pt;"><span style="color: green; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">maya.cmds</span> <span style="color: green; font-weight: bold;">as</span> <span style="color: #0e84b5; font-weight: bold;">cmds</span>
<span style="color: green; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">maya.api.OpenMaya</span> <span style="color: green; font-weight: bold;">as</span> <span style="color: #0e84b5; font-weight: bold;">OpenMaya</span>
<span style="color: green; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">math</span>
<span style="color: green; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">sys</span>
<span style="color: green; font-weight: bold;">def</span> <span style="color: #0060b0; font-weight: bold;">getMatrix</span>(node):
<span style="color: #d04020;">'''</span>
<span style="color: #d04020;"> Gets the world matrix of an object based on name.</span>
<span style="color: #d04020;"> '''</span>
<span style="color: grey;">#Selection list object and MObject for our matrix</span>
selection <span style="color: #303030;">=</span> OpenMaya<span style="color: #303030;">.</span>MSelectionList()
matrixObject <span style="color: #303030;">=</span> OpenMaya<span style="color: #303030;">.</span>MObject()
<span style="color: grey;">#Adding object</span>
selection<span style="color: #303030;">.</span>add(node)
<span style="color: grey;">#New api is nice since it will just return an MObject instead of taking two arguments.</span>
MObjectA <span style="color: #303030;">=</span> selection<span style="color: #303030;">.</span>getDependNode(<span style="color: #0000d0; font-weight: bold;">0</span>)
<span style="color: grey;">#Dependency node so we can get the worldMatrix attribute</span>
fnThisNode <span style="color: #303030;">=</span> OpenMaya<span style="color: #303030;">.</span>MFnDependencyNode(MObjectA)
<span style="color: grey;">#Get it's world matrix plug</span>
worldMatrixAttr <span style="color: #303030;">=</span> fnThisNode<span style="color: #303030;">.</span>attribute( <span style="background-color: #fff0f0;">"worldMatrix"</span> )
<span style="color: grey;">#Getting mPlug by plugging in our MObject and attribute</span>
matrixPlug <span style="color: #303030;">=</span> OpenMaya<span style="color: #303030;">.</span>MPlug( MObjectA, worldMatrixAttr )
matrixPlug <span style="color: #303030;">=</span> matrixPlug<span style="color: #303030;">.</span>elementByLogicalIndex( <span style="color: #0000d0; font-weight: bold;">0</span> )
<span style="color: grey;">#Get matrix plug as MObject so we can get it's data.</span>
matrixObject <span style="color: #303030;">=</span> matrixPlug<span style="color: #303030;">.</span>asMObject( )
<span style="color: grey;">#Finally get the data</span>
worldMatrixData <span style="color: #303030;">=</span> OpenMaya<span style="color: #303030;">.</span>MFnMatrixData( matrixObject )
worldMatrix <span style="color: #303030;">=</span> worldMatrixData<span style="color: #303030;">.</span>matrix( )
<span style="color: green; font-weight: bold;">return</span> worldMatrix
<span style="color: green; font-weight: bold;">def</span> <span style="color: #0060b0; font-weight: bold;">decompMatrix</span>(node,matrix):
<span style="color: #d04020;">'''</span>
<span style="color: #d04020;"> Decomposes a MMatrix in new api. Returns an list of translation,rotation,scale in world space.</span>
<span style="color: #d04020;"> '''</span>
<span style="color: grey;">#Rotate order of object</span>
rotOrder <span style="color: #303030;">=</span> cmds<span style="color: #303030;">.</span>getAttr(<span style="background-color: #fff0f0;">'</span><span style="background-color: #e0e0e0;">%s</span><span style="background-color: #fff0f0;">.rotateOrder'</span><span style="color: #303030;">%</span>node)
<span style="color: grey;">#Puts matrix into transformation matrix</span>
mTransformMtx <span style="color: #303030;">=</span> OpenMaya<span style="color: #303030;">.</span>MTransformationMatrix(matrix)
<span style="color: grey;">#Translation Values</span>
trans <span style="color: #303030;">=</span> mTransformMtx<span style="color: #303030;">.</span>translation(OpenMaya<span style="color: #303030;">.</span>MSpace<span style="color: #303030;">.</span>kWorld)
<span style="color: grey;">#Euler rotation value in radians</span>
eulerRot <span style="color: #303030;">=</span> mTransformMtx<span style="color: #303030;">.</span>rotation()
<span style="color: grey;">#Reorder rotation order based on ctrl.</span>
eulerRot<span style="color: #303030;">.</span>reorderIt(rotOrder)
<span style="color: grey;">#Find degrees</span>
angles <span style="color: #303030;">=</span> [math<span style="color: #303030;">.</span>degrees(angle) <span style="color: green; font-weight: bold;">for</span> angle <span style="color: black; font-weight: bold;">in</span> (eulerRot<span style="color: #303030;">.</span>x, eulerRot<span style="color: #303030;">.</span>y, eulerRot<span style="color: #303030;">.</span>z)]
<span style="color: grey;">#Find world scale of our object.</span>
scale <span style="color: #303030;">=</span> mTransformMtx<span style="color: #303030;">.</span>scale(OpenMaya<span style="color: #303030;">.</span>MSpace<span style="color: #303030;">.</span>kWorld)
<span style="color: grey;">#Return Values</span>
<span style="color: green; font-weight: bold;">return</span> [trans<span style="color: #303030;">.</span>x,trans<span style="color: #303030;">.</span>y,trans<span style="color: #303030;">.</span>z],angles,scale
<span style="color: grey;">#If we're in the main namespace run our stuffs!</span>
<span style="color: green; font-weight: bold;">if</span> __name__ <span style="color: #303030;">==</span> <span style="background-color: #fff0f0;">'__main__'</span>:
<span style="color: grey;">#Defining object name.</span>
nodeName <span style="color: #303030;">=</span> <span style="background-color: #fff0f0;">'yourName'</span>
<span style="color: grey;">#Get Matrix</span>
mat <span style="color: #303030;">=</span> getMatrix(nodeName)
<span style="color: grey;">#Decompose matrix</span>
matDecomp <span style="color: #303030;">=</span> decompMatrix(nodeName,mat)
<span style="color: grey;">#Print our values</span>
sys<span style="color: #303030;">.</span>stdout<span style="color: #303030;">.</span>write(<span style="background-color: #fff0f0;">'</span><span style="background-color: #fff0f0; color: #606060; font-weight: bold;">\n</span><span style="background-color: #fff0f0;">---------------------------</span><span style="background-color: #e0e0e0;">%s</span><span style="background-color: #fff0f0;">---------------------------</span><span style="background-color: #fff0f0; color: #606060; font-weight: bold;">\n</span><span style="background-color: #fff0f0;">'</span><span style="color: #303030;">%</span>nodeName)
sys<span style="color: #303030;">.</span>stdout<span style="color: #303030;">.</span>write(<span style="background-color: #fff0f0;">'</span><span style="background-color: #fff0f0; color: #606060; font-weight: bold;">\n</span><span style="background-color: #fff0f0;">Translation : </span><span style="background-color: #e0e0e0;">%s</span><span style="background-color: #fff0f0;">'</span> <span style="color: #303030;">%</span>matDecomp[<span style="color: #0000d0; font-weight: bold;">0</span>])
sys<span style="color: #303030;">.</span>stdout<span style="color: #303030;">.</span>write(<span style="background-color: #fff0f0;">'</span><span style="background-color: #fff0f0; color: #606060; font-weight: bold;">\n</span><span style="background-color: #fff0f0;">Rotation : </span><span style="background-color: #e0e0e0;">%s</span><span style="background-color: #fff0f0;">'</span> <span style="color: #303030;">%</span>matDecomp[<span style="color: #0000d0; font-weight: bold;">1</span>])
sys<span style="color: #303030;">.</span>stdout<span style="color: #303030;">.</span>write(<span style="background-color: #fff0f0;">'</span><span style="background-color: #fff0f0; color: #606060; font-weight: bold;">\n</span><span style="background-color: #fff0f0;">Scale : </span><span style="background-color: #e0e0e0;">%s</span><span style="background-color: #fff0f0; color: #606060; font-weight: bold;">\n</span><span style="background-color: #fff0f0;">'</span> <span style="color: #303030;">%</span>matDecomp[<span style="color: #0000d0; font-weight: bold;">2</span>])</pre>
</div>
<br />
You could very easily get an MMatrix using maya.cmds by just doing:<style type="text/css">p, li { white-space: pre-wrap; }</style><br />
<table style="margin: 4px;">
<tbody>
<tr>
<td style="border: medium none;"><div style="margin: 0px; text-indent: 0px;">
<br /></div>
<div style="margin: 0px; text-indent: 0px;">
mat = OpenMaya.MMatrix(cmds.getAttr('YourNode.worldMatrix'))</div>
<div style="margin: 0px; text-indent: 0px;">
<br /></div>
<div style="margin: 0px; text-indent: 0px;">
But this will only work with the new API, not the old.</div>
</td></tr>
</tbody></table>
Chris Devitohttp://www.blogger.com/profile/16878156216065769373noreply@blogger.com8tag:blogger.com,1999:blog-7568611745852142759.post-38623934056579823002013-03-04T18:48:00.001-08:002013-03-04T18:55:57.522-08:00cdScaleAnimCurves So upon request, I wrote a script that scales selected curves relative to it's selection. Either copy this to the python script editor and run it or put it in your scripts directory and import it and run:<br />
<br />
import cdScaleAnimCurves as cdAnim<br />
cd.createUI()<br />
<br />
<a href="http://www.chribis.com/scripts/cdScaleAnimCurves.py">cdScaleAnimCurves</a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.chribis.com/scripts/cdScaleAnimCurves.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://www.chribis.com/scripts/cdScaleAnimCurves.JPG" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Let me know how it works!</div>
<div class="separator" style="clear: both; text-align: left;">
-Chris</div>
<br />Chris Devitohttp://www.blogger.com/profile/16878156216065769373noreply@blogger.com0tag:blogger.com,1999:blog-7568611745852142759.post-50220403952330378742013-01-21T15:59:00.000-08:002013-03-04T18:49:54.286-08:00cdRenderCompsWithSelectedSo I wrote an after effects script. I've never written in java, but always fun learning something new.
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><table><tr><td><pre style="margin: 0; line-height: 125%"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102</pre></td><td><pre style="margin: 0; line-height: 125%"><span style="color: #808080">/*</span>
<span style="color: #808080">This script takes the selected footage in an after effects project </span>
<span style="color: #808080">and makes a composition for each footage with the selected layers.</span>
<span style="color: #808080">It then adds it to the render queue with the inputed after effects</span>
<span style="color: #808080">template and the user specified path.</span>
<span style="color: #808080">Input:</span>
<span style="color: #808080"> Selected Footage and Layer with an active composition</span>
<span style="color: #808080">Returns:</span>
<span style="color: #808080"> None</span>
<span style="color: #808080">Functions:</span>
<span style="color: #808080"> cdGetItems();</span>
<span style="color: #808080"> cdRenderCompsWithSelected(comp, layers, footage, outputPathName, endTime, templateName);</span>
<span style="color: #808080">*/</span>
<span style="color: #008000; font-weight: bold">function</span> cdGetItems()
{
<span style="color: #008000; font-weight: bold">var</span> mySelectedItems <span style="color: #303030">=</span> [];
<span style="color: #008000; font-weight: bold">for</span> (<span style="color: #008000; font-weight: bold">var</span> i <span style="color: #303030">=</span> <span style="color: #0000D0; font-weight: bold">1</span>; i <span style="color: #303030"><=</span> app.project.numItems; i<span style="color: #303030">++</span>)
{
<span style="color: #008000; font-weight: bold">if</span> (app.project.item(i).selected)
{
mySelectedItems[mySelectedItems.length] <span style="color: #303030">=</span> app.project.item(i);
}
}
<span style="color: #008000; font-weight: bold">if</span>(mySelectedItems.length <span style="color: #303030"><</span> <span style="color: #0000D0; font-weight: bold">1</span>)
{
alert(<span style="background-color: #fff0f0">"You have no footage selected"</span>);
<span style="color: #008000; font-weight: bold">return</span>;
}
<span style="color: #008000; font-weight: bold">if</span>(app.project.activeItem <span style="color: #303030">==</span> <span style="color: #008000; font-weight: bold">undefined</span> <span style="color: #303030">||</span> app.project.activeItem <span style="color: #303030">==</span> <span style="color: #008000; font-weight: bold">null</span> <span style="color: #303030">||</span> app.project.activeItem.selectedLayers <span style="color: #303030">==</span> <span style="color: #008000; font-weight: bold">undefined</span> <span style="color: #303030">||</span> app.project.activeItem.selectedLayers <span style="color: #303030">==</span> <span style="color: #008000; font-weight: bold">undefined</span> <span style="color: #303030">||</span> app.project.activeItem.selectedLayers <span style="color: #303030">==</span> <span style="color: #008000; font-weight: bold">null</span> <span style="color: #303030">||</span> app.project.activeItem.selectedLayers.length <span style="color: #303030">==</span> <span style="color: #0000D0; font-weight: bold">0</span>)
{
alert(<span style="background-color: #fff0f0">"You have no adjustment layer selected"</span>);
<span style="color: #008000; font-weight: bold">return</span>;
}
<span style="color: #008000; font-weight: bold">else</span>
{
<span style="color: #008000; font-weight: bold">var</span> currentComp <span style="color: #303030">=</span> app.project.activeItem;
<span style="color: #008000; font-weight: bold">var</span> selectedLayer <span style="color: #303030">=</span> app.project.activeItem.selectedLayers[<span style="color: #0000D0; font-weight: bold">0</span>];
<span style="color: #008000; font-weight: bold">var</span> endTime <span style="color: #303030">=</span> app.project.activeItem.workAreaDuration;
<span style="color: #008000; font-weight: bold">var</span> myOutputPath<span style="color: #303030">=</span> Folder.selectDialog(<span style="background-color: #fff0f0">"Select output path!"</span>);
<span style="color: #008000; font-weight: bold">if</span> (myOutputPath <span style="color: #303030">==</span> <span style="color: #008000; font-weight: bold">undefined</span>)
{
<span style="color: #008000; font-weight: bold">return</span>;
}
<span style="color: #008000; font-weight: bold">var</span> outputPathName <span style="color: #303030">=</span> myOutputPath.fsName <span style="color: #303030">+</span> <span style="background-color: #fff0f0">"/"</span>;
<span style="color: #008000; font-weight: bold">var</span> name <span style="color: #303030">=</span> prompt(<span style="background-color: #fff0f0">"What is your render queue template name?"</span>, <span style="background-color: #fff0f0">"Spiderman"</span>);
<span style="color: #008000; font-weight: bold">if</span> (name <span style="color: #303030">==</span> <span style="color: #008000; font-weight: bold">undefined</span>)
{
<span style="color: #008000; font-weight: bold">return</span>;
}
cdRenderCompsWithSelected(currentComp, selectedLayer, mySelectedItems, outputPathName, endTime, name)
}
}
<span style="color: #008000; font-weight: bold">function</span> cdRenderCompsWithSelected(comp, layers, footage, outputPathName, endTime, templateName)
{
app.beginUndoGroup(<span style="background-color: #fff0f0">"Run the Function."</span>);
<span style="color: #008000; font-weight: bold">var</span> g <span style="color: #303030">=</span> <span style="color: #0000D0; font-weight: bold">0</span>;
<span style="color: #008000; font-weight: bold">for</span> (<span style="color: #008000; font-weight: bold">var</span> i <span style="color: #303030">=</span> <span style="color: #0000D0; font-weight: bold">0</span>; i <span style="color: #303030"><</span> footage.length; i<span style="color: #303030">++</span>)
{
<span style="color: #008000; font-weight: bold">var</span> currentFootage <span style="color: #303030">=</span> footage[i];
<span style="color: #008000; font-weight: bold">var</span> myComp <span style="color: #303030">=</span> app.project.items.addComp(currentFootage.name, <span style="color: #0000D0; font-weight: bold">1280</span>, <span style="color: #0000D0; font-weight: bold">720</span>, <span style="color: #0000D0; font-weight: bold">1</span>, currentFootage.duration, <span style="color: #0000D0; font-weight: bold">24</span>);
<span style="color: #008000; font-weight: bold">var</span> myLayer <span style="color: #303030">=</span> myComp.layers.add(currentFootage);
newLayer <span style="color: #303030">=</span> layers.copyToComp(myComp);
myComp.layers[<span style="color: #0000D0; font-weight: bold">1</span>].outPoint <span style="color: #303030">=</span> currentFootage.duration;
<span style="color: #008000; font-weight: bold">var</span> theRender <span style="color: #303030">=</span> app.project.renderQueue.items.add(myComp);
<span style="color: #008000; font-weight: bold">var</span> newFile <span style="color: #303030">=</span> <span style="color: #008000; font-weight: bold">new</span> File(outputPathName <span style="color: #303030">+</span> currentFootage.name);
theRender.outputModules[<span style="color: #0000D0; font-weight: bold">1</span>].file <span style="color: #303030">=</span> newFile;
<span style="color: #008000; font-weight: bold">try</span>
{
theRender.outputModules[<span style="color: #0000D0; font-weight: bold">1</span>].applyTemplate(templateName);
}
<span style="color: #008000; font-weight: bold">catch</span>(err)
{
<span style="color: #008000; font-weight: bold">if</span> (g <span style="color: #303030">==</span> <span style="color: #0000D0; font-weight: bold">0</span>)
{
g <span style="color: #303030">=</span> <span style="color: #0000D0; font-weight: bold">1</span>;
alert(<span style="background-color: #fff0f0">"You didn't specify an existing template name!"</span>);
}
<span style="color: #008000; font-weight: bold">continue</span>;
}
}
app.endUndoGroup();
}
cdGetItems();
</pre></td></tr></table></div>
Chris Devitohttp://www.blogger.com/profile/16878156216065769373noreply@blogger.com0tag:blogger.com,1999:blog-7568611745852142759.post-19397007835216909622012-10-15T11:26:00.002-07:002012-10-15T14:45:20.040-07:00Selected Curve to Python CommandIn the process of making a control maker for python, I found it super annoying to manually figure out the command for a curve. This script will take the selected curve and return the command in python. SO MUCH EASIER.<br />
<br />
Just run the script and type makePythonCommand("New Curve Name"). It should print out the commands for all curve types as well as transforms selected with multiple shapes under it.<br />
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><table><tr><td><pre style="margin: 0; line-height: 125%"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47</pre></td><td><pre style="margin: 0; line-height: 125%"><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">maya.cmds</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0e84b5; font-weight: bold">mc</span>
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0060B0; font-weight: bold">makePythonCommand</span>(name):
<span style="color: #008000; font-weight: bold">try</span>:
curve <span style="color: #303030">=</span> mc<span style="color: #303030">.</span>ls(selection <span style="color: #303030">=</span> <span style="color: #007020">True</span>)[<span style="color: #0000D0; font-weight: bold">0</span>]
curveShapes <span style="color: #303030">=</span> mc<span style="color: #303030">.</span>listRelatives(curve, children <span style="color: #303030">=</span> <span style="color: #007020">True</span>, path<span style="color: #303030">=</span> <span style="color: #007020">True</span>, <span style="color: #007020">type</span> <span style="color: #303030">=</span> <span style="background-color: #fff0f0">'nurbsCurve'</span>)
<span style="color: #008000; font-weight: bold">except</span>:
<span style="color: #008000; font-weight: bold">raise</span> <span style="color: #F00000; font-weight: bold">RuntimeError</span>(<span style="background-color: #fff0f0">'Select a curve Please'</span>)
<span style="color: #008000; font-weight: bold">if</span> name <span style="color: #303030">==</span> <span style="background-color: #fff0f0">''</span>:
name <span style="color: #303030">=</span> <span style="background-color: #fff0f0">'What'</span>
<span style="color: #008000; font-weight: bold">for</span> curveShape <span style="color: #000000; font-weight: bold">in</span> curveShapes:
<span style="color: #808080">#curveInfo </span>
infoNode <span style="color: #303030">=</span> mc<span style="color: #303030">.</span>createNode(<span style="background-color: #fff0f0">'curveInfo'</span>)
mc<span style="color: #303030">.</span>connectAttr(<span style="background-color: #fff0f0">"</span><span style="background-color: #e0e0e0">%s</span><span style="background-color: #fff0f0">.worldSpace[0]"</span> <span style="color: #303030">%</span>curveShape, <span style="background-color: #fff0f0">"</span><span style="background-color: #e0e0e0">%s</span><span style="background-color: #fff0f0">.inputCurve"</span> <span style="color: #303030">%</span>infoNode, force <span style="color: #303030">=</span> <span style="color: #007020">True</span>)
<span style="color: #808080">#Find the knot values and get the numSpans,degree,form, and CVs</span>
knots <span style="color: #303030">=</span> <span style="color: #007020">list</span>(mc<span style="color: #303030">.</span>getAttr(<span style="background-color: #fff0f0">'</span><span style="background-color: #e0e0e0">%s</span><span style="background-color: #fff0f0">.knots'</span> <span style="color: #303030">%</span>infoNode)[<span style="color: #0000D0; font-weight: bold">0</span>])
numSpans <span style="color: #303030">=</span> mc<span style="color: #303030">.</span>getAttr(<span style="background-color: #fff0f0">'</span><span style="background-color: #e0e0e0">%s</span><span style="background-color: #fff0f0">.spans'</span> <span style="color: #303030">%</span>curveShape)
degree <span style="color: #303030">=</span> mc<span style="color: #303030">.</span>getAttr(<span style="background-color: #fff0f0">'</span><span style="background-color: #e0e0e0">%s</span><span style="background-color: #fff0f0">.degree'</span> <span style="color: #303030">%</span>curveShape)
form <span style="color: #303030">=</span> mc<span style="color: #303030">.</span>getAttr(<span style="background-color: #fff0f0">'</span><span style="background-color: #e0e0e0">%s</span><span style="background-color: #fff0f0">.form'</span> <span style="color: #303030">%</span>curveShape)
numCVs <span style="color: #303030">=</span> numSpans <span style="color: #303030">+</span> degree
mc<span style="color: #303030">.</span>delete(infoNode)
<span style="color: #008000; font-weight: bold">if</span> form <span style="color: #303030">==</span> <span style="color: #0000D0; font-weight: bold">2</span>:
numCVs <span style="color: #303030">-=</span> degree
cVs <span style="color: #303030">=</span> mc<span style="color: #303030">.</span>ls(<span style="background-color: #fff0f0">'</span><span style="background-color: #e0e0e0">%s</span><span style="background-color: #fff0f0">.cv[0:</span><span style="background-color: #e0e0e0">%d</span><span style="background-color: #fff0f0">]'</span> <span style="color: #303030">%</span>(curveShape, (numCVs<span style="color: #303030">-</span><span style="color: #0000D0; font-weight: bold">1</span>)), flatten <span style="color: #303030">=</span> <span style="color: #007020">True</span>)
<span style="color: #808080">#For each cv get it's world position</span>
cvArray <span style="color: #303030">=</span> [mc<span style="color: #303030">.</span>xform(cv, q <span style="color: #303030">=</span> <span style="color: #007020">True</span>, ws <span style="color: #303030">=</span> <span style="color: #007020">True</span>, translation <span style="color: #303030">=</span> <span style="color: #007020">True</span>) <span style="color: #008000; font-weight: bold">for</span> cv <span style="color: #000000; font-weight: bold">in</span> cVs]
<span style="color: #008000; font-weight: bold">if</span> form <span style="color: #303030">==</span> <span style="color: #0000D0; font-weight: bold">2</span>:
cvArray<span style="color: #303030">.</span>append(cvArray[<span style="color: #0000D0; font-weight: bold">0</span>])
cvArray<span style="color: #303030">.</span>append(cvArray[<span style="color: #0000D0; font-weight: bold">1</span>])
cvArray<span style="color: #303030">.</span>append(cvArray[<span style="color: #0000D0; font-weight: bold">2</span>])
pyCmd <span style="color: #303030">=</span> <span style="background-color: #fff0f0">'mc.curve(name = "</span><span style="background-color: #e0e0e0">%s</span><span style="background-color: #fff0f0">", per = True, d= </span><span style="background-color: #e0e0e0">%s</span><span style="background-color: #fff0f0">,p= </span><span style="background-color: #e0e0e0">%s</span><span style="background-color: #fff0f0">, k = </span><span style="background-color: #e0e0e0">%s</span><span style="background-color: #fff0f0">)'</span> <span style="color: #303030">%</span>(name, degree, cvArray, knots)
<span style="color: #008000; font-weight: bold">if</span> degree <span style="color: #303030">==</span> <span style="color: #0000D0; font-weight: bold">1</span> <span style="color: #000000; font-weight: bold">and</span> form <span style="color: #303030">!=</span><span style="color: #0000D0; font-weight: bold">2</span>:
pyCmd <span style="color: #303030">=</span> <span style="background-color: #fff0f0">'mc.curve(name = "</span><span style="background-color: #e0e0e0">%s</span><span style="background-color: #fff0f0">", d= 1,p= </span><span style="background-color: #e0e0e0">%s</span><span style="background-color: #fff0f0">)'</span> <span style="color: #303030">%</span>(name, cvArray)
<span style="color: #008000; font-weight: bold">if</span> degree <span style="color: #303030">>=</span><span style="color: #0000D0; font-weight: bold">2</span> <span style="color: #000000; font-weight: bold">and</span> form <span style="color: #303030">!=</span><span style="color: #0000D0; font-weight: bold">2</span>:
pyCmd <span style="color: #303030">=</span> <span style="background-color: #fff0f0">'mc.curve(name = "</span><span style="background-color: #e0e0e0">%s</span><span style="background-color: #fff0f0">", d= </span><span style="background-color: #e0e0e0">%s</span><span style="background-color: #fff0f0">,p= </span><span style="background-color: #e0e0e0">%s</span><span style="background-color: #fff0f0">, k = </span><span style="background-color: #e0e0e0">%s</span><span style="background-color: #fff0f0">)'</span> <span style="color: #303030">%</span>(name, degree, cvArray, knots)
<span style="color: #008000; font-weight: bold">print</span> <span style="background-color: #fff0f0">'</span><span style="color: #606060; font-weight: bold; background-color: #fff0f0">\n</span><span style="background-color: #e0e0e0">%s</span><span style="background-color: #fff0f0">'</span> <span style="color: #303030">%</span>pyCmd
</pre></td></tr></table></div>
Chris Devitohttp://www.blogger.com/profile/16878156216065769373noreply@blogger.com1tag:blogger.com,1999:blog-7568611745852142759.post-82447267147439291662012-09-10T16:01:00.002-07:002012-09-10T16:01:47.347-07:00cdReorderAttributesI wrote this script today just because maya has never implemented the feature of moving your user defined attributes. Basically you can do this by hand by deleting an attribute and undoing it. Do make sure you have undo's enabled and have the object selected/have an object with user defined attributes. Just run the script in the python script editor and move attributes in the list in the order you want.<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; background: white; border-width: .1em .1em .1em .8em; border: solid gray; color: black; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: green; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">maya.cmds</span> <span style="color: green; font-weight: bold;">as</span> <span style="color: #0e84b5; font-weight: bold;">mc</span>
<span style="color: green; font-weight: bold;">def</span> <span style="color: #0060b0; font-weight: bold;">cdReorderAttributes</span>():
<span style="color: green; font-weight: bold;">if</span> mc<span style="color: #303030;">.</span>window(<span style="background-color: #fff0f0;">'cdReOrderAttributes'</span>, exists <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>):
mc<span style="color: #303030;">.</span>deleteUI(<span style="background-color: #fff0f0;">'cdReOrderAttributes'</span>)
<span style="color: grey;">#Get the selected nurbs surface and joints, otherwise print an error. </span>
<span style="color: green; font-weight: bold;">try</span>:
obj <span style="color: #303030;">=</span> mc<span style="color: #303030;">.</span>ls(selection<span style="color: #303030;">=</span> <span style="color: #007020;">True</span>)[<span style="color: #0000d0; font-weight: bold;">0</span>]
<span style="color: green; font-weight: bold;">except</span>:
<span style="color: green; font-weight: bold;">raise</span> <span style="color: #f00000; font-weight: bold;">RuntimeError</span>(<span style="background-color: #fff0f0;">'Please select an object to load attributes.'</span>)
attrs <span style="color: #303030;">=</span> mc<span style="color: #303030;">.</span>listAttr(obj, userDefined <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>)
<span style="color: green; font-weight: bold;">if</span> attrs:
<span style="color: green; font-weight: bold;">if</span> <span style="color: #007020;">len</span>(attrs) <span style="color: #303030;"><</span> <span style="color: #0000d0; font-weight: bold;">2</span>:
<span style="color: green; font-weight: bold;">raise</span> <span style="color: #f00000; font-weight: bold;">RuntimeError</span>(<span style="background-color: #fff0f0;">'Not enough attributes to reorder.'</span>)
<span style="color: green; font-weight: bold;">else</span>:
<span style="color: green; font-weight: bold;">raise</span> <span style="color: #f00000; font-weight: bold;">RuntimeError</span>(<span style="background-color: #fff0f0;">'Not enough attributes to reorder.'</span>)
win <span style="color: #303030;">=</span> mc<span style="color: #303030;">.</span>window(<span style="background-color: #fff0f0;">'cdReOrderAttributes'</span>, title<span style="color: #303030;">=</span> <span style="background-color: #fff0f0;">'cdReOrderAttributes'</span>, sizeable <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>)
mc<span style="color: #303030;">.</span>columnLayout(<span style="background-color: #fff0f0;">'attrLayout'</span>, adjustableColumn <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>, rowSpacing <span style="color: #303030;">=</span> <span style="color: #0000d0; font-weight: bold;">5</span>)
mc<span style="color: #303030;">.</span>rowColumnLayout(<span style="background-color: #fff0f0;">'attrRowLayout'</span>, numberOfColumns <span style="color: #303030;">=</span> <span style="color: #0000d0; font-weight: bold;">2</span>, columnWidth <span style="color: #303030;">=</span> [(<span style="color: #0000d0; font-weight: bold;">1</span>, <span style="color: #0000d0; font-weight: bold;">120</span>), (<span style="color: #0000d0; font-weight: bold;">2</span>,<span style="color: #0000d0; font-weight: bold;">50</span>)])
mc<span style="color: #303030;">.</span>columnLayout(<span style="background-color: #fff0f0;">'attrLayout'</span>, adjustableColumn <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>, rowSpacing <span style="color: #303030;">=</span> <span style="color: #0000d0; font-weight: bold;">5</span>)
mc<span style="color: #303030;">.</span>textScrollList(<span style="background-color: #fff0f0;">'attrScroll'</span>, allowMultiSelection<span style="color: #303030;">=</span><span style="color: #007020;">True</span>, append <span style="color: #303030;">=</span> attrs, selectItem<span style="color: #303030;">=</span> attrs[<span style="color: #0000d0; font-weight: bold;">0</span>])
mc<span style="color: #303030;">.</span>setParent(<span style="background-color: #fff0f0;">'..'</span>)
mc<span style="color: #303030;">.</span>columnLayout(<span style="background-color: #fff0f0;">'buttonLayout'</span>, adjustableColumn <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>, rowSpacing <span style="color: #303030;">=</span> <span style="color: #0000d0; font-weight: bold;">5</span>)
mc<span style="color: #303030;">.</span>symbolButton(image <span style="color: #303030;">=</span> <span style="background-color: #fff0f0;">'trackUp.png'</span>, height <span style="color: #303030;">=</span> <span style="color: #0000d0; font-weight: bold;">90</span>, command <span style="color: #303030;">=</span> <span style="background-color: #fff0f0;">'moveAttrUp()'</span>)
mc<span style="color: #303030;">.</span>symbolButton(image <span style="color: #303030;">=</span> <span style="background-color: #fff0f0;">'trackDown.png'</span>, height <span style="color: #303030;">=</span> <span style="color: #0000d0; font-weight: bold;">90</span>, command <span style="color: #303030;">=</span> <span style="background-color: #fff0f0;">'moveAttrDown()'</span>)
mc<span style="color: #303030;">.</span>setParent(<span style="background-color: #fff0f0;">'..'</span>)
mc<span style="color: #303030;">.</span>setParent(<span style="background-color: #fff0f0;">'..'</span>)
mc<span style="color: #303030;">.</span>columnLayout(<span style="background-color: #fff0f0;">'buttonLayout'</span>, adjustableColumn <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>, rowSpacing <span style="color: #303030;">=</span> <span style="color: #0000d0; font-weight: bold;">5</span>)
mc<span style="color: #303030;">.</span>button(<span style="background-color: #fff0f0;">'Reorder Attributes'</span>, command <span style="color: #303030;">=</span> <span style="background-color: #fff0f0;">'reorderAttr("</span><span style="background-color: #e0e0e0;">%s</span><span style="background-color: #fff0f0;">")'</span> <span style="color: #303030;">%</span>obj, backgroundColor <span style="color: #303030;">=</span> (<span style="color: #0000d0; font-weight: bold;">0</span>,<span style="color: #303030;">.</span><span style="color: #0000d0; font-weight: bold;">2</span>,<span style="color: #303030;">.</span><span style="color: #0000d0; font-weight: bold;">2</span>))
mc<span style="color: #303030;">.</span>setParent(<span style="background-color: #fff0f0;">'..'</span>)
mc<span style="color: #303030;">.</span>window(win, edit<span style="color: #303030;">=</span> <span style="color: #007020;">True</span>, width <span style="color: #303030;">=</span> <span style="color: #0000d0; font-weight: bold;">100</span>, height <span style="color: #303030;">=</span> <span style="color: #0000d0; font-weight: bold;">200</span>)
mc<span style="color: #303030;">.</span>showWindow(win)
<span style="color: green; font-weight: bold;">def</span> <span style="color: #0060b0; font-weight: bold;">moveAttrUp</span>():
attrs <span style="color: #303030;">=</span> mc<span style="color: #303030;">.</span>textScrollList( <span style="background-color: #fff0f0;">'attrScroll'</span>, query <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>, ai <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>)
attrSel <span style="color: #303030;">=</span> mc<span style="color: #303030;">.</span>textScrollList( <span style="background-color: #fff0f0;">'attrScroll'</span>, query <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>, selectItem <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>)[<span style="color: #0000d0; font-weight: bold;">0</span>]
a <span style="color: #303030;">=</span> attrs<span style="color: #303030;">.</span>index(attrSel)
attrs[a<span style="color: #303030;">-</span><span style="color: #0000d0; font-weight: bold;">1</span>], attrs[a] <span style="color: #303030;">=</span> attrs[a], attrs[a<span style="color: #303030;">-</span><span style="color: #0000d0; font-weight: bold;">1</span>]
mc<span style="color: #303030;">.</span>textScrollList(<span style="background-color: #fff0f0;">'attrScroll'</span>, e <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>, ra <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>)
mc<span style="color: #303030;">.</span>textScrollList(<span style="background-color: #fff0f0;">'attrScroll'</span>, e <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>, append <span style="color: #303030;">=</span> attrs, selectItem <span style="color: #303030;">=</span> attrSel)
<span style="color: green; font-weight: bold;">def</span> <span style="color: #0060b0; font-weight: bold;">moveAttrDown</span>():
attrs <span style="color: #303030;">=</span> mc<span style="color: #303030;">.</span>textScrollList( <span style="background-color: #fff0f0;">'attrScroll'</span>, query <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>, ai <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>)
attrSel <span style="color: #303030;">=</span> mc<span style="color: #303030;">.</span>textScrollList( <span style="background-color: #fff0f0;">'attrScroll'</span>, query <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>, selectItem <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>)[<span style="color: #0000d0; font-weight: bold;">0</span>]
a <span style="color: #303030;">=</span> attrs<span style="color: #303030;">.</span>index(attrSel)
<span style="color: green; font-weight: bold;">if</span> a <span style="color: #303030;">==</span> (<span style="color: #007020;">len</span>(attrs) <span style="color: #303030;">-</span> <span style="color: #0000d0; font-weight: bold;">1</span>):
attrs[<span style="color: #0000d0; font-weight: bold;">0</span>], attrs[a] <span style="color: #303030;">=</span> attrs[a], attrs[<span style="color: #0000d0; font-weight: bold;">0</span>]
<span style="color: green; font-weight: bold;">else</span>:
attrs[a<span style="color: #303030;">+</span><span style="color: #0000d0; font-weight: bold;">1</span>], attrs[a] <span style="color: #303030;">=</span> attrs[a], attrs[a<span style="color: #303030;">+</span><span style="color: #0000d0; font-weight: bold;">1</span>]
mc<span style="color: #303030;">.</span>textScrollList(<span style="background-color: #fff0f0;">'attrScroll'</span>, e <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>, ra <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>)
mc<span style="color: #303030;">.</span>textScrollList(<span style="background-color: #fff0f0;">'attrScroll'</span>, e <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>, append <span style="color: #303030;">=</span> attrs, selectItem <span style="color: #303030;">=</span> attrSel)
<span style="color: green; font-weight: bold;">def</span> <span style="color: #0060b0; font-weight: bold;">reorderAttr</span>(obj):
attrs <span style="color: #303030;">=</span> mc<span style="color: #303030;">.</span>textScrollList( <span style="background-color: #fff0f0;">'attrScroll'</span>, query <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>, ai <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>)
<span style="color: green; font-weight: bold;">for</span> attr <span style="color: black; font-weight: bold;">in</span> attrs:
mc<span style="color: #303030;">.</span>undo(mc<span style="color: #303030;">.</span>deleteAttr(obj, attribute <span style="color: #303030;">=</span> attr))
cdReorderAttributes()
</pre>
</td></tr>
</tbody></table>
</div>
Chris Devitohttp://www.blogger.com/profile/16878156216065769373noreply@blogger.com0tag:blogger.com,1999:blog-7568611745852142759.post-22094185265050903302012-09-06T13:38:00.001-07:002012-09-06T13:42:21.375-07:00Sliding JointsHere's a demo of python script I wrote to make joints slide on surfaces. On the demo, there's a hidden nurbs sphere that the joints are sliding on. It does keep the orientation of the joint, but I just didn't orient my joints when I did the demo.<br />
<br />
<iframe allowfullscreen="allowfullscreen" frameborder="0" height="405" mozallowfullscreen="mozallowfullscreen" src="http://player.vimeo.com/video/48976192?byline=0&portrait=0" webkitallowfullscreen="webkitallowfullscreen" width="720"></iframe>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7568611745852142759.post-13871393068865571682012-09-05T07:55:00.001-07:002013-06-20T15:38:53.798-07:00sceneFileContents<span style="color: #444444; font-family: sans-serif;"><span style="font-size: 15px; line-height: 24px;"><b> </b></span></span>I had the idea to write a python script that exported all your file contents neatly into a text file. I wrote some of it, but the important parts were written by old chocolate milk Dan Bradham. Just replace the directory with where you want the text file to be written.
<!-- HTML generated using hilite.me --><br />
<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><pre style="background-color: white;"><pre style="color: #333333;"><span style="color: green; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">maya.cmds</span> <span style="color: green; font-weight: bold;">as</span> <span style="color: #0e84b5; font-weight: bold;">cmds</span>
<span style="color: green; font-weight: bold;">import</span> <span style="color: #0e84b5; font-weight: bold;">os</span>
<span style="color: green; font-weight: bold;">def</span> <span style="color: #0060b0; font-weight: bold;">sceneFileContents</span>(filePath):
<span style="color: #d04020;">'''</span>
<span style="color: #d04020;"> Creates a text file that lists all your nodes in order of node types.</span>
<span style="color: #d04020;"> It puts it in your shot maya directory as a text file.</span>
<span style="color: #d04020;"> '''</span>
fileName <span style="color: #303030;">=</span> cmds<span style="color: #303030;">.</span>file(query <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>, sn <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>)
nodes <span style="color: #303030;">=</span> cmds<span style="color: #303030;">.</span>ls(showType <span style="color: #303030;">=</span> <span style="color: #007020;">True</span>)
size <span style="color: #303030;">=</span> <span style="color: #007020;">len</span>(nodes)<span style="color: #303030;">/</span><span style="color: #0000d0; font-weight: bold;">2</span>
sceneContents <span style="color: #303030;">=</span> [<span style="background-color: #fff0f0;">"</span><span style="background-color: #e0e0e0;">%s</span><span style="background-color: #fff0f0;">:</span><span style="background-color: #fff0f0; color: #606060; font-weight: bold;">\n\n</span><span style="background-color: #fff0f0;">There are </span><span style="background-color: #e0e0e0;">%i</span><span style="background-color: #fff0f0;"> objects in this scene.</span><span style="background-color: #fff0f0; color: #606060; font-weight: bold;">\n</span><span style="background-color: #fff0f0;">"</span> <span style="color: #303030;">%</span> (fileName,size)]
<span style="color: grey;">#Build a Dictionary</span>
node_dictionary <span style="color: #303030;">=</span> {}
<span style="color: green; font-weight: bold;">for</span> i <span style="color: black; font-weight: bold;">in</span> <span style="color: #007020;">range</span>(<span style="color: #0000d0; font-weight: bold;">0</span>, <span style="color: #007020;">len</span>(nodes), <span style="color: #0000d0; font-weight: bold;">2</span>):
node <span style="color: #303030;">=</span> nodes[i]
nodeType <span style="color: #303030;">=</span> nodes[i<span style="color: #303030;">+</span><span style="color: #0000d0; font-weight: bold;">1</span>]
<span style="color: green; font-weight: bold;">if</span> <span style="color: black; font-weight: bold;">not</span> nodeType <span style="color: black; font-weight: bold;">in</span> node_dictionary:
<span style="color: grey;">#If nodeType is not in dictionary, assign node as a list item</span>
node_dictionary[nodeType] <span style="color: #303030;">=</span> [node]
<span style="color: green; font-weight: bold;">else</span>:
<span style="color: grey;">#If nodeType is in dictionary, append node to the existing list</span>
node_dictionary[nodeType]<span style="color: #303030;">.</span>append(node)
<span style="color: green; font-weight: bold;">for</span> k <span style="color: black; font-weight: bold;">in</span> node_dictionary:
sceneContents<span style="color: #303030;">.</span>append (<span style="background-color: #fff0f0;">'</span><span style="background-color: #fff0f0; color: #606060; font-weight: bold;">\n</span><span style="background-color: #fff0f0;">Node Type : </span><span style="background-color: #e0e0e0;">%s</span><span style="background-color: #fff0f0;"> (</span><span style="background-color: #e0e0e0;">%s</span><span style="background-color: #fff0f0;"> Nodes)</span><span style="background-color: #fff0f0; color: #606060; font-weight: bold;">\n</span><span style="background-color: #fff0f0;">'</span> <span style="color: #303030;">%</span>(k,<span style="color: #007020;">len</span>(node_dictionary[k])))
<span style="color: green; font-weight: bold;">for</span> i, each <span style="color: black; font-weight: bold;">in</span> <span style="color: #007020;">enumerate</span>(node_dictionary[k]):
sceneContents<span style="color: #303030;">.</span>append (<span style="background-color: #fff0f0;">' </span><span style="background-color: #e0e0e0;">%d</span><span style="background-color: #fff0f0;">:</span><span style="background-color: #e0e0e0;">%s</span><span style="background-color: #fff0f0; color: #606060; font-weight: bold;">\n</span><span style="background-color: #fff0f0;">'</span> <span style="color: #303030;">%</span> (i, each))
sceneTxt <span style="color: #303030;">=</span> <span style="color: #007020;">open</span>(<span style="background-color: #fff0f0;">r'</span><span style="background-color: #e0e0e0;">%s</span><span style="background-color: #fff0f0;">sceneContent.txt'</span><span style="color: #303030;">%</span>filePath, <span style="background-color: #fff0f0;">'w'</span>)
sceneTxt<span style="color: #303030;">.</span>writelines(sceneContents)
sceneTxt<span style="color: #303030;">.</span>close()
<span style="color: green; font-weight: bold;">if</span> __name__ <span style="color: #303030;">==</span> <span style="background-color: #fff0f0;">'__main__'</span>:
sceneFileContents(<span style="background-color: #fff0f0;">'/USERS/YourName/Desktop/'</span>)</pre>
</pre>
</pre>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7568611745852142759.post-81425245145489014412012-08-17T01:54:00.002-07:002012-08-17T01:55:57.085-07:00cdFootSnap<div class="separator" style="clear: both; text-align: left;">
Wrote a tiny little script because I was working with a rig without a foot roll (why?!). Basically just position a locator/object where you want it to roll from and frame ahead until you're done.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.chribis.com/scripts/cdFootSnap.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://www.chribis.com/scripts/cdFootSnap.jpg" /></a></div>
<br />
<div style="text-align: center;">
Download it <a href="http://www.chribis.com/scripts/cdFootSnap.mel" target="_blank">here!</a></div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
If you have any question/comments just drop me an email.</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-7568611745852142759.post-65471361803383216782012-05-08T07:10:00.000-07:002012-09-05T12:53:23.065-07:00RamusSo "Ramus", has finished. After a year of work, Danica and I are both done with it.<br />
<a href="http://www.blogger.com/goog_392462566"><br /></a>
<a href="http://www.svacomputerart.com/studentwork/2012/devito_parry.html"><iframe allowfullscreen="allowfullscreen" frameborder="0" height="405" mozallowfullscreen="mozallowfullscreen" src="http://player.vimeo.com/video/41078032?byline=0&portrait=0&color=ff9933" webkitallowfullscreen="webkitallowfullscreen" width="720"></iframe></a><br />
<br />
WOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!<br />
<br />
Hopefully I'll update this more.<br />
<br />
-ChrisUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-7568611745852142759.post-65771605337891172832011-10-06T10:18:00.000-07:002011-10-06T10:23:17.139-07:00ThesisSo basically, the next year of my life is dedicated to a short film I'm working on for my final thesis. You can check out the blog for the <a href="http://ramusfilm.blogspot.com/">film here!</a> So I've been rigging and animating that. Otherwise, I've been trying to work on a side dialogue for some time unable to find all the time to work on it. I'll be posting any work non related to the film here. <div><br /></div><div><div>Yerp</div><div><br /></div><div>-Chris</div></div>Unknownnoreply@blogger.com0