<?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>Technical Art for Games &#187; Maya Python</title>
	<atom:link href="http://adammechtley.com/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://adammechtley.com</link>
	<description>Tips, Tutorials, and Tools - by Adam Mechtley</description>
	<lastBuildDate>Wed, 14 Jul 2010 02:27:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>AM Tools 1.04</title>
		<link>http://adammechtley.com/2010/02/amtools-1-04/</link>
		<comments>http://adammechtley.com/2010/02/amtools-1-04/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 15:30:11 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[General Interest]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Command]]></category>
		<category><![CDATA[Maya]]></category>
		<category><![CDATA[Maya Python]]></category>
		<category><![CDATA[Node]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://adammechtley.com/?p=649</guid>
		<description><![CDATA[I just released a minor update to AM Tools that I thought was worth mentioning here. The only change is some refactoring in plug-in verification to ensure everything will work fine with versions of Maya older than 2010 on Windows. Previously, I was using the allNodeTypes command to verify the existence of plug-ins containing nodes. [...]]]></description>
			<content:encoded><![CDATA[<p>I just released a minor update to <a title="Download free AM Tools Maya Python package for rigging and games" href="../../../tools/maya/#Python_AMTools">AM Tools</a> that I thought was worth mentioning here. The only change is some refactoring in plug-in verification to ensure everything will work fine with versions of Maya older than 2010 on Windows. Previously, I was using the <a title = "Maya Python allNodeTypes command" href="../../../2009/12/problems-with-allnodetypes-command/">allNodeTypes command</a> to verify the existence of plug-ins containing nodes. While this command generally only needs to be called twice to make it work in old versions of Maya on OSX (and I believe Linux too), Windows users could get a Debug.dll error that would just prevent the script from working. Special thanks to <a title="The art of Sean Binder, 3D character artist" href="http://binderart.blogspot.com/">Sean Binder</a> and <a title="Website of Chad Dombrova, creator of Pymel project" href="http://www.chadrikvon.com/">Chad Dombrova</a> for helping me troubleshoot this!</p>
]]></content:encoded>
			<wfw:commentRss>http://adammechtley.com/2010/02/amtools-1-04/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AM Tools 1.03</title>
		<link>http://adammechtley.com/2010/02/am-tools-1-03/</link>
		<comments>http://adammechtley.com/2010/02/am-tools-1-03/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 09:38:58 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Maya Python]]></category>
		<category><![CDATA[Rigging]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Command]]></category>
		<category><![CDATA[Maya]]></category>
		<category><![CDATA[Node]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://adammechtley.com/?p=623</guid>
		<description><![CDATA[I just uploaded an update to my AM Tools package, which contains some new goodies. In addition to including the AM_Ribbon plug-in that I previewed previously, I have also included an AM_ExposeTransform node, which I will be discussing in an upcoming Autodesk MasterClass that I am doing with Ryan. This node, much like its counterpart [...]]]></description>
			<content:encoded><![CDATA[<p>I just uploaded an update to my <a title="Download free AM Tools Maya Python package for rigging and games" href="../../../tools/maya/#Python_AMTools">AM Tools package</a>, which contains some new goodies. In addition to including the AM_Ribbon plug-in that I previewed previously, I have also included an AM_ExposeTransform node, which I will be discussing in an upcoming Autodesk MasterClass that I am doing with <a title="Ryan Trowbridge's website" href="http://rtrowbridge.com/blog">Ryan</a>. This node, much like its counterpart in 3D Studio Max, outputs transformation data for an object with respect to another object. In addition to basics like translation, rotation, and distance, the node also allows you to compute the angle between arbitrary axes on the objects as well as an angle from the exposed object&#8217;s arbitrary axis to the reference object&#8217;s position. Take a look in the example file to get some ideas of how you might use it. Special thanks to my friend, <a title="The art of Sean Binder, 3D character artist" href="http://binderart.blogspot.com/">Sean Binder</a> of Raven Software, for providing me with the torso model.<br />
<span id="more-623"></span><br />
On top of these additions and the usual cleanup and bug fixes, I have made some further changes:</p>
<ul>
<li>In keeping with Maya convention and planning for a future merge of hip and shoulder constraint commands and nodes, the node names are now lowercase (am_hipConstraint and am_shoulderConstraint) and the version numbering scheme has been changed. Please take note if you have any Maya ASCII files containing these nodes.</li>
<li>I fixed some errors with the Insert Parents tool (the module and the command) that could arise from naming conflicts.</li>
<li>I have added debug support for MDagPath and MObject objects in API debug mode.</li>
<li>I have added some <a title="Source code documentation for AM Tools Maya Python package" href="../../../downloads/python/documentation/" target="_blank">source code documentation</a> online generated using doxygen. It&#8217;s pretty bare bones for now, but I hope to expand it in the future.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://adammechtley.com/2010/02/am-tools-1-03/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>New Plug-in Coming Soon: AM_Ribbon</title>
		<link>http://adammechtley.com/2010/02/new-plug-in-coming-soon-am_ribbon/</link>
		<comments>http://adammechtley.com/2010/02/new-plug-in-coming-soon-am_ribbon/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 03:54:58 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[General Interest]]></category>
		<category><![CDATA[Maya Python]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Command]]></category>
		<category><![CDATA[Marian]]></category>
		<category><![CDATA[Maya]]></category>
		<category><![CDATA[Node]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://adammechtley.com/?p=613</guid>
		<description><![CDATA[Things have been unusually hectic so far this year, and with GDC on the horizon it&#8217;s not looking to be much clearer for awhile. However, that doesn&#8217;t mean I haven&#8217;t found a way to make all of my different obligations overlap in some ways! I&#8217;ve been working a little bit as a consultant over the [...]]]></description>
			<content:encoded><![CDATA[<p>Things have been unusually hectic so far this year, and with GDC on the horizon it&#8217;s not looking to be much clearer for awhile. However, that doesn&#8217;t mean I haven&#8217;t found a way to make all of my different obligations overlap in some ways! I&#8217;ve been working a little bit as a consultant over the last few months to help out <a title="Indie game developer Infinite Ammo, creators of Marian" href="http://infiniteammo.ca/">Infinite Ammo</a> with an upcoming title: Marian.</p>
<p>During the course of my work on the project, I developed a new Python plug-in for Maya to help out with hair modeling. I will hopefully have a chance to deploy a new version of my free Python package soon that will include it, but in the meantime I thought I might share this video that Alec <a title="Making hair for Infinite Ammo's Marian: Adam's AM_Ribbon Maya Python plug-in for modeling hair from NURBS curves" href="http://infiniteammo.ca/blog/marian-mondays-maya-hair/">posted up on the IA website</a> where I show what the plug-in does. Hopefully some other folks out there will find it useful too!</p>
<p><object class ="video" width="425" height="344"><param name="movie" value="http://www.youtube.com/v/RzjsUQ3hrcs&#038;hl=en_US&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/RzjsUQ3hrcs&#038;hl=en_US&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://adammechtley.com/2010/02/new-plug-in-coming-soon-am_ribbon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MSyntax.enableQuery() and MSyntax.enableEdit() Break Object Parsing</title>
		<link>http://adammechtley.com/2010/01/msyntax-enablequery-and-msyntax-enableedit-break-object-parsing/</link>
		<comments>http://adammechtley.com/2010/01/msyntax-enablequery-and-msyntax-enableedit-break-object-parsing/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 06:41:26 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Maya Python]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Bugs]]></category>
		<category><![CDATA[Command]]></category>
		<category><![CDATA[Maya]]></category>
		<category><![CDATA[Undocumented]]></category>

		<guid isPermaLink="false">http://adammechtley.com/?p=573</guid>
		<description><![CDATA[In Maya, many built-in commands support any of three modes: create, edit, and query. Although it may not be immediately obvious, each of these modes has some particularities that set them apart, and which consequently require some extra effort on the part of the programmer to support. Maya does have some built-in support, which is [...]]]></description>
			<content:encoded><![CDATA[<p>In Maya, many built-in commands support any of three modes: create, edit, and query. Although it may not be immediately obvious, each of these modes has some particularities that set them apart, and which consequently require some extra effort on the part of the programmer to support. Maya does have some built-in support, which is presently only partially functional, so it is helpful to understand what it actually gains you to use it and work around its issues.<br />
<span id="more-573"></span><br />
Consider the <code>polySphere</code> command in MEL as an example:</p>
<p><strong>Create Mode:</strong></p>
<pre class="code">polySphere -n "newSphere" -r 5;
polySphere -n "otherSphere" -r 2;</pre>
<p>This creates two polygon sphere objects with the specified radii.</p>
<p><strong>Edit Mode:</strong></p>
<pre class="code">polySphere -e -r 1 newSphere otherSphere;</pre>
<p>Try though you might, edit mode only works on one object at a time. In this case, the edit will only be applied to newSphere.</p>
<p><strong>Query Mode:</strong></p>
<pre class="code">polySphere -q -r newSphere otherSphere;</pre>
<p>Just as is the case in edit mode, trying to specify multiple objects does not work—you can only query one object and one attribute at a time. Moreover, while the -r flag typically requires a decimal number, it requires no argument in query mode.</p>
<p>Fundamentally then, you as a programmer have two somewhat tedious problems to solve:</p>
<ol>
<li>How do I make my command throw an error in create/edit modes when there is no argument specified, but not in query mode?</li>
<li>How do I make my command require an object in edit and query modes, but not in create mode?</li>
</ol>
<p>In Complete Maya Programming, David Gould writes:</p>
<blockquote><p>The various modes are simply a convention used to describe when certain operations can and can&#8217;t be performed. Since the operations of creating, editing, and querying are so common, they have been given their own convention that all commands should follow. The standard convention is that if a command supports querying and editing, it adds the query and edit flags. These are defined in their short and long forms as -q/query and -e/edit, respectively. (334-335)</p></blockquote>
<p>Though this may have been the case at the time that Gould wrote, the API has included special functions for dealing with these modes at least as far back as version 8.5, so they are accessible to Python in all versions with official support. Specifically, the API includes <a href="http://download.autodesk.com/us/maya/2010help/API/class_m_syntax.html#410dd274062a09c42c4408800608fb3a">MSyntax.enableQuery()</a> and <a href="http://download.autodesk.com/us/maya/2010help/API/class_m_syntax.html#5ad50dd986e8ac8f1c230eefc0755f80">MSyntax.enableEdit()</a> as part of the syntax definition. Calling these functions in the syntax creator does a couple of things:</p>
<ol>
<li>Automatically adds the edit/query flags to the syntax definition, consequently permitting the use of the <a href="http://download.autodesk.com/us/maya/2010help/API/class_m_arg_parser.html#c686baf47950d9d1c8dfd4f18f88b00b">MArgParser.isEdit()</a> and <a href="http://download.autodesk.com/us/maya/2010help/API/class_m_arg_parser.html#63817d4c39c80aa7bc5eb92593de694a">MArgParser.isQuery()</a> functions</li>
<li>Automatically handles problem number 1 above by throwing descriptive errors<sup>&dagger;</sup> when <a href="http://download.autodesk.com/us/maya/2010help/API/class_m_arg_database.html#00f67ce6fa6f70b5be4803f6406afc0d">constructing the MArgDatabase object using the custom syntax</a></li>
</ol>
<p>However, there are a couple of problems. Typically, you can rely on your MArgDatabase construction to catch a variety of syntax errors and provide the user with valuable information.<sup>&dagger;</sup> For example, you can specify a minimum number of objects in your syntax creator that your command requires:</p>
<pre class="code">syntax.setObjectType(OM.MSyntax.kSelectionList, 1) # the command requires a minimum of 1 object</pre>
<p>Using this function call, you can reliably parse arguments in your <code>doIt()</code> function like this:</p>
<pre class="code">try:
    argData = OM.MArgDatabase(self.syntax(), args) # if this fails, it will raise its own exception...
except:
    pass # ...so we can just pass here
else:
    # Do cool stuff here</pre>
<p>&#8230;and get a descriptive error message in MEL<sup>&dagger;</sup> like this if you try to invoke the command without supplying any objects:</p>
<pre class="code">// Error: line 1: This command requires at least 1 argument(s) to be specified or selected;  found 0. //</pre>
<p>If you try to implement edit and query modes fully manually, as David Gould suggests, then this same technique still works. However, if you use <a href="http://download.autodesk.com/us/maya/2010help/API/class_m_syntax.html#410dd274062a09c42c4408800608fb3a">MSyntax.enableQuery()</a> or <a href="http://download.autodesk.com/us/maya/2010help/API/class_m_syntax.html#5ad50dd986e8ac8f1c230eefc0755f80">MSyntax.enableEdit()</a> to add these modes, then <strong>they will not respect your minimum object requirements!</strong> You can therefore run into problems where your command tries to work with an object in the selection list, but it does not exist because Maya&#8217;s built-in error-trapping did not catch the problem. Consequently, you need to add an additional, manual check when you parse your arguments. It could look something like this:</p>
<pre class="code"># parse the arguments
try:
	argData = OM.MArgDatabase(self.syntax(), args) # if this fails, it will raise its own exception...
except:
	pass # ...so we can just pass here
else:
	# manually confirm the object list
	sList = OM.MSelectionList()
	argData.getObjects(sList)
	if (argData.isEdit() or argData.isQuery()) and sList.length() is not 1:
		sys.stderr.write ("ERROR: This command requires exactly 1 argument to be specified or selected;  found 0.")
		sys.exit()
	# Do cool stuff here</pre>
<p>In the end, there is (at least presently) still some manual work required, though these simple function calls do go some way in helping you easily support additional command modes.</p>
<p><sup>&dagger;</sup>Presently, the Command Engine only throws descriptive syntax errors when a command is invoked from MEL. Invoking with a syntax error from Python simply prints no message, though the dysfunction will be contained.</p>
]]></content:encoded>
			<wfw:commentRss>http://adammechtley.com/2010/01/msyntax-enablequery-and-msyntax-enableedit-break-object-parsing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AM Tools 1.01</title>
		<link>http://adammechtley.com/2010/01/am-tools-1-01/</link>
		<comments>http://adammechtley.com/2010/01/am-tools-1-01/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 20:41:15 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Maya Python]]></category>
		<category><![CDATA[Rigging]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Command]]></category>
		<category><![CDATA[Maya]]></category>
		<category><![CDATA[Node]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://adammechtley.com/?p=562</guid>
		<description><![CDATA[I just uploaded version 1.01 of my AM Tools Python package today, which you can of course download from the Maya tools section. You can look through the files to see all of the changes that I made, but here are some of the major highlights. amInsertParents is now a Python command. I have therefore [...]]]></description>
			<content:encoded><![CDATA[<p>I just uploaded version 1.01 of my AM Tools Python package today, which you can of course <a title="Download AM Tools free - a Python package for rigging and Python API programming in Maya" href="../../../tools/maya/#Python_AMTools">download from the Maya tools section</a>. You can look through the files to see all of the changes that I made, but here are some of the major highlights.</p>
<ul>
<li><a title="Download amInsertParents Python command for Maya free" href="../../../tools/maya/#PythonPlugin_InsertParents"><strong>amInsertParents</strong> is now a Python command</a>. I have therefore retired the old MEL version.</li>
<li>Added <strong>API Debug Mode</strong> to menu. Enabling this mode overrides some Maya Python API classes for debugging. For this release, this mode overrides the __str__() functionality of MMatrix and MVector.</li>
<li>Substantially improved a number of utility functions for validating input.</li>
<li>Added validation for custom plug-ins.</li>
<li>Fixed some language-related bugs that existed for Maya 8.5.</li>
</ul>
<p>As always, please let me know if you have any problems or other feedback!</p>
]]></content:encoded>
			<wfw:commentRss>http://adammechtley.com/2010/01/am-tools-1-01/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
