May
19
2010

obtaining maya filenames via two methods

As I continue to learn more about python and maya I’m finding more efficient ways of gathering data. Yesterday during a code review I used the following way to grab the base path from a Maya filename.

import maya.cmds as cmds
fileName = cmds.file(sceneName=True, q=True)
baseFileName = fileName.split('/')
del baseFileName[-1]
basePath = "/".join(baseFileName)
print basePath

It seemed to do the job for me, it would return the base path to the maya file that was currently open but drop off the last obj in the array.
My buddy JT reviewed the code and suggested I check out the os. commands. So in a quick exercise I did just that, and found I can do the exact same thing with even fewer lines of code.


import maya.cmds as cmds
import os
fileName = cmds.file(sceneName=True, q=True)
basePath = os.path.dirname(fileName)
print basePath

1
Mar
01
2010

xlrd – t3h xls hottn3ss

Tags: , , ,

Really great py module for reading .xls files. Instead of having to export excel to .csv and then parse, you can use this module to read/open/print info from whole excel files or from selected rows/cells. Research for this came about while trying to figure out at easier way to pull data from a particular portion of an excel sheet.

After you have installed xlrd the code is simple:


import xlrd
wb = xlrd.open_workbook('simple.xls')

wb.sheet_names()

sh = wb.sheet_by_index(0)
sh = wb.sheet_by_name(u'Sheet1')

for rownum in range(sh.nrows):
print sh.row_values(rownum)

Thanks to John Machin Author of:
http://pypi.python.org/pypi/xlrd/0.7.1

0
Jan
26
2010

Code Junkie…

A buddy at work has been motivating me to try to script more things as I am going through my daily routine and I’m starting to realize the power that is there. We have a number of minor repetitive tasks that we do every day in our jobs as tech artists, and as one-offs they might take 30 secs or a minute and seem trivial. Now take that ‘one-off’ and think about how many times we actually do it in any given day…10, 20, 50? That time savings adds up exponentially over the course of a week, month, year…What can one say, except, the AWESOME power of scripting continues to amaze!

red coolness

A small task that we need to do is assign all of our physics objects a physics shader. Now normally you have to create the shader, change it’s color to red, and then assign it to the physics objects in your scene. Not exactly rocket-science, nor does it take an hour to do, nonetheless it IS repetitive. Well I started thinking about it and found out it’s not too difficult to do with script. With a bit o’ help from a tutorial I found here: I was quickly able to create a script to do exactly what I was looking for.


import maya.cmds as cmds
import maya.mel as mel

def createMaterial( name, color, type ):
cmds.sets( renderable=True, noSurfaceShader=True, empty=True, name=name + 'SG' )
cmds.shadingNode( type, asShader=True, name=name )
cmds.setAttr( name + ".color", color[0], color[1], color[2], 'double3')
cmds.connectAttr( name + ".outColor", name+"SG.surfaceShader" )

def assignMaterial (name, object):
cmds.sets(object, edit=True, forceElement=name+'SG')

def assignNewMaterial( name, color, type, object):
createMaterial (name, color, type)
assignMaterial (name, object)

cmds.select("*_physobj*")
mrSelection = cmds.ls(sl=True)

assignNewMaterial( 'Physobj' , (1, 0, 0), 'lambert', mrSelection )

Give it a try. This will toss all of your named meshes of _physobj in your scene into an array and assign them with a shader that is red with the name Physobj.

Cool!

Step 2 will then be to mark the faces as Physics and NoDraw, but I’ll save that for when I’m actually at work :D

0
Dec
02
2009

camera, units, time … action!

The power of scripting never ceases to amaze me.  One of the biggest things that bothers me on a daily basis (albeit) a small and simple issue, is that when you bring a model in for rigging the scene size, frames, and camera are never setup correctly.  We have a mel script at work to do some of this for us, but at home I was at a loss tonight, so I decided, it can’t be that hard to do…and found out it wasn’t!  Here you go, a few lines of python code and voila, scene units, time, and cameras setup.


import maya.cmds as cmds
cmds.setAttr( 'perspShape.nearClipPlane', .001 )
cmds.setAttr( 'perspShape.farClipPlane', 1000 )
cmds.currentUnit( linear='m' )
cmds.currentUnit( time='ntscf' )

0
Nov
22
2009

Almost Turkey Day…

wOOt!  The countdown to Turkey day begins.  Going to visit friends in Jersey. Yeah go ahead snicker…we get that alot. Evidently when you tell someone you are going to visit New Jersey their first response is usually a snicker or a giggle or a wth. Well I have no idea what they are talking about.

