<?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>duber&#039;s blog &#187; Python</title>
	<atom:link href="http://blog.duber.cz/category/python/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.duber.cz</link>
	<description>the blog of duber studio™</description>
	<lastBuildDate>Wed, 01 Feb 2012 11:31:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Calling Shotgun API v3.0.8 from IronPython</title>
		<link>http://blog.duber.cz/software/calling-shotgun-api-v3-0-8-from-ironpython</link>
		<comments>http://blog.duber.cz/software/calling-shotgun-api-v3-0-8-from-ironpython#comments</comments>
		<pubDate>Wed, 01 Feb 2012 11:15:54 +0000</pubDate>
		<dc:creator>loocas</dc:creator>
				<category><![CDATA[dotNET]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[technical]]></category>

		<guid isPermaLink="false">http://blog.duber.cz/?p=993</guid>
		<description><![CDATA[As you might know there has been a significant change in the latest Shotgun API that&#8217;s somehow transparent to the CPython users, but presents a rather significant roadblock for IronPython users (including our duberPython bridge, that is based on the IronPython engine). First, let&#8217;s discuss what&#8217;s changed in the API so dramatically that it breaks [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.duber.cz/wp-content/uploads/ipy_shotgun_banner.png" alt="IronPython and Shotgun" title="IronPython and Shotgun" width="560" height="300" class="alignnone size-full wp-image-996" /></p>
<p>As you might know there has been a significant change in the latest Shotgun API that&#8217;s somehow transparent to the CPython users, but presents a rather significant roadblock for IronPython users (including our <a href="http://blog.duber.cz/?s=duberpython">duberPython</a> bridge, that is based on the IronPython engine).</p>
<p>First, let&#8217;s discuss what&#8217;s changed in the API so dramatically that it breaks IronPython compatibility. It&#8217;s the introduction of a JSON formatting that requires a few specific CPython libraries that are not available in IronPython. The effect it has on CPython users is a faster data transfer to/from Shotgun, but other than that, the API looks to be unchanged from a user point of view. You still keep calling the same methods and you&#8217;re getting back the same objects. From IronPython point of view, you&#8217;ll hit a roadblock as there are a few modifications you&#8217;ll have to make to the Shotgun modules in order to make them run in IPy without issues.</p>
<p><span id="more-993"></span></p>
<p>With huge thanks to the Shotgun Software support, I was able to work around the few limitations and start using the latest API without issues inside IronPython. Here&#8217;s what you have to do, in order to make this happen:</p>
<ul>
<li>First and foremost, <a href="https://github.com/shotgunsoftware/python-api/downloads">download the latest Shotgun API from the github site</a>. Place it some place you&#8217;d like to use it from, most likely in the Lib\site-packages folder, though my folder structure is completely different and based on different rules.</li>
</ul>
<p>Now if you try to instantiate the Shotgun class, you&#8217;ll get tons of errors, so, allow me to save you a few minutes (hours in my case, to be honest) searching and working around them. <img src='http://blog.duber.cz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<ul>
<li>The first thing you have to overcome the &#8220;<a href="http://en.wikipedia.org/wiki/Internationalized_domain_name">IDNA</a>&#8221; encoding, which isn&#8217;t supported directly in IronPython. This isn&#8217;t as clean and easy as it could be, though the workaround is rather trivial, but bear in mind you might break something potentially doing this. I haven&#8217;t come across any issues yet, so, I&#8217;d consider this modification safe. Find the <strong>iri2uri.py</strong> module in the <strong>httplib2</strong> folder, open it and change line 71 from <em>authority = authority.encode(&#8216;idna&#8217;)</em> to <em>authority = authority.encode(&#8216;utf-8&#8242;)</em>. This effectively changes the codec under which you&#8217;ll be dealing with the unicode strings. Again, it&#8217;s not a clean modification and you can potentially run into issues doing this, but in my experience, all seems to have been working fine so far.</li>
</ul>
<ul>
<li>
The next problem will be SSL authentication, which, again, is tripping IronPython&#8217;s SSL module. To fix this, open the <strong>shotgun.py</strong> module and on line 73 change <em>NO_SSL_VALIDATION = False</em> to <em>NO_SSL_VALIDATION = True</em>.
</li>
</ul>
<ul>
<li>Then IronPython will still be complaining about a module called <strong>zlib</strong>, which is a compiled CPython module that cannot be used inside IronPython. Luckily there is a C# variant based on the same code as zlib. Download it from <a href="https://bitbucket.org/jdhardy/ironpythonzlib/downloads">Jeff Hardy&#8217;s bitBucket site</a> and place it somewhere where IronPython can source it (i.e. within your PATH). I put it in a recommended folder called DLLs directly in the IronPython folder. This means that the IPy interpreter will source the DLL automatically, but bear in mind you&#8217;ll have to add a reference to this library manually in your scripts when run outside the shell.</li>
</ul>
<ul>
<li>
The easiest way is to add these two lines in your imports into the shotgun.py module:</p>
<pre>import clr
clr.AddReference("IronPython.Zlib")</pre>
</li>
</ul>
<p>This way you&#8217;ll make sure the zlib module required by some of the shotgun modules is going to be readily available.</p>
<p>That&#8217;s it! Let&#8217;s test it. <img src='http://blog.duber.cz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Oh, one more thing, I&#8217;ve found these Python variant couples to be perfectly compatible and working in production: IronPython 2.6.2 and CPython 2.6 and for clr4 folks IronPython 2.7.1 and Python 2.7.2.</p>
<p>IronPython 2.7.1:<br />
<a href="http://blog.duber.cz/wp-content/uploads/ipy_271_shotgun_308api.png" rel="lightbox[993]"><img src="http://blog.duber.cz/wp-content/uploads/ipy_271_shotgun_308api_thumbnail.png" alt="IronPython 2.7.1" title="IronPython 2.7.1" width="560" height="248" class="alignnone size-thumbnail wp-image-994" /></a></p>
<p>duberPython (utilizing IronPython engine 2.6.2):<br />
<a href="http://blog.duber.cz/wp-content/uploads/duberPython_shotgun_308api.png" rel="lightbox[993]"><img src="http://blog.duber.cz/wp-content/uploads/duberPython_shotgun_308api_thumbnail.png" alt="duberPython" title="duberPython" width="560" height="149" class="alignnone size-thumbnail wp-image-995" /></a></p>
<p>I hope this helps you out with your IronPython and Shotgun scripting and I&#8217;m certainly looking forward to the new versions of the Shotgun API. <img src='http://blog.duber.cz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>A huge thank you to the <a href="https://support.shotgunsoftware.com/home">Shotgun Software support</a> team!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.duber.cz/software/calling-shotgun-api-v3-0-8-from-ironpython/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shotgun and 3ds Max, practical example</title>
		<link>http://blog.duber.cz/software/shotgun-and-3ds-max-practical-example</link>
		<comments>http://blog.duber.cz/software/shotgun-and-3ds-max-practical-example#comments</comments>
		<pubDate>Mon, 05 Dec 2011 22:50:24 +0000</pubDate>
		<dc:creator>loocas</dc:creator>
				<category><![CDATA[dotNET]]></category>
		<category><![CDATA[maxscript]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[technical]]></category>

		<guid isPermaLink="false">http://blog.duber.cz/?p=943</guid>
		<description><![CDATA[Here&#8217;s a video demonstrating the power and practical usage of Shotgun (data) brought over to 3ds Max natively via our Python plugin, duberPython.]]></description>
			<content:encoded><![CDATA[<p><img src="" /></p>
<p>Here&#8217;s a video demonstrating the power and practical usage of Shotgun (data) brought over to 3ds Max natively via our Python plugin, <a href="http://blog.duber.cz/?s=duberpython">duberPython</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.duber.cz/software/shotgun-and-3ds-max-practical-example/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://blog.duber.cz/wp-content/gallery/vids/duberPython_Shotgun_demo.mp4" length="58014303" type="video/mp4" />
		</item>
		<item>
		<title>RVIO in a daily use</title>
		<link>http://blog.duber.cz/software/rvio-in-a-daily-use</link>
		<comments>http://blog.duber.cz/software/rvio-in-a-daily-use#comments</comments>
		<pubDate>Tue, 01 Nov 2011 10:53:06 +0000</pubDate>
		<dc:creator>loocas</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[RV]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[technical]]></category>

		<guid isPermaLink="false">http://blog.duber.cz/?p=919</guid>
		<description><![CDATA[Every TD knows that command line tools are among the most powerful in their arsenal of tricks and secrets. I want to mention RVIO, as today it saved me quite a lot of time (again), which is absolutely key when a deadline is coming. My client requested a minor tweak of animation (a lip sync, [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.duber.cz/wp-content/uploads/rvio_cmd_banner.png" alt="RVIO" title="RVIO" width="560" height="100" class="alignnone size-full wp-image-920" /></p>
<p>Every TD knows that command line tools are among the most powerful in their arsenal of tricks and secrets.</p>
<p>I want to mention <a href="http://www.tweaksoftware.com/products/rvio-sequence-converter">RVIO</a>, as today it saved me quite a lot of time (again), which is absolutely key when a deadline is coming.</p>
<p>My client requested a minor tweak of animation (a lip sync, to be concrete) on an almost finished shot. So, the general approach would be to do the change, have the animation data go through the pipeline and at the end have the finished frames ready to be loaded in an existing edit, which then gets rendered out and the final result gets showed to the client.</p>
<p>All fine, until you realize your render farm is completely full with other shots, so you have to skip the &#8220;beauty&#8221; pass rendering and only present the client with a, somehow, polished preview directly from your 3D package, which isn&#8217;t the <em>safest</em> way, trust me. But this client is great and understands that what he sees is actually only a preview of the animation.</p>
<p>So, the last piece of puzzle to solve is to get the preview assembled with additional layers of information (such as frame number, shot name etc&#8230;), basically a slightly customized overlay. All this sounds nice and simple, you just open up (in my case) Premiere Pro, swap the layers, render out the portion you need and be done with it.</p>
<p>But this certainly isn&#8217;t the <em>TD way</em>. <img src='http://blog.duber.cz/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><span id="more-919"></span></p>
<p>Fortunately for me, I&#8217;d purchased a license of RVIO some time ago, so I have an extremely powerful and versatile tool in my arsenal of VFX software that just <strong>gets the job done</strong>, no matter what.</p>
<p>The problem with the Premiere Pro approach, actually, there are two problems: 1) my lazyness and 2) the time it actually takes to get it done. Besides, this way you are also exposing your project to errors. You might accidently save the project and when you least need it, it&#8217;ll jump back at you and you&#8217;ll have to be dealing with this fuck-up in the least desirable time &#8211; the minute before the deadline.</p>
<p>So, the easiest approach for such a trivial task would be <em>something</em> that allows you to combine an image sequence with your sound file and spits out a movie file with the correct size, color, the whole package, basically.</p>
<p>RVIO is such a tool and it is aimed at TDs and people who aren&#8217;t afraid of using the command line (which you certainly should NOT be as it is the most powerful, fastest and actually easiest way of getting things done, even in 2011). It allows for both simple and extremely complex image, movie and sound file conversions. See the <a href="http://www.tweaksoftware.com/products/rvio-sequence-converter">RVIO site</a> for more info on that.</p>
<p>So, what is the concrete example I&#8217;m talking about? Something as simple as delivering a correct file and presenting it properly to the client can be a complex process in a large pipeline. In my case, as I&#8217;m a fairly small boutique, what I needed to do was to take an image sequence of the fixed animation, place it in an existing timeline (effectively replacing the previous, fully rendered, version), setting up markers for in-out points, setting up the export settings, correct file name, correct video and audio codecs, correct output size etc&#8230; Then have it exported, review the file, upload it to our server and present the link to our proprietary review site for clients to the client.</p>
<p>This entire process isn&#8217;t too difficult to manage in five to ten minutes, but presents a bit of a security threat that I mentioned above and also isn&#8217;t very flexible or comfortable. Sure, for people that can only deal with their software via nice and polished user interfaces, this is the only way to get the job done, but for a TD, there is a much smarter, faster and cooler way. <img src='http://blog.duber.cz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Here come the super-powers of RVIO. It&#8217;s strictly a command line tool. But to perform all (and many more!) tasks that I just mentioned, all you need is this line of code:</p>
<pre>rvio [ "inputFrameSequence_12-125#.tif" "inputSoundFile.wav" ] -codec avc1
-outkeyinterval 20 -outdatarate 1000000 -outgamma 0.85 -outres 1024 576
-audiocodec aac -o "outputMovieFile.mp4"</pre>
<p>That&#8217;s it! See how awesomely simple, fast, effective and cool this is?! <img src='http://blog.duber.cz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Now, this was just a command line command you execute directly and you get a outputMovieFile.mp4 in the correct format, the correct in and out of the animation, correct sound and everything between. However, imagine what you can do with this! If you know Python, or on Windows, preferrably, IronPython, you can do WONDERS!</p>
<p>I&#8217;ve tied RVIO with <a href="http://www.shotgunsoftware.com/">Shotgun</a> via IronPython so that I can do very easily, effectively and super fast deliveries to our client on a project with about 120+ shots. It&#8217;s not a huge project, though, but the sheer number of shots definitely calls for scripting. There is no way I&#8217;d be sitting at 4am at the computer and manually editing and converting 120+ shots to a desired format for review whenever there is a change in the animation or compositing! That&#8217;d be a suicide and a complete waste of resources.</p>
<p>What I did was calling a loop on all the shot folders where our final comp files were being stored, picked the rendered files and fed them to RVIO with a few parameters set specifically for that project, similar to what I just showed you above, pulling a few variables from <a href="http://www.shotgunsoftware.com/">Shotgun</a>, such as in and out cuts, shot name and other data. Then it automatically takes the resulting movie files and uploads them to our review system via FTP. That was it! With about fifty lines of code I achieved a task that&#8217;d take me at least three hours of intensive file hassling and messing around! All of this then takes about ten minutes to process, which is perfect for a coffee break. <img src='http://blog.duber.cz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Besides, it&#8217;s recycable, in a sense that when there is something changed in any of the shots and we need to re-deliver, I just run the script again.</p>
<p>This is what I love about my work! The effectivity, productivity and the cool factor, of course. <img src='http://blog.duber.cz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.duber.cz/software/rvio-in-a-daily-use/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>duberPython runs the latest IronPython 2.7.1 without issues!</title>
		<link>http://blog.duber.cz/3ds-max/duberpython-runs-the-latest-ironpython-2-7-1-without-issues</link>
		<comments>http://blog.duber.cz/3ds-max/duberpython-runs-the-latest-ironpython-2-7-1-without-issues#comments</comments>
		<pubDate>Thu, 27 Oct 2011 17:06:10 +0000</pubDate>
		<dc:creator>loocas</dc:creator>
				<category><![CDATA[3ds Max]]></category>
		<category><![CDATA[maxscript]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[showcase]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[technical]]></category>

		<guid isPermaLink="false">http://blog.duber.cz/?p=914</guid>
		<description><![CDATA[Just a quick shout about the compatibility of duberPython and the latest and greatest IronPython 2.7.1 release (released a couple of days ago). All working smoothly and quickly, as expected. Should you need more info on duberPython or what we&#8217;re doing with it and Shotgun or Tactic, just drop me a line and I&#8217;ll be [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.duber.cz/wp-content/uploads/envVersion.png" alt="duberPython" title="duberPython" width="560" height="300" class="alignnone size-full wp-image-915" /></p>
<p>Just a quick shout about the compatibility of duberPython and the latest and greatest IronPython 2.7.1 release (released a couple of days ago). All working smoothly and quickly, as expected. <img src='http://blog.duber.cz/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Should you need more info on duberPython or what we&#8217;re doing with it and <a href="http://shotgunsoftware.com/">Shotgun</a> or <a href="http://www.southpawtech.com/">Tactic</a>, just drop me a line and I&#8217;ll be more than happy to show you how cool duberPython is. <img src='http://blog.duber.cz/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.duber.cz/3ds-max/duberpython-runs-the-latest-ironpython-2-7-1-without-issues/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scripting Deadline Event plugins, tutorial</title>
		<link>http://blog.duber.cz/technical/scripting-deadline-event-plugins-tutorial</link>
		<comments>http://blog.duber.cz/technical/scripting-deadline-event-plugins-tutorial#comments</comments>
		<pubDate>Sun, 24 Jul 2011 19:07:57 +0000</pubDate>
		<dc:creator>loocas</dc:creator>
				<category><![CDATA[deadline]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[videotutorials]]></category>

		<guid isPermaLink="false">http://blog.duber.cz/?p=855</guid>
		<description><![CDATA[People have asked me how to actually write a plugin for Deadline that will automatically submit a Nuke scene (or any other, for that matter), so I put together a quick tutorial showing you just that.]]></description>
			<content:encoded><![CDATA[<p>People have asked me how to actually write a plugin for Deadline that will automatically submit a Nuke scene (or any other, for that matter), so I put together a quick tutorial showing you just that. <img src='http://blog.duber.cz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><img src="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.duber.cz/technical/scripting-deadline-event-plugins-tutorial/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://blog.duber.cz/wp-content/gallery/vids/scriptingDeadlineEventPlugins.mp4" length="136176118" type="video/mp4" />
		</item>
		<item>
		<title>Shotgun and 3ds Max integration preview</title>
		<link>http://blog.duber.cz/3ds-max/shotgun-and-3ds-max-integration-preview</link>
		<comments>http://blog.duber.cz/3ds-max/shotgun-and-3ds-max-integration-preview#comments</comments>
		<pubDate>Thu, 28 Apr 2011 23:01:26 +0000</pubDate>
		<dc:creator>loocas</dc:creator>
				<category><![CDATA[3ds Max]]></category>
		<category><![CDATA[maxscript]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[showcase]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[technical]]></category>

		<guid isPermaLink="false">http://blog.duber.cz/?p=780</guid>
		<description><![CDATA[If you&#8217;re interested in a live demo or more information about the duber Python and Shotgun integration in 3ds Max, drop me a line via e-mail at: ldubeda[at]duber.cz]]></description>
			<content:encoded><![CDATA[<p><img src="" /></p>
<p>If you&#8217;re interested in a live demo or more information about the duber Python and Shotgun integration in 3ds Max, drop me a line via e-mail at: ldubeda[at]duber.cz</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.duber.cz/3ds-max/shotgun-and-3ds-max-integration-preview/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://blog.duber.cz/wp-content/gallery/vids/Shotgun_Integration_Preview.mp4" length="32328407" type="video/mp4" />
		</item>
		<item>
		<title>Using Dictionary data types in 3ds Max</title>
		<link>http://blog.duber.cz/software/using-dictionary-data-types-in-3ds-max</link>
		<comments>http://blog.duber.cz/software/using-dictionary-data-types-in-3ds-max#comments</comments>
		<pubDate>Thu, 28 Apr 2011 19:43:44 +0000</pubDate>
		<dc:creator>loocas</dc:creator>
				<category><![CDATA[maxscript]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[technical]]></category>

		<guid isPermaLink="false">http://blog.duber.cz/?p=770</guid>
		<description><![CDATA[I&#8217;ve had a few customers and clients asked me specifically about getting Dictionaries from 3ds Max to Python using our 3ds Max Python plugin, but I wasn&#8217;t able to answer with an elegant or productive way of handling these data types in the MAXScript environment. Until recently, I&#8217;ve been handling Dictionaries two ways: String parsing [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had a few customers and clients asked me specifically about getting Dictionaries from 3ds Max to Python using our <a href="http://blog.duber.cz/3ds-max/duberpython-features-demonstration">3ds Max Python plugin</a>, but I wasn&#8217;t able to answer with an elegant or productive way of handling these data types in the MAXScript environment.</p>
<p>Until recently, I&#8217;ve been handling Dictionaries two ways:</p>
<ol>
<li>String parsing (i.e. a very primitive way of handling foreign data types, not really recommended)</li>
<li>Manual wrapping (i.e. passing in a List or Array object and converting it back to a Dictionary object)</li>
</ol>
<p>String parsing is the worst possible way of handling such an issue. It&#8217;s very cumbersome, highly unintuitive and with MAXScript string capabilities, extremely difficult. Manual wrapping, on the other hand, is rather more elegant, faster and you can use other, known, data types to construct your future Dictionary and have that converted in Python natively. The down side is, you have to be very careful with the way you&#8217;re handling the future Dictionary. The thing is, only a tuple of list pairs can be successfully converted to a Dictionary in Python. This is a bit limiting as we don&#8217;t have any specific way to tell what is a Tuple and what is a List in our Python implementation in MAXScript as there are no such data types available. So, what I did was I had an Array sent to Python (an actual .NET Array object, by the way) I had that converted first to a Tuple, which is pretty straight forward and then have that converted to a Dictionary. Worked fine, but it was a bit difficult to construct more complex Dictionaries, especially nested Dictionaries, in MAXScript.</p>
<p><span id="more-770"></span></p>
<p>Recently I was writing some .NET code and I bumped into Collections namespace. I then investigated further the Hashtable objects and realized I could substitute Dictionaries in MAXScript with Hashtables using .NET classes and objects! Obviously, again, it&#8217;s not as elegant as native Python, but it&#8217;s closer than manual wrapping of Lists and Arrays!</p>
<p>All you need to do is instantiate a Hashtable object in MAXScript:</p>
<pre>HT = dotNetObject "System.Collections.Hashtable"</pre>
<p>and then you can call the .Add() method for adding the Key Value pairs! Pretty cool! Also, you can access the Values or Keys similarly to Python&#8217;s Dictionaries:</p>
<pre>HT.Add "Key" "Value"
HT.Item["Key"]</pre>
<p>This is far more productive and intuitive than my previous methods!</p>
<p>Also, then you can pass the Hashtable object directly to IronPython and have it converted to the native Dictionary object using the dict() method, without any issues! Again, this is a much straight forward way of doing such a, rather, complex data type conversion.</p>
<p>I&#8217;m currently implementing this approach to my Shotgun wrapper I use with our Python plugin. All seems to be working perfectly fine!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.duber.cz/software/using-dictionary-data-types-in-3ds-max/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Direct MD5 checksum object comparison behavior in IronPython prior to version 2.7</title>
		<link>http://blog.duber.cz/misc/direct-md5-checksum-object-comparison-behavior-in-ironpython-prior-to-version-2-7</link>
		<comments>http://blog.duber.cz/misc/direct-md5-checksum-object-comparison-behavior-in-ironpython-prior-to-version-2-7#comments</comments>
		<pubDate>Thu, 24 Mar 2011 22:35:55 +0000</pubDate>
		<dc:creator>loocas</dc:creator>
				<category><![CDATA[miscellaneous]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[technical]]></category>

		<guid isPermaLink="false">http://blog.duber.cz/?p=713</guid>
		<description><![CDATA[I&#8217;ve recently bumped into a strange problem that kept on crashing on me on my Virtual machine testing my latest IronPython script. The problem was that a dircet MD5 object comparison of files originating from the same source, i.e.: from System.Security.Cryptography import MD5CryptoServiceProvider md5 = MD5CryptoServiceProvider() file1crc = md5.CreateHashs(file1Stream) file2crc = md5.CreateHashs(file2Stream) file1crc == file2crc [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently bumped into a strange problem that kept on crashing on me on my Virtual machine testing my latest IronPython script.</p>
<p>The problem was that a dircet MD5 object comparison of files originating from the same source, i.e.:</p>
<p><code>from System.Security.Cryptography import MD5CryptoServiceProvider<br />
md5 = MD5CryptoServiceProvider()</p>
<p>file1crc = md5.CreateHashs(file1Stream)<br />
file2crc = md5.CreateHashs(file2Stream)</p>
<p>file1crc == file2crc</code></p>
<p>returned, in IronPython 2.7, expected <em>True</em>, but in earlier versions, I got <em>False</em>.</p>
<p>This is the actual checksum converted to a string, so you can see they really are both identical (though computed from different sources):</p>
<p><code>>>> System.BitConverter.ToString(destMD5)<br />
'2A-74-7D-5F-CC-FD-B6-75-57-C0-30-28-E4-BB-A4-0C'<br />
>>> System.BitConverter.ToString(srcMD5)<br />
'2A-74-7D-5F-CC-FD-B6-75-57-C0-30-28-E4-BB-A4-0C'</code></p>
<p>Interestingly enough, when I compare the two strings, the result is <em>True</em>.</p>
<p>After an hour or so of experimentation, I had to re-write the script to compare the strings rather than the actual MD5 checksum objects directly, in order to make my script compatible in earlier versions of IronPython.</p>
<p>I still haven&#8217;t received an answer to this behavior on the IronPython public mailing list, so, I really don&#8217;t have an answer as to whether this is a bug or some kind of a feature that isn&#8217;t clear to me. I&#8217;ll report back when I get more info.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.duber.cz/misc/direct-md5-checksum-object-comparison-behavior-in-ironpython-prior-to-version-2-7/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Still no Visual Studio goodness for me</title>
		<link>http://blog.duber.cz/opinions/still-no-visual-studio-goodness-for-me</link>
		<comments>http://blog.duber.cz/opinions/still-no-visual-studio-goodness-for-me#comments</comments>
		<pubDate>Thu, 24 Mar 2011 13:18:13 +0000</pubDate>
		<dc:creator>loocas</dc:creator>
				<category><![CDATA[opinions]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.duber.cz/?p=699</guid>
		<description><![CDATA[Once again, after the promising IronPython Tools for Visual Studio 2010 were included in the installation of IronPython 2.7, I decided to give Visual Studio Express another shot. Well, VisualStudio Integrated Shell, to be exact, as Express doesn&#8217;t specifically support IronPython. I&#8217;m fairly inexperienced with Visual Studio and also I don&#8217;t code very large script/programming [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.duber.cz/wp-content/uploads/visual_studio_2010_banner.png" alt="Visual Studio 2010" title="Visual Studio 2010" width="560" height="200" class="alignnone size-full wp-image-702" /></p>
<p>Once again, after the promising <a href="http://ironpython.net/tools/">IronPython Tools for Visual Studio 2010</a> were included in the installation of <a href="http://ironpython.codeplex.com/releases/view/54498">IronPython 2.7</a>, I decided to give <a href="http://www.microsoft.com/visualstudio/en-us/">Visual Studio Express</a> another shot. Well, VisualStudio Integrated Shell, to be exact, as Express doesn&#8217;t specifically support IronPython.</p>
<p>I&#8217;m fairly inexperienced with Visual Studio and also I don&#8217;t code very large script/programming projects, thus a full Visual Studio suite is a complete overkill for my needs, however, I really like Instellisense and Autocomplete features it offers, but mainly I really dig the Forms or XAML designers.</p>
<p><span id="more-699"></span></p>
<p><a href="http://blog.duber.cz/wp-content/uploads/visual_studio.png" rel="lightbox[699]"><img src="http://blog.duber.cz/wp-content/uploads/visual_studio.thumbnail.png" alt="Visual Studio 2010" title="Visual Studio 2010" width="560" height="300" class="alignnone size-thumbnail wp-image-707" /></a></p>
<p>So far, I&#8217;ve only used <a href="http://www.scintilla.org/SciTE.html">SciTE</a> and toyed a bit with SharpDevelop. For 90% of my scripting work (connecting to provided APIs and gluing tools together), where I don&#8217;t need to design any GUI, I&#8217;m just fine with SciTE&#8217;s capabilities. It has Python syntax highlighting, it is extremely customizable, it is the same editor found in 3ds Max (I wish there was a maxscript lexer!) and it&#8217;s very lightweight. Also, it&#8217;s free. <img src='http://blog.duber.cz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Anyways, I installed VS Integrated Shell and IronPython 2.7. All worked just fine, no issues, no special steps needed for the two to work together, which is fantastic. I opened up Visual Studio and started some coding. Immediately I simply fell in love with Intellisense. It&#8217;s just awesome! Really. The WPF or WinForms designers are absolutely fantastic and generally, the whole .NET support is (naturally) flawless. I&#8217;m not much of a debugger guy (again, I don&#8217;t code huge projects), I&#8217;m better off with some print functions here and there for testing, but I hear the debuggers are also fine. Lastly, the entire integration of .NET, IronPython shell, the script editor, managers, designers etc&#8230; everything is just pure gold (from a SciTE user point of view).</p>
<p>However, very soon you bump into tiny quirks that may or may not bother you. For me it&#8217;s essentially three, minor, things:</p>
<ol>
<li>The error highlight feature (the wavy underline) will start annoy you very soon.</li>
<li>No Tab/Indent guides as I was used to from SciTE.</li>
<li>No current line highlighting.</li>
</ol>
<p>That&#8217;s pretty much it! I know these things are nothing, to some, but I just can&#8217;t stand them. But if you don&#8217;t mind these, definitely go check <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=8e5aa7b6-8436-43f0-b778-00c3bca733d3">Visual Studio Integrated Shell</a> (required for IronPython Tools), it&#8217;s a fantastic IDE and if you&#8217;re into a much more hard-core coding, you&#8217;ll love its vast options and features.</p>
<p><a href="http://blog.duber.cz/wp-content/uploads/scite.png" rel="lightbox[699]"><img src="http://blog.duber.cz/wp-content/uploads/scite.thumbnail.png" alt="SciTE" title="SciTE" width="560" height="300" class="alignnone size-thumbnail wp-image-707" /></a></p>
<p>For me, I&#8217;ll stick with SciTE for now as it has been the editor of choice of mine for years and has never failed me. Of course I&#8217;ll be using Visual Studio for the WPF design, that&#8217;s just priceless! But then again I can simply design the GUI, save a XAML and reference that in any other IDE of choice for the &#8220;gluing&#8221; part.</p>
<p>Anyways, if the dev team fixes these three minor things, I&#8217;ll be very happy to use Visual Studio full time for my IronPython scripting, it&#8217;s just that good. <img src='http://blog.duber.cz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.duber.cz/opinions/still-no-visual-studio-goodness-for-me/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>duberPython features demonstration!</title>
		<link>http://blog.duber.cz/3ds-max/duberpython-features-demonstration</link>
		<comments>http://blog.duber.cz/3ds-max/duberpython-features-demonstration#comments</comments>
		<pubDate>Thu, 04 Mar 2010 15:16:28 +0000</pubDate>
		<dc:creator>loocas</dc:creator>
				<category><![CDATA[3ds Max]]></category>
		<category><![CDATA[maxscript]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[technical]]></category>

		<guid isPermaLink="false">http://blog.duber.cz/?p=457</guid>
		<description><![CDATA[I&#8217;m trhilled to be able to finally showcase, at least, some of our very own Python implementation into 3ds Max! First off, our primary reason for writing our own, proprietary, Python connection to 3ds Max is Tactic by Southpaw Technology. An awesome asset management system entirely written in Python that I decided to invest in [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://blog.duber.cz/wp-content/uploads/duberpython_banner.png' alt='duberPython banner' /></p>
<p>I&#8217;m trhilled to be able to finally showcase, at least, some of our very own Python implementation into 3ds Max!</p>
<p>First off, our primary reason for writing our own, proprietary, Python connection to 3ds Max is <a href="http://southpawtech.com/tactic.html">Tactic by Southpaw Technology</a>. An awesome asset management system entirely written in Python that I decided to invest in and integrate our tools and software packages into. Another reason for this connection, later came up, was the need for writing much more complex scripts with complex GUIs, since, as you probably know, a few functional lines of code are hardly enough in a modern, efficient, VFX production of today. <img src='http://blog.duber.cz/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>The heart of our Python integration is <a href="http://www.microsoft.com/NET/">dotNET from Microsoft</a>. I can&#8217;t express myself enough how much I appretiate this framework! The brain of our Python integration is <a href="http://www.ironpython.net/">IronPython</a>. Also a product from Microsoft, completely open source and free, which are two very important aspects for any pipeline tool in any production facility of any size. Not the price as much as the availability of the software. And with IronPython and Microsoft, I am certain that this piece of software will be around for years!</p>
<p><span id="more-457"></span></p>
<p>So, what have we done?</p>
<ul>
<li>We&#8217;ve developed a bridge that connects MAXScript and Python via dotNET.</li>
<li>The bridge converts most of native Python and MAXScript data types to and from one another.</li>
<li>We&#8217;ve implemented several, custom, methods in Python that allow us to directly communicate with 3ds Max via MAXScript.</li>
<li>We&#8217;ve also implemented error reporting so that when an error is thrown in Python, it&#8217;ll return the exception in MAXScript for debuging.</li>
<li>Everything is based on dotNET and written in C#.</li>
<li>The best part? Our Python bridge is completely platform and 3ds Max version independent!</li>
</ul>
<p>Let me talk about the custom Python methods first. We&#8217;ve incorporated a class called <strong>mxsCon</strong>, that stores several methods for direct communication with 3ds Max as well as a variable<br />
that stores passed arguments from MAXScript to Python for greater flexibility, especially when executing short code snippets.</p>
<p>The initial design meant to provide a way of directly running Python code from within MAXScript. However, with more complex tools needed nowdays, this proved to be insufficient and thus we&#8217;ve developed a way of executing more complex Python scripts written externally using IronPython. This works perfectly well if you plan on using 3ds Max&#8217;s interpreter and just want to pass values around MAXScript and Python. This is perfectly efficitent and enough for writing really complex tools based on Python. In our case, it&#8217;s the connection to Tactic.</p>
<p>However, later, it occured to me that since we have most of the hard work done, why not bring everything over to the Python side. Since Python is such a great and powerful language, why bother with MAXScript! So we developed another method for executing MAXScript code directly within Python scripts and have the result, evaluated in MAXScript, be passed back to Python. IronPython that is. Since all the value conversions had already been done, this proved to be an extremely powerful and efficient way of writing very complex tools, now even, with very complex GUIs. Since everything is based on dotNET, we can utilise IronPython and some of the IDEs available for super quick GUI development. I used <a href="http://www.icsharpcode.net/OpenSource/SD/">SharpDevelop</a>, an open source IDE for writing dotNET applications, for all my GUI and code stuff. Then I just hook up MAXScript commands that I pass Python values to in order to perform some actions in 3ds Max, like opening a file from our server stored in Tactic. Or, create objects and list them in a ListView. Or even write a direct 3ds Max &#8211; Maya translator! Why not? <img src='http://blog.duber.cz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Anyways, here are the methods and their purpose in 3ds Max:</p>
<ul>
<li>Python.run( &#60;string&#62; ) &#8212; will execute a Python script wrapped in double quotes (effectively a string).</li>
</ul>
<p>Example:</p>
<pre>
Python.run
(
	"import sys
	mxsCon.setResult( sys.version )"
)
</pre>
<p></br><br />
In this case, Python.run() will return whatever the mxsCon.setResult() will pass to it (more on that later).</p>
<ul>
<li>Python.runFromFile( &#60;string&#62; ) [ args:#() ] &#8212; will execute a Python script stored in an external file and alternatively pass it custom arguments.</li>
</ul>
<p>Example:</p>
<pre>
Python.runFromFile @"C:\myPythonScript.py" args:#( 10., true, #(1,2,3), "some string" )
</pre>
<p></br><br />
In Python, you&#8217;ll have to catch the passed arguments in order to use them, however the conversion of the data types will be done automatically for you.</p>
<ul>
<li>Python.inspect( &#60;data type&#62; ) &#8212; this method will inspect what data type you passed to it and how it will convert it to Python.</li>
<li>Python.getError() &#8212; this method returns the last unhandled exception in Python code.</li>
<li>Python.setVerbosity( &#60;int&#62; ) &#8212; allows you to set the level of verbosity for error reporting.</li>
<li>Python.getVerbosity() &#8212; retreives the level of verbosity you currently use.</li>
<li>Python.resetPy() &#8212; a very useful method for resetting our bridge residing in memory in case you&#8217;ve changed something radical in the source code etc&#8230;</li>
</ul>
<p>And here are the custom methods developed in C# for IronPython use in the scripts. These only exist when run via our Pythoner.dll module. If you run the Python scripts without Pythoner, you&#8217;ll have to handle their lack of presence. I&#8217;ve done this via a custom class that I import in the scripts I use. This is extremely flexible since when I run the code outside of 3ds Max, I can still use its functionality without having to deal with error handlers all over the place.</p>
<ul>
<li>mxsCon.setResult( &#60;data&#62; ) # this method will return whatever it encapsulates directly to 3ds Max as well as in Python should you need to work with it later in the script.</li>
</ul>
<p>Example:</p>
<pre>
import math

def myFunc( arg ):
	sum = arg + 100.
	return mxsCon.setResult( [arg, sum] )

if __name__ == '&#60;module&#62;':
	myFunc( math.pi )
</pre>
<p></br><br />
The myFunc function will not only return a List of whatever you pass to it as well as the result of addition, but it&#8217;ll also pass this List directly to MAXScript for later use in 3ds Max.</p>
<ul>
<li>mxsCon.getResult() # this method will only return the last value stored in memory using the .setResult() method. Useful for later usage in Python.</li>
<li>mxsCon.convert( &#60;data&#62; ) # this method will convert the input data types from Python to MAXScript compatible data types, but will return then wrapped as a string. This<br />
may be useful for other usage reasons. I used it for debugging or printing values in Python in MAXScript format.</li>
<li>mxsCon.execute( &#60;data&#62; ) # here&#8217;s where the magic happens. This method is quite complex. It not only evaluates whatever is passed to it in a String format, but it&#8217;ll also wait for the result from MAXScript and return it within Python. Another, very cool, feature of this method is similar to String formatting capabilities known from Python.</li>
</ul>
<p>Some examples of the mxsCon.execute() method:</p>
<pre>
# assume here's a ton of complex Python code that invokes this method
returnedVal = mxsCon.execute( r'Box()' )
# will create a box in 3ds Max and return OK (converted to True) back to Python.

returnedVal = mxsCon.execute( r'getDir {0}', r'#scripts' )</pre>
<p>The .execute method will first evaluate its input into a single string,<br />
in this case: r&#8217;getDir #scripts&#8217;, in a similar fashion the .format method works in Python.<br />
Then it&#8217;ll execute the command in MAXScript and retun its output back to Python.<br />
The output, in this case, will be a string: &#8216;C:\Program Files\Autodesk\3ds Max 2009\scripts&#8217;</p>
<p><a href="http://blog.duber.cz/wp-content/gallery/vids/pythoner_demo/pythoner_demo.html"><img src="http://blog.duber.cz/wp-content/uploads/pythoner_sharpdevelop_demo.png" alt="duberPython Features Demo" title="duberPython Features Demo" width="560" height="350" class="aligncenter size-full wp-image-468" /></a></p>
<p>But, enought with the talk, see it for yourself in action in this short Windows.Forms demo. (clicking the image will take you to the video)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.duber.cz/3ds-max/duberpython-features-demonstration/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

