<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>sjt &#187; Python</title>
	<atom:link href="http://sjt.is/category/scripting/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://sjt.is</link>
	<description>[insert clever tagline here]</description>
	<lastBuildDate>Tue, 08 May 2012 23:38:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>subprocess.Popen and the env argument</title>
		<link>http://sjt.is/2011/11/30/subprocess-popen-and-the-env-argument/</link>
		<comments>http://sjt.is/2011/11/30/subprocess-popen-and-the-env-argument/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 21:17:41 +0000</pubDate>
		<dc:creator>sjt</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[whatilearnedtoday]]></category>

		<guid isPermaLink="false">http://sjt.is/?p=338</guid>
		<description><![CDATA[Today I was looking at launching programs with some custom environment variables set and if you don&#8217;t want to redefine a whole lot of them for this new environment I&#8217;d recommend is copying the os.environ dictionary and do your changes on the copy, like so: new_env = os.environ.copy&#40;&#41; new_env&#91;'MEGAVARIABLE'&#93; = 'MEGAVALUE' subprocess.Popen&#40;'path', env=new_env&#41; Then you [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was looking at launching programs with some custom environment variables set and if you don&#8217;t want to redefine a whole lot of them for this new environment I&#8217;d recommend is copying the os.environ dictionary and do your changes on the copy, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">new_env = <span style="color: #dc143c;">os</span>.<span style="color: black;">environ</span>.<span style="color: #dc143c;">copy</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
new_env<span style="color: black;">&#91;</span><span style="color: #483d8b;">'MEGAVARIABLE'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'MEGAVALUE'</span>
<span style="color: #dc143c;">subprocess</span>.<span style="color: black;">Popen</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'path'</span>, env=new_env<span style="color: black;">&#41;</span></pre></div></div>

<p>Then you should have your program launched with all them fancy environment variables set.</p>
]]></content:encoded>
			<wfw:commentRss>http://sjt.is/2011/11/30/subprocess-popen-and-the-env-argument/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XSICollections, python and you</title>
		<link>http://sjt.is/2011/06/24/xsicollections-python-and-you/</link>
		<comments>http://sjt.is/2011/06/24/xsicollections-python-and-you/#comments</comments>
		<pubDate>Fri, 24 Jun 2011 14:06:52 +0000</pubDate>
		<dc:creator>sjt</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[XSI]]></category>

		<guid isPermaLink="false">http://sjt.is/?p=333</guid>
		<description><![CDATA[Have you ever called a some scripting function in Softimage and gotten back an XSICollection and printed that return value only to get a &#8216;None&#8217; value printed to the log? Don&#8217;t worry, you got some data there. Just remember that thats the way python in Softimage prints XSICollections if you would iterate over the collection [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever called a some scripting function in Softimage and gotten back an XSICollection and printed that return value only to get a &#8216;None&#8217; value printed to the log?<br />
Don&#8217;t worry, you got some data there. Just remember that thats the way python in Softimage prints XSICollections if you would iterate over the collection you will find your values:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: #008000;">object</span> <span style="color: #ff7700;font-weight:bold;">in</span> returnedCollectin:
   <span style="color: #808080; font-style: italic;"># do something with object</span>
   ...</pre></div></div>

<p>I have seen some people who just started scripting in xsi run in to this little issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://sjt.is/2011/06/24/xsicollections-python-and-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sjtCopySkinWeights</title>
		<link>http://sjt.is/2011/03/19/sjtcopyskinweights/</link>
		<comments>http://sjt.is/2011/03/19/sjtcopyskinweights/#comments</comments>
		<pubDate>Sat, 19 Mar 2011 21:05:17 +0000</pubDate>
		<dc:creator>sjt</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Maya]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://sjt.is/?p=315</guid>
		<description><![CDATA[This is a simple plug-in command to copy skin weights from one object to another with some significant restrictions: Download sjtCopySkinWeights The meshes must be exactly mirrors of each other vertex-number wise. This plugin simply uses the vertex numbers of the mesh so each vertex of object A must have a corresponding vertex on object [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple plug-in command to copy skin weights from one object to another with some significant restrictions:</p>
<p><a href="http://sjt.is/efni/scripts/sjtCopySkinWeights_v1_0.zip">Download sjtCopySkinWeights</a></p>
<ol>
<li>The meshes must be exactly mirrors of each other vertex-number wise.  This plugin simply uses the vertex numbers of the mesh so each vertex of object A must have a corresponding vertex on object B.
</li>
<li>The joint names must be somehow side-differentiated e.g. L_joint and R_joint or left_side_arm_JNT and right_side_arm_JNT or you must somehow be able to map one side of joint names to the other.
</li>
</ol>
<p>This has mostly been useful when dealing with hands, you skin one and then you have to copy the weights over, but sometimes maya does a lousy job. This plug-in is pretty much like going in the component editor and copying each value for each vertex between meshes (which would be insane to do by hand).<br />
<strong>Note:</strong> this is not a very fast script (I was trying to learn the Maya API while writing this) so give it some time to work through dense meshes.</p>
<p>If you have questions or comments just either send me an email or comment below.<br />
&nbsp;</p>
<h3>Usage</h3>
<ol>
<li>Select the object with the correct weights.</li>
<li>Select the object with the incorrect weights.</li>
<li>Run the command e.g. &#8216;sjtCopySkinWeights -s &#8220;L_&#8221; -r &#8220;R_&#8221;&#8216;</li>
</ol>
<h3>Arguments</h3>
<p>This command accepts two arguments -search/-s and -replace/-r and each argument requires a string to follow it that tells the plugin how to map the right joint names to the left ones. Yes it works kind of backwards. The command first constructs a list of all the influences on the first object, then it goes over every vertex on the other object and tries to map it&#8217;s influences to the ones in the influence-list from the first object.</p>
<h3>Example</h3>
<p>On one side the joints are called <em>L_&#8230;.._JNT</em> and the other <em>R_&#8230;&#8230;_JNT</em> the proper arguments for this command to work would be (MEL syntax):</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">sjtCopySkinWeights -s <span style="color: #483d8b;">&quot;L_&quot;</span> -r <span style="color: #483d8b;">&quot;R_&quot;</span></pre></div></div>

<p> (if no arguments are givien, this is the default search pattern)<br />
This would also have worked (since the search strings can be regular expressions):</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">sjtCopySkinWeights -s <span style="color: #483d8b;">&quot;L_&quot;</span> -r <span style="color: #483d8b;">&quot;^[rR]_&quot;</span></pre></div></div>

<p>This would allow the right side joints to be named either <em>R_&#8230;._JNT</em> or <em>r_&#8230;._JNT</em> Just remember the regular expression should go with the -r flag, the -s flag is just used to replace the match from the -r flag with.</p>
<h3>Example file</h3>
<p>To test the command immediately you can load up th test file included in the zip download &#8216;copyWeights_example.ma&#8217;. First  try scrubbing in the timeline to see the difference in weighting. The right side (pCube1) bends in the middle but the left side(pCube2) does not. To copy the weights from pCube1 to pCube2 first load the plugin, select pCube1 then pCube2 and type (MEL syntax):</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">sjtCopySkinWeights</pre></div></div>

<p>into the command line (or script editor) and then the weights will have been copied from pCube1 to pCube2. Voila.</p>
]]></content:encoded>
			<wfw:commentRss>http://sjt.is/2011/03/19/sjtcopyskinweights/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Select constraining object</title>
		<link>http://sjt.is/2011/01/25/select-constraining-object/</link>
		<comments>http://sjt.is/2011/01/25/select-constraining-object/#comments</comments>
		<pubDate>Tue, 25 Jan 2011 21:10:45 +0000</pubDate>
		<dc:creator>sjt</dc:creator>
				<category><![CDATA[Maya]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Snippet]]></category>

		<guid isPermaLink="false">http://sjt.is/?p=296</guid>
		<description><![CDATA[This is a tiny snippet I threw together today to speed up selecting the object that was controlling my selected object. In this case the object that was being controlled was a curve, but the constraining object (controlling the curve) was an invisible transform node, so instead of going through the hypergraph I wrote this: [...]]]></description>
			<content:encoded><![CDATA[<p>This is a tiny snippet I threw together today to speed up selecting the object that was controlling my selected object. In this case the object that was being controlled was a curve, but the constraining object (controlling the curve) was an invisible transform node, so instead of going through the hypergraph I wrote this:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> maya.<span style="color: black;">cmds</span> <span style="color: #ff7700;font-weight:bold;">as</span> mc
selection = mc.<span style="color: black;">ls</span><span style="color: black;">&#40;</span>sl=<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
toSelect = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> item <span style="color: #ff7700;font-weight:bold;">in</span> selection:
   constraint = mc.<span style="color: black;">listConnections</span><span style="color: black;">&#40;</span> item+<span style="color: #483d8b;">'.parentInverseMatrix[0]'</span>, d=<span style="color: #ff4500;">1</span>, s=<span style="color: #ff4500;">0</span>,<span style="color: #008000;">type</span>=<span style="color: #483d8b;">'constraint'</span><span style="color: black;">&#41;</span>
   <span style="color: #ff7700;font-weight:bold;">if</span> constraint:
      constraint = constraint<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
      src = mc.<span style="color: black;">listConnections</span><span style="color: black;">&#40;</span>constraint+<span style="color: #483d8b;">'.target[0].targetParentMatrix'</span>, d=<span style="color: #ff4500;">0</span>, s=<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">if</span> src:
         toSelect.<span style="color: black;">extend</span><span style="color: black;">&#40;</span>src<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">try</span>:
   mc.<span style="color: #dc143c;">select</span><span style="color: black;">&#40;</span>toSelect<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">except</span>:
   <span style="color: #ff7700;font-weight:bold;">pass</span></pre></div></div>

<p>Note: this allows you to select multiple constrained objects and this will try and find the driving objects, this does not handle multiple constraints or anything fancy like that. Enjoy</p>
]]></content:encoded>
			<wfw:commentRss>http://sjt.is/2011/01/25/select-constraining-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What I learned today #2: Various definitions of TEMP</title>
		<link>http://sjt.is/2010/10/04/what-i-learned-today-2-various-definitions-of-temp/</link>
		<comments>http://sjt.is/2010/10/04/what-i-learned-today-2-various-definitions-of-temp/#comments</comments>
		<pubDate>Mon, 04 Oct 2010 20:10:38 +0000</pubDate>
		<dc:creator>sjt</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[whatilearnedtoday]]></category>
		<category><![CDATA[XSI]]></category>

		<guid isPermaLink="false">http://sjt.is/?p=270</guid>
		<description><![CDATA[In Softimage on Windows, if you fetch the TEMP environment variable e.g. from witihn python (with the os.environ dictionary), you will get a different directory when you get the TEMP variable from outside Softimage. Outside Softimage you get: C:\Users\&#60;username&#62;\some\path\I\cannot\rembemer within it you get: C:\Users\&#60;username&#62;\some\path\I\cannot\rembemer\XSI_temp_### Just in case you wanted to write files to TEMP and [...]]]></description>
			<content:encoded><![CDATA[<p>In Softimage on Windows, if you fetch the <code>TEMP</code> environment variable e.g. from witihn python (with the <code>os.environ</code> dictionary), you will get a different directory when you get the <code>TEMP</code> variable from outside Softimage.<br />
Outside Softimage you get: <br />
<code>C:\Users\&lt;username&gt;\some\path\I\cannot\rembemer</code><br />
within it you get:<br />
<code>C:\Users\&lt;username&gt;\some\path\I\cannot\rembemer\XSI_temp_###</code> </p>
<p>Just in case you wanted to write files to <code>TEMP</code> and read from them later.</p>
]]></content:encoded>
			<wfw:commentRss>http://sjt.is/2010/10/04/what-i-learned-today-2-various-definitions-of-temp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What I learned today #1: profiling helps you make things run faster</title>
		<link>http://sjt.is/2010/09/29/what-i-learned-today-1-profiling-helps-you-make-things-run-faster/</link>
		<comments>http://sjt.is/2010/09/29/what-i-learned-today-1-profiling-helps-you-make-things-run-faster/#comments</comments>
		<pubDate>Wed, 29 Sep 2010 20:33:45 +0000</pubDate>
		<dc:creator>sjt</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[whatilearnedtoday]]></category>

		<guid isPermaLink="false">http://sjt.is/?p=268</guid>
		<description><![CDATA[After seeing an excellent post (as usual) on Hamish&#8217;s site about a profiling utility he wrote I decided to give it a try today, and man is this thing useful or what. It helped me find bottlenecks in two of my scripts today and I can only imagine how much of the user&#8217;s time it [...]]]></description>
			<content:encoded><![CDATA[<p>After seeing an excellent post (as usual) on Hamish&#8217;s site about a <a href="http://www.macaronikazoo.com/?p=366">profiling utility he wrote</a> I decided to give it a try today, and man is this thing useful or what. It helped me find bottlenecks in two of my scripts today and I can only imagine how much of the user&#8217;s time it will save.</p>
]]></content:encoded>
			<wfw:commentRss>http://sjt.is/2010/09/29/what-i-learned-today-1-profiling-helps-you-make-things-run-faster/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>doughellmann.com &#8211; a fantastic python resource</title>
		<link>http://sjt.is/2010/06/16/doughellmann-com-a-fantastic-python-resource/</link>
		<comments>http://sjt.is/2010/06/16/doughellmann-com-a-fantastic-python-resource/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 21:06:29 +0000</pubDate>
		<dc:creator>sjt</dc:creator>
				<category><![CDATA[Interesting]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://sjt.is/?p=258</guid>
		<description><![CDATA[I ran into Doug Hellmann&#8217;s site the other day doughellmann.com. And he an excellent collection of articles and examples for a bunch of modules from python&#8217;s standard library called Python Module of the Week. The one&#8217;s I&#8217;ve used and had no idea existed were configparser, optparser and the logging module. But there are many, many [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into Doug Hellmann&#8217;s site the other day <a href="http://doughellmann.com">doughellmann.com</a>. And he an excellent collection of articles and examples for a bunch of modules from python&#8217;s standard library called <a href="http://www.doughellmann.com/PyMOTW/contents.html">Python Module of the Week</a>. The one&#8217;s I&#8217;ve used and had no idea existed were configparser, optparser and the logging module. But there are many, many more there.</p>
<p>Absolute gold for those of us who havent gone through every page of the documentation.</p>
]]></content:encoded>
			<wfw:commentRss>http://sjt.is/2010/06/16/doughellmann-com-a-fantastic-python-resource/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