Jersey has a lot of things going for it.

1. You never have to pump your own gas

2. Ever hear of a little board game called Monopoly?

3. (and the most important :) ) Two of our best friends live there.

So before you naysayers out there rag on Jersey, just remember you could never have hotels on Boardwalk and Park Place without it!

0
Aug
31
2009

Project: Green lantern / He-man continued

Wow night two of actually working on a project…I know right? Wow, committing at home to a project more then one night in a row. Who knows? I might actually go for three! Whoa now. Anywho, I got to messing with laying out some flat color and I’m pretty happy so far. I have to keep the yellow suit, and the orange/tan skin since those are staples of Sinestro, but I’m going to break it up with a gray instead of black base, and browns/metals. I feel like it’s a pretty solid base. I’ll refine the outlines of the flats, then work on some ink to toss over it.


sinestro2

0
Aug
30
2009

Project: Green Lantern / He-man Team up

I was sitting at my desk at work one day and had an idea to mix up two of my favorite heroes of all time. The one and only Hal Jordan (Green Lantern) with the defender of Eternia himself, He-man. The premise behind the story would be simple. Sinestro’s yellow power battery has completed construction. He and his yellow corps had recently crippled the Green Lantern Corps’ central power battery on OA. The Guardians, along with Hal, decide it best to abandon the unsafe planet of OA and move the central power battery to a planet in another sector. Ganthet has heard stories of a peaceful planet of Eternia in a nearby sector that is home to a mysterious dark castle with a near-impenetrable barrier around it. The decision is made and the GL Corps along with the Guardians contact the Sorceress inside Grayskull. The Sorceress is in agreement and allows them to relocate the central power battery to Grayskull until it is repaired.

Meanwhile, Sinestro learns of the plan to move the battery and aligns himself with a powerful sorceror on Eternia. Enter Skeletor. Skeletor tells Sinestro of his plight with He-man and they combine their efforts to form a powerful force against He-man and Grayskull.

I’ll work on fleshing out the story a bit more, but I decided since I can never see ANY project to completion that I will focus on two alternate covers to the series, namely a cover that showcases Sinestro and Skeletor, and one that has Hal and He-man.

At the suggestion of my buddy Chonny, I’m going to be taking a different approach for Sinestro and Hal. To fit with the style of Eternia, I’ve elected to remove the heroes from their typical spandex gear and put them in more of a MadMax-esq steampunk outift. I’ve started with Sinestro.

Sinestro

2
Aug
24
2009

sugarpy

Tags:

some cool stuffs from chad
http://www.sugarpy.com/
guy is doing some cool work with graphical nodes in python

0
Aug
12
2009

python and perforce

Tags: ,

woot, wrote a python script to connect to a p4 server and create a changelist to add data to:

The idea here would be to open a file, parse it for files that need to be added/updated/revisioned in perforce, then pass this info to p4 via python.

from P4 import P4
p4 = P4()
# p4.port = "perforce-server:XXXX"
# p4.user = "username"
# print p4.env( "P4PORT" ) - this will allow you to get the .env info from p4

# sets the clientspec you want to connect to (otherwise will default to the p4′s default)
p4.client = “clientspec”

# connect to p4
p4.connect()

# setting description for changelist header info
desc = {“Description”: “Updates”, “Change”: “new”}

# calls desc and adds
p4.input = desc

# calls p4 run command and runs it with the changes integrated flag
p4.run(“changelist”, “-i”)

# closes connection to p4
p4.disconnect()

found a bit of info regarding open/reading/writing in python.

open(filename,mode)

1. filename can be a file or path to a file
2. mode can be any of the following

1. ‘r’ for reading
2. ‘r+’ for reading and writing
3. ‘w’ for writing
4. ‘a’ for appending
5. both read and write modes also have a ‘b’ option for binary reading and writing (’rb’, or ‘wb’)

Ex:
myInput = open('myfile.txt','r')

This command will open the file “myfile.txt” in the current
directory, in “read” mode. You can access the methods of this file
using the ‘myInput’ variable. In the example, the open command will
open the file indicated in the first argument(’myfile.txt’).
This argument can be a file, or the path to a file. The second
argument, is the file mode.

2
Aug
02
2009

Large Posting Updates!

I finally merged over all my posts from the old blog. Consolidating everything to one place for all my ramblings. mattregnier.blogspot.com is dead. all hail !revolution! Anywho just check back here in the future for any updates.

0