<?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; Tip</title>
	<atom:link href="http://sjt.is/category/tip/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>Batch adventures (or: expanding variables in batch files)</title>
		<link>http://sjt.is/2011/12/14/batch-adventures-or-expanding-variables-in-batch-files/</link>
		<comments>http://sjt.is/2011/12/14/batch-adventures-or-expanding-variables-in-batch-files/#comments</comments>
		<pubDate>Wed, 14 Dec 2011 21:05:21 +0000</pubDate>
		<dc:creator>sjt</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tip]]></category>
		<category><![CDATA[whatilearnedtoday]]></category>

		<guid isPermaLink="false">http://sjt.is/?p=342</guid>
		<description><![CDATA[I was looking into writing a fairly simple batch file to install some stuff and update environment variables. At some point I wanted to do something like this (constructing a string of &#8216;;&#8217; separated paths): set env_vars = \path\to\stuff if x%user%==xsveinbjorn &#40; set env_vars = %env_vars%;\another\path &#41; if x%hostname%==xgefjun &#40; set env_vars = %env_vars%;\whoah\this\is\radical &#41; [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking into writing a fairly simple batch file to install some stuff and update environment variables. At some point I wanted to do something like this (constructing a string of &#8216;;&#8217; separated paths):</p>

<div class="wp_syntax"><div class="code"><pre class="winbatch" style="font-family:monospace;">set env_vars = \path\<span style="color: #800080;">to</span>\stuff
<span style="color: #800080;">if</span> x<span style="color: #66cc66;">%</span>user<span style="color: #66cc66;">%</span>==xsveinbjorn <span style="color: #66cc66;">&#40;</span>
set env_vars = <span style="color: #66cc66;">%</span>env_vars<span style="color: #66cc66;">%</span><span style="color: #008000; font-style: italic;">;\another\path</span>
<span style="color: #66cc66;">&#41;</span>
<span style="color: #800080;">if</span> x<span style="color: #66cc66;">%</span>hostname<span style="color: #66cc66;">%</span>==xgefjun <span style="color: #66cc66;">&#40;</span>
set env_vars = <span style="color: #66cc66;">%</span>env_vars<span style="color: #66cc66;">%</span><span style="color: #008000; font-style: italic;">;\whoah\this\is\radical</span>
<span style="color: #66cc66;">&#41;</span>
echo env_vars</pre></div></div>

<p>When I would run this I would always get</p>

<div class="wp_syntax"><div class="code"><pre class="winbatch" style="font-family:monospace;">\path\<span style="color: #800080;">to</span>\stuff<span style="color: #008000; font-style: italic;">;\whoah\this\is\radical</span></pre></div></div>

<p>(Notice that the second path \another\path is missing from the result)<br />
Being very new to writing batch scripts I found this extremely confusing since this sort of stuff would work like a charm in python. So I started the google machine. </p>
<p>The reason this happens is that variables enclosed in &#8216;%&#8217; are expanded when the script is read, which is quite different from the way python handles this resolving stuff at the last possible time. So when the script is read it will actually look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="winbatch" style="font-family:monospace;">set env_vars = \path\<span style="color: #800080;">to</span>\stuff
<span style="color: #800080;">if</span> xsveinbjorn==xsveinbjorn <span style="color: #66cc66;">&#40;</span>
set env_vars = \path\<span style="color: #800080;">to</span>\stuff<span style="color: #008000; font-style: italic;">;\another\path</span>
<span style="color: #66cc66;">&#41;</span>
<span style="color: #800080;">if</span> xgefjun==xgefjun <span style="color: #66cc66;">&#40;</span>
set env_vars = \path\<span style="color: #800080;">to</span>\stuff<span style="color: #008000; font-style: italic;">;\whoah\this\is\radical</span>
<span style="color: #66cc66;">&#41;</span>
echo env_vars</pre></div></div>

<p>(I resolved the variables %user% to &#8216;sveinbjorn&#8217; and %hostname% to &#8216;gefjun&#8217;)<br />
And we can clearly see why we got the result that we got.</p>
<p>So what we have to do is tell the batch file to expand the variables as we go along (something close to how python does things) instead of this expand-it-when-you-read-it nonsense.</p>
<p>To do this we simply have to do three things:</p>
<ol>
<li>Add this line to the top of the code

<div class="wp_syntax"><div class="code"><pre class="winbatch" style="font-family:monospace;">setlocal EnableDelayedExpansion</pre></div></div>

</li>
<li>Add this to the end of it

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

</li>
<li>Replace the enclosing &#8216;%&#8217; to &#8216;!&#8217; for the variable you want to delay the expansion for.
<pre lang=winbatch">
if x%user%==xsveinbjorn (
set env_vars = !env_vars!;\another\path
)
</pre>
</li>
</ol>
<p>So my original example would look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="winbatch" style="font-family:monospace;">setlocal EnableDelayedExpansion
set env_vars = \path\<span style="color: #800080;">to</span>\stuff
<span style="color: #800080;">if</span> xsveinbjorn==xsveinbjorn <span style="color: #66cc66;">&#40;</span>
set env_vars = \path\<span style="color: #800080;">to</span>\stuff<span style="color: #008000; font-style: italic;">;\another\path</span>
<span style="color: #66cc66;">&#41;</span>
<span style="color: #800080;">if</span> xgefjun==xgefjun <span style="color: #66cc66;">&#40;</span>
set env_vars = \path\<span style="color: #800080;">to</span>\stuff<span style="color: #008000; font-style: italic;">;\whoah\this\is\radical</span>
<span style="color: #66cc66;">&#41;</span>
echo env_vars
endlocal</pre></div></div>

<p>Now we get the result we were looking for:</p>

<div class="wp_syntax"><div class="code"><pre class="winbatch" style="font-family:monospace;">\path\<span style="color: #800080;">to</span>\stuff<span style="color: #008000; font-style: italic;">;\another\path;\whoah\this\is\radical</span></pre></div></div>

<p>This also applies to loops and other places where the variable might change between the time you start the batch script and when you actually want to expand it.</p>
]]></content:encoded>
			<wfw:commentRss>http://sjt.is/2011/12/14/batch-adventures-or-expanding-variables-in-batch-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A tiny FCP tip</title>
		<link>http://sjt.is/2009/07/03/a-tiny-fcp-tip/</link>
		<comments>http://sjt.is/2009/07/03/a-tiny-fcp-tip/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 07:10:17 +0000</pubDate>
		<dc:creator>sjt</dc:creator>
				<category><![CDATA[FinalCut]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://sjt.is/?p=229</guid>
		<description><![CDATA[I had this issue the other day where I had at some point deleted the sound that accompanied a clip from a timeline. The quickest way I found was the &#8216;match frame&#8217; (shortcut: f) command. Just put your playhead on the start of the clip you want to get the sound back from and hit [...]]]></description>
			<content:encoded><![CDATA[<p>I had this issue the other day where I had at some point deleted the sound that accompanied a clip from a timeline. The quickest way I found was the &#8216;match frame&#8217; (shortcut: f) command. Just put your playhead on the start of the clip you want to get the sound back from and hit f. Then the viewer loads with the source clip (not the clip from the timeline) with the appropriate in and out points. Then you can  either hit f10 or use your preffered method of inserting thing into your timeline. And there&#8217;s your clip with sound.</p>
<p>I found this extremely useful when I had to recover the sound from around 100 shots. Then I pressed the down arrow key, hit f, f10 and repeat.</p>
]]></content:encoded>
			<wfw:commentRss>http://sjt.is/2009/07/03/a-tiny-fcp-tip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A really nice post on using GTD for animation</title>
		<link>http://sjt.is/2009/06/15/a-really-nice-post-on-using-gtd-for-animation/</link>
		<comments>http://sjt.is/2009/06/15/a-really-nice-post-on-using-gtd-for-animation/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 10:18:35 +0000</pubDate>
		<dc:creator>sjt</dc:creator>
				<category><![CDATA[Animation]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://sjt.is/?p=226</guid>
		<description><![CDATA[Jason Schleifer wrote a really nice post about GTD and some ideas about how to use it for animation. He&#8217;s also got some nice posts about using gtdagenda.com and other nice stuff. Check it out.]]></description>
			<content:encoded><![CDATA[<p><a href="http://jasonschleifer.com">Jason Schleifer</a> wrote a really nice post about GTD and some ideas about <a href="http://jasonschleifer.com/2009/06/06/gtd-for-animation/">how to use it for animation</a>. </p>
<p>He&#8217;s also got some nice posts about using gtdagenda.com and other nice stuff. Check it out.</p>
]]></content:encoded>
			<wfw:commentRss>http://sjt.is/2009/06/15/a-really-nice-post-on-using-gtd-for-animation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Replace layers in a composition in AfterEffects</title>
		<link>http://sjt.is/2009/05/18/replace-layers-in-a-composition-in-aftereffects/</link>
		<comments>http://sjt.is/2009/05/18/replace-layers-in-a-composition-in-aftereffects/#comments</comments>
		<pubDate>Mon, 18 May 2009 11:56:17 +0000</pubDate>
		<dc:creator>sjt</dc:creator>
				<category><![CDATA[After Effects]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://sjt.is/?p=201</guid>
		<description><![CDATA[I found this tip somewhere and thought I&#8217;d share this as the first in hopefully several posts of the &#8220;post a week &#8216;othon&#8221;. To replace a layer in a composition with a new item from the project window select the layer to be replaced in the composition window. Press option and drag the item from [...]]]></description>
			<content:encoded><![CDATA[<p>I found this tip somewhere and thought I&#8217;d share this as the first in hopefully several posts of the &#8220;post a week &#8216;othon&#8221;.</p>
<p>To replace a layer in a composition with a new item from the project window select the layer to be replaced in the composition window. Press option and drag the item from the project window and drop it on top of the selected layer in the composition window. Simple.</p>
<p>This preserves everything you had done to the first layer. So this saves you the hassle from dropping in the new item, copying animation, effects and transforms.</p>
<p>I don&#8217;t know why I didn&#8217;t know before last week.</p>
]]></content:encoded>
			<wfw:commentRss>http://sjt.is/2009/05/18/replace-layers-in-a-composition-in-aftereffects/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Add 360 to keyframe values</title>
		<link>http://sjt.is/2008/10/02/add-360-to-keyframe-values/</link>
		<comments>http://sjt.is/2008/10/02/add-360-to-keyframe-values/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 22:08:06 +0000</pubDate>
		<dc:creator>sjt</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Maya]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://sjt.is/?p=171</guid>
		<description><![CDATA[Here&#8217;s a little mel snippet that I found occasionally useful while animating, all these commands do is add (or subtract) 360 from a keyframe value &#8211; which is perfect for those rotational values that need to come down (or go up). Anyway, to add 360 degrees: keyframe -e -r -vc 360; Subtract 360 degrees: keyframe [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little mel snippet that I found occasionally useful while animating, all these commands do is add (or subtract) 360 from a keyframe value &#8211; which is perfect for those rotational values that need to come down (or go up).</p>
<p>Anyway, to add 360 degrees:</p>
<p><code>keyframe -e -r -vc 360;</code></p>
<p>Subtract 360 degrees:</p>
<p><code>keyframe -e -r -vc -360;</code></p>
<p>I&#8217;ve found this useful in certain cases (gimbal lock?). And hopefully someone can find this useful as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://sjt.is/2008/10/02/add-360-to-keyframe-values/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Maya&#8217;s built-in calculator (sort of)</title>
		<link>http://sjt.is/2008/04/16/mayas-built-in-calculator-sort-of/</link>
		<comments>http://sjt.is/2008/04/16/mayas-built-in-calculator-sort-of/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 03:38:29 +0000</pubDate>
		<dc:creator>sjt</dc:creator>
				<category><![CDATA[Maya]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://blog.sjt.is/?p=21</guid>
		<description><![CDATA[Just a little Maya tip here if you have Maya 8.5 or later. If you need to make some calculations and don&#8217;t want to go find your calculator of choice you can use Maya to calculate stuff for you. First, make sure you have python active in the command line (bottom left text field). If [...]]]></description>
			<content:encoded><![CDATA[<p>Just a little Maya tip here if you have Maya 8.5 or later.<br />
<br />
If you need to make some calculations and don&#8217;t want to go find your calculator of choice you can use Maya to calculate stuff for you. First, make sure you have python active in the command line (bottom left text field).<br />
<br />
<img src="http://sjt.is/efni/2008/04/commandmel.png" alt="" title="commandmel" width="307" height="134" class="alignnone size-full wp-image-23" /><br />
<br />
If it says MEL, just click it and it should switch to Python<br />
<br />
<img src="http://sjt.is/efni/2008/04/commandpython.png" alt="" title="commandpython" width="307" height="114" class="alignnone size-full wp-image-24" /><br />
<br />
Then you just type in what you want calculated, for example if you type in &#8220;4+4&#8243; and then hit control-enter, then the results pops up in the command response window. Easy.<br />
<br />
<img src="http://sjt.is/efni/2008/04/commandoutput-300x53.png" alt="" title="commandoutput" width="300" height="53" class="alignnone size-medium wp-image-22" /></p>
<p>&nbsp;</p>
<p>IMPORTANT NOTE<br />
To use Python as your calculator you have to remember that if you are using division remember to type the number you want to divide as a decimal number (like 5.0 instead of 5) otherwise you&#8217;ll get a rounded down result. 5/2 gives you 2 and 5.0/2 gives you 2.5. This obviously doesn&#8217;t matter if you are adding, multiplying or subtracting.</p>
]]></content:encoded>
			<wfw:commentRss>http://sjt.is/2008/04/16/mayas-built-in-calculator-sort-of/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

