<?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>chris-g.net &#187; Scripting</title>
	<atom:link href="http://www.chris-g.net/tag/scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chris-g.net</link>
	<description>Animation, 3D scripts and tools,  stuff and nonsense</description>
	<lastBuildDate>Thu, 14 Jul 2011 04:17:01 +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>Maya QT windows &#8211; inaccessible titlebars</title>
		<link>http://www.chris-g.net/2011/07/13/maya-qt-windows-inaccessible-titlebars/</link>
		<comments>http://www.chris-g.net/2011/07/13/maya-qt-windows-inaccessible-titlebars/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 01:26:18 +0000</pubDate>
		<dc:creator>chrisg</dc:creator>
				<category><![CDATA[Maya]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.chris-g.net/?p=347</guid>
		<description><![CDATA[The very first time you call a QT interface window (in a given user preferences set), it will draw the window so that the titlebar is offscreen. Problematic, because you can&#8217;t move the window, and it tends to freak your users out. This is because Maya doesn&#8217;t have a window pref for it yet, and ]]></description>
			<content:encoded><![CDATA[<p>The very first time you call a QT interface window (in a given user preferences set), it will draw the window so that the titlebar is offscreen. Problematic, because you can&#8217;t move the window, and it tends to freak your users out.</p>
<p>This is because Maya doesn&#8217;t have a window pref for it yet, and it&#8217;s default is brain meltingly stupid. Mac maya doesn&#8217;t suffer from this problem. Not sure about Linux. </p>
<p>So, use this function after you showWindow(). For example:</p>
<pre class="brush: python; title: ; notranslate">
uiFile = &quot;/path/to/uiFile.ui&quot;
rlDialog = cmds.loadUI(f=uiFile)
cmds.showWindow(rlDialog)
windowPosFix(rlDialog)

def windowPosFix(windowName):
    &quot;&quot;&quot;
    Fix for QT windows with no position information. If they are positioned at the very
    top left of screen, they are moved somewhere more sensible.

    @param windowName: Window Name
    @type windowName: String
    &quot;&quot;&quot;

    if cmds.window(windowName, query=True, exists=True):
        winPos = cmds.window(windowName, query=True, topLeftCorner=True)
        if winPos[0] &lt;=0 or winPos[1] &lt;=0:
            cmds.window(windowName, edit=True, topLeftCorner=[150,150])
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.chris-g.net/2011/07/13/maya-qt-windows-inaccessible-titlebars/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maya QT interfaces in a class</title>
		<link>http://www.chris-g.net/2011/06/24/maya-qt-interfaces-in-a-class/</link>
		<comments>http://www.chris-g.net/2011/06/24/maya-qt-interfaces-in-a-class/#comments</comments>
		<pubDate>Fri, 24 Jun 2011 05:01:10 +0000</pubDate>
		<dc:creator>chrisg</dc:creator>
				<category><![CDATA[Maya]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.chris-g.net/?p=327</guid>
		<description><![CDATA[Most tutorials online have suggested the way to fire commands inside QT interfaces launched in Maya (via cmds.loadUi &#8211; not involving pyQT) is to add a string property like: Pretty craptastical &#8211; it can only fire commands inside a specific python module, the name of which has to be known when you&#8217;re laying out your ]]></description>
			<content:encoded><![CDATA[<p>Most tutorials online have suggested the way to fire commands inside QT interfaces launched in Maya (via cmds.loadUi &#8211; not involving pyQT) is to add a string property like:</p>
<pre class="brush: python; title: ; notranslate">+command=&quot;myPythonInstance.pythonCommand()&quot;</pre>
<p>Pretty craptastical &#8211; it can only fire commands inside a specific python module, the name of which has to be known when you&#8217;re laying out your interface.</p>
<p>Ideally, we&#8217;d like to have our interface instanced from a python class. This would allow us, amongst other things, so have multiple, independant instances. However it seems that a &#8220;self&#8221; reference can&#8217;t get passed to an interface, which is what you&#8217;d reallly like to do.</p>
<pre class="brush: python; title: ; notranslate">+command=self.pythonCommand</pre>
<p>A (reasonably hacky) solution is to create the widget callbacks from inside our python class, after we&#8217;ve loaded the interface via cmds.loadUi(). </p>
<pre class="brush: python; title: ; notranslate">
import maya.cmds as cmds

class myUi(object):
	def __init__(self, *args):
		uiFile = '/path/to/uiFile.ui'
		rlDialog = cmds.loadUI(f=uiFile)
		cmds.showWindow(rlDialog)
		cmds.button( &quot;ovrAdd_btn&quot;, edit=True, command=self.overrideAdd )

	def overrideAdd(self, *args):
		print 'do something!'
</pre>
<p>Which is slightly better, but we&#8217;re still referring to our widget by a string name. This is problematic if you have multiple instances of this class &#8211; targeting &#8220;ovrAdd_btn&#8221; is going to get confusing. We need to find out exactly which control, in amongst the whole widget mess, is the one that we&#8217;ve spawned when we&#8217;re called cmds.loadUI().</p>
<p>Sadly, loadUI() doesn&#8217;t give us any help in this department. So, and here&#8217;s the hacky bit, we can trawl through the widgets to find those belonging to our class instance, store them in a dict and then we can refer back to them by a simplified name. Easy!</p>
<pre class="brush: python; title: ; notranslate">
import maya.cmds as cmds

def widgetPath(windowName, widgetNames):
    &quot;&quot;&quot;

    @param windowName: Window instance name to search
    @param widgetNames: list of names to search for
    &quot;&quot;&quot;

    returnDict = {}
    mayaWidgetList = cmds.lsUI(dumpWidgets=True)

    for widget in widgetNames:
        for mayaWidge in mayaWidgetList:
            if windowName in mayaWidge:
                if mayaWidge.endswith(widget):
                    returnDict[widget] = mayaWidge

    return returnDict

class myUi(object):
	def __init__(self, *args):
		uiWidgetList = ['ovrAdd_btn']

		uiFile = '/path/to/uiFile.ui'
		rlDialog = cmds.loadUI(f=uiFile)
		self.uiObjects = widgetPath(rlDialog, uiWidgetList)

		cmds.showWindow(rlDialog)

		cmds.button( self.uiObjects[&quot;ovrAdd_btn&quot;], edit=True, command=self.overrideAdd )

	def overrideAdd(self, *args):
		print 'do something!'
</pre>
<p>Trawling through Maya&#8217;s widget list isn&#8217;t particularly elegant, but you only have to do it once per class initialisation, so there isn&#8217;t too much of a cost. The advantage is that you can now have per-instance widget names.</p>
<p>Why not just use pyQT proper, you ask? Installing external dependencies isn&#8217;t always an option for our less techy brethren, or easily done in a studio-wide fashion. Using pyQT would be far better (and give all sorts of other benefits), but if you&#8217;re constrained to using vanilla maya / python, this seems to do the trick.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chris-g.net/2011/06/24/maya-qt-interfaces-in-a-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Name changed callbacks in maya/python/api</title>
		<link>http://www.chris-g.net/2011/06/15/name-changed-callbacks-in-mayapythonapi/</link>
		<comments>http://www.chris-g.net/2011/06/15/name-changed-callbacks-in-mayapythonapi/#comments</comments>
		<pubDate>Wed, 15 Jun 2011 00:14:13 +0000</pubDate>
		<dc:creator>chrisg</dc:creator>
				<category><![CDATA[Maya]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.chris-g.net/?p=321</guid>
		<description><![CDATA[Could not figure this out for quite a while &#8211; maya API is a little obtuse if you&#8217;re not used to it, and with all the examples in c++, you&#8217;re on your own when it comes to translating to python. Ergh. &#160; &#038;nbsp]]></description>
			<content:encoded><![CDATA[<p>Could not figure this out for quite a while &#8211; maya API is a little obtuse if you&#8217;re not used to it, and with all the examples in c++, you&#8217;re on your own when it comes to translating to python. Ergh.</p>
<p>&nbsp;</p>
<pre class="brush: python; title: ; notranslate">
from maya import OpenMaya

def nameChangedCallback( *args):
    node = args[0]
    # convert the MObject to a dep node
    depNode = OpenMaya.MFnDependencyNode(node)
    oldName = args[1]

    print '----\nNameChangedCallback'
    print 'newName: ', depNode.name()
    print 'oldName', oldName
    print 'type', depNode.typeName()

# passing in a null MObject (ie, without a name as an argument)
# registers the callback to get all name changes in the scene
# if you wanted to monitor a specific object's name changes
# you could pass a name to the MObject

nullMObject = OpenMaya.MObject()
OpenMaya.MNodeMessage.addNameChangedCallback( nullMObject, nameChangedCallback )
</pre>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chris-g.net/2011/06/15/name-changed-callbacks-in-mayapythonapi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>EXR compression in maya</title>
		<link>http://www.chris-g.net/2011/01/06/exr-compression-in-maya/</link>
		<comments>http://www.chris-g.net/2011/01/06/exr-compression-in-maya/#comments</comments>
		<pubDate>Thu, 06 Jan 2011 02:22:21 +0000</pubDate>
		<dc:creator>chrisg</dc:creator>
				<category><![CDATA[Maya]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.chris-g.net/?p=316</guid>
		<description><![CDATA[If you want to script it, it&#8217;s here: setAttr &#8220;mentalrayGlobals.imageCompression&#8221; ]]></description>
			<content:encoded><![CDATA[<p>If you want to script it, it&#8217;s here:<br />
setAttr &#8220;mentalrayGlobals.imageCompression&#8221; 4</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chris-g.net/2011/01/06/exr-compression-in-maya/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>South for db migrations</title>
		<link>http://www.chris-g.net/2010/10/09/south-for-db-migrations/</link>
		<comments>http://www.chris-g.net/2010/10/09/south-for-db-migrations/#comments</comments>
		<pubDate>Sat, 09 Oct 2010 06:05:18 +0000</pubDate>
		<dc:creator>chrisg</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.chris-g.net/?p=314</guid>
		<description><![CDATA[South is looking like a godsend for Django database migrations&#8230; so far, so sexy]]></description>
			<content:encoded><![CDATA[<p><a href="http://south.aeracode.org/">South</a> is looking like a godsend for Django database migrations&#8230; so far, so sexy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chris-g.net/2010/10/09/south-for-db-migrations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maya python snippets</title>
		<link>http://www.chris-g.net/2010/09/22/maya-python-snippets/</link>
		<comments>http://www.chris-g.net/2010/09/22/maya-python-snippets/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 23:39:55 +0000</pubDate>
		<dc:creator>chrisg</dc:creator>
				<category><![CDATA[Maya]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.chris-g.net/?p=292</guid>
		<description><![CDATA[Posting these for my (and anybody else&#8217;s) edification &#8211; the help docs only get you so far, especially when the nitty gritty of actually *doing* something is more complicated. Get current shelf: Install a menu in the main window menubar: Interfaces This is quite handy]]></description>
			<content:encoded><![CDATA[<p>Posting these for my (and anybody else&#8217;s) edification &#8211; the help docs only get you so far, especially when the nitty gritty of actually *doing* something is more complicated.</p>
<p>Get current shelf:</p>
<pre class="brush: python; title: ; notranslate">
import maya.cmds as cmds
import maya.mel as mel

gShelfTopLevel = mel.eval('$temp1=$gShelfTopLevel')
print cmds.tabLayout(gShelfTopLevel, query=True, st=True)
</pre>
<p>Install a menu in the main window menubar:</p>
<pre class="brush: python; title: ; notranslate">
import maya.cmds as cmds
import maya.mel as mel

gMainWindow = maya.mel.eval('$temp1=$gMainWindow')
oMenu= cmds.menu(parent=gMainWindow, tearOff = True, label = 'MyLabel')
subMenu= cmds.menuItem(parent=oMenu, label='mySubMenu', subMenu=True)
cmds.menuItem(parent=subMenu, label='MenuItem1', c='somePythonProc()')
</pre>
<p>Interfaces<br />
<a href="http://oferz.com/blog////blog4.php/2008/08/25/dynamic-ui-in-maya-using-python">This is quite handy</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chris-g.net/2010/09/22/maya-python-snippets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>cgBreakdown v1.33</title>
		<link>http://www.chris-g.net/2010/01/26/cgbreakdown-v1-33/</link>
		<comments>http://www.chris-g.net/2010/01/26/cgbreakdown-v1-33/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 10:57:21 +0000</pubDate>
		<dc:creator>chrisg</dc:creator>
				<category><![CDATA[XSI]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.chris-g.net/?p=276</guid>
		<description><![CDATA[A small update to cgBreakdown. Will now update params on refmodels, which tend to report themselves as locked. Thanks to Alex Kong for the heads up]]></description>
			<content:encoded><![CDATA[<p>A small update to <a href="/scripts/cgBreakdown">cgBreakdown</a>. Will now update params on refmodels, which tend to report themselves as locked. Thanks to Alex Kong for the heads up.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chris-g.net/2010/01/26/cgbreakdown-v1-33/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>cgBreakDown &#8211; 1.31</title>
		<link>http://www.chris-g.net/2009/01/15/cgbreakdown-131/</link>
		<comments>http://www.chris-g.net/2009/01/15/cgbreakdown-131/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 23:48:03 +0000</pubDate>
		<dc:creator>chrisg</dc:creator>
				<category><![CDATA[XSI]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.chris-g.net/?p=149</guid>
		<description><![CDATA[Fixed a bug in cgBreakDown &#8211; it now ignores fcurves with no keys (very practical idea, thanks SoftImage). This previously caused the script to error out. Grab it on the cgBreakDown page]]></description>
			<content:encoded><![CDATA[<p>Fixed a bug in cgBreakDown &#8211; it now ignores fcurves with no keys (very practical idea, thanks SoftImage). This previously caused the script to error out. Grab it on the <a href="/tools/cgBreakdown/">cgBreakDown</a> page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chris-g.net/2009/01/15/cgbreakdown-131/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>After Effects &#8211; creating open masks via scripting</title>
		<link>http://www.chris-g.net/2008/12/08/after-effects-creating-open-masks-via-scripting/</link>
		<comments>http://www.chris-g.net/2008/12/08/after-effects-creating-open-masks-via-scripting/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 05:12:41 +0000</pubDate>
		<dc:creator>chrisg</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AfterEffects]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.chris-g.net/?p=141</guid>
		<description><![CDATA[Okay, so you&#8217;re creating an After Effects script (my condolences to you, by the way) to create a mask or a shape layer. And you want to create an *open* mask. And you&#8217;ve been banging your head against a brick wall, because the damn thing always wants to close. Here&#8217;s how to fix it&#8230; The ]]></description>
			<content:encoded><![CDATA[<p>Okay, so you&#8217;re creating an After Effects script (my condolences to you, by the way) to create a mask or a shape layer. And you want to create an *open* mask. And you&#8217;ve been banging your head against a brick wall, because the damn thing always wants to close. Here&#8217;s how to fix it&#8230;<span id="more-141"></span></p>
<p>The trick seems to be to declare the mask to be open *before* you set the points of the mask. So simple when you know how. So, this will not work:</p>
<blockquote>
<pre>newMask = thisLayer.Masks.addProperty("Mask");
myMaskShape = newMask.property("maskShape");
myShape = myMaskShape.value;
myShape.vertices = maskPointArray;
<strong>myMaskShape.setValue(myShape);
myShape.closed = false;</strong></pre>
</blockquote>
<p>Whereas this *will* work:</p>
<blockquote>
<pre>newMask = thisLayer.Masks.addProperty("Mask");
myMaskShape = newMask.property("maskShape");
myShape = myMaskShape.value;
myShape.vertices = maskPointArray;
<strong>myShape.closed = false;</strong>
<strong>myMaskShape.setValue(myShape);
</strong></pre>
</blockquote>
<p>I thought i&#8217;d write this up to hopefully save someone the same frustration i&#8217;ve been through.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chris-g.net/2008/12/08/after-effects-creating-open-masks-via-scripting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

