help a python!

One of the most underused aspects of python is the documentation system. In any def, one can add a line or two of text documenting what the function does, or how to use it. The string needs to be encapsulated by three quotes (single or double) on each side. '''Like this''' or """like this""".

Here is a simple Maya function that gets the parent of the passed object. Note the documentation tag.

def getParent():
	'''This def returns the parent of the passed object'''
	selObject = cmds.ls(sl=True)
	par = cmds.listRelatives(p=True)
	return par

myPar = getParent()
print myPar[0]

Now, for the fun part, you can use something like this to find out what is going on with the def. print getParent.__doc__

You can even store the documentation into a variable as you would any string. helpDoc = getParent.__doc__.

Commenting your code:Brilliant. Documenting your code:Priceless

Tags: ,

2 Comments

Python for Photoshop

I’ve been using python at work for about a year off and on between management duties, and other stuff. I haven’t played around much with the com interface, but this has certainly peaked my interest.

http://techarttiki.blogspot.com/2008/08/photoshop-scripting-with-python.html

The ability to interface with other applications via python is huge. I am already planning some validation and error checking (texture sizes, etc) scripts for work using this. Thanks to the tech art tiki for this amazing info!

Tags: ,

No Comments

A little bit of python for Pete

So as I mentioned I am doing a bit of rigging for Pete’s project (see last post). Pete’s left the file in decent shape although I find myself having to move pivot points of the meshes to the joints I wish to constrain them to. “If you have to do anything more than twice, script it” is the motto I subscribe to, so here’s a little python widget I wrote …

def moveMeshPivotsToJointPos(*args):
	allSelNodes = cmds.ls(sl=True)
	selectedJoints = cmds.ls( sl=True, type='joint' )
	print selectedJoints
	if not len(selectedJoints) == 1:
		print 'Please select one joint'
	else:
		selectedJoint = selectedJoints[0]
		cmds.select(selectedJoint, replace=True)
		selJointPos = cmds.xform(query=True, rp=True, ws=True)
		for eachSelNode in allSelNodes:
			if not eachSelNode == selectedJoint:
				print eachSelNode
				cmds.select(eachSelNode, replace=True)
				cmds.xform(eachSelNode, ws=True,
                                piv=(selJointPos[0], selJointPos[1], selJointPos[2]))
				cmds.select(selectedJoint, replace=True)
				cmds.select(eachSelNode, add=True)
				mel.eval(cons + '-mo;')
		cmds.select(cl=True)
cons = 'pointConstraint'
moveMeshPivotsToJointPos(cons)

Changing the cons variable to the name of different constraints will allow the user to dictate the moving of pivots and the type of constraint to execute, all in one shot.

I suppose a simple UI is in order to change the cons variable.

Below is a commented version of the script, so you know what each line is doing …
moveMeshPivotsToJointPos.py

Tags: , , ,

2 Comments

Pete’s secret project

My co-worker and buddy Pete has a project he’s working on in his free time.  He suckered me into asked me if I’d be interested in rigging it.  I just started out, and it’ll have some intersting challenges.  I’ll update as I progress.2009-04-10_2308

Tags:

1 Comment

Break from teaching

My stint over at CDIA has come to a pause. I’ll be glad for the break as teaching was really sucking up my free time. I’ll have more time for some side projects I want to explore. I have a feeling come summer or fall I’ll jump back into teaching, if an opportunity presents itself.  I really do enjoy it.  I gave a guest lecture at Emerson a while ago, here is the google presentation…

No Comments

Bristlebots go!

I made some Bristlebots with the kids last Sunday evening. We had a blast!



Here are the instructions I followed…

http://www.evilmadscientist.com/article.php/bristlebot
I need to resolder the battery wires and do some other mods next weekend.

Tags: ,

1 Comment

Mooftronic

I am gearing up to embark on making some stuff.  I have a love of music and technology, plus a subscription to Make Magazine.  When I saw the mooftronic on page 70 of issue 15, I knew it was the beginning level project I was looking for.

Here is what it looks and sounds like …

http://www.youtube.com/watch?v=U3cZBj7ZKZY

The parts should cost about 25 bucks, although I’ll need to buy a soldering iron too.  I’ll update as I aquire the parts and start building the mooftronic.

Tags: ,

2 Comments

Welcome

Hi. The site is still under construction, but it’s coming along. Stay tuned for more info.

No Comments