Skip to content

Instantly share code, notes, and snippets.

View hogjonny's full-sized avatar

Jonny K Galloway hogjonny

View GitHub Profile
@hogjonny
hogjonny / test_01.py
Created June 6, 2013 15:24
This is a test of Gist using some template code for a making progress window in Autodesk Maya
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# test.py
# This is a test
# version: 0.1
# date: 5/23/2013
# author: jGalloway
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
@hogjonny
hogjonny / maya_UndoContext.py
Created June 13, 2013 15:08
This is a block of code, which creates a Class for managing Undo chunking in Autodesk Maya, Python scripts. I have tested this in my Maya 2011 setup, and it works great. This code snippet came from Rob Galanakis, via Tech-artist.org forums: http://tech-artists.org/forum/showthread.php?2522-Undo-in-Maya-(Mel-Python-Execution)
import maya.cmds as mc
###########################################################################
## This wraps commands in a maya UndoContext
# -------------------------------------------------------------------------
class UndoContext(object):
def __enter__(self):
mc.undoInfo(openChunk=True)
def __exit__(self, *exc_info):
mc.undoInfo(closeChunk=True)
@hogjonny
hogjonny / autologger.py
Last active December 18, 2015 19:19
... method/function for a logging class. Will return the message and information about the last function run: the function, the file called from, and the line number the function begins on.
###########################################################################
## Code Block. This Class sets up a logger for debugging.
# -------------------------------------------------------------------------
class SetupLogger():
def __init__(self):
# Set up fresh logging
self.name = name
self.log = logging.getLogger(self.name)
# Set the logging level
self.log.setLevel(logging.DEBUG)
@hogjonny
hogjonny / mayaSave.py
Last active October 5, 2022 15:23
maya, check for 'unsaved changes', if there are ... save before proceeding:
import maya.cmds as mc
# check if there are unsaved changes
fileCheckState = mc.file(q=True, modified=True)
# if there are, save them first ... then we can proceed
if fileCheckState:
print 'Need to save.'
# This is maya's native call to save, with dialogs, etc.
# No need to write your own.
@hogjonny
hogjonny / funcName.py
Created June 27, 2013 00:01
example for how you can return a functions name (as a string)
def foo():
# a func can just make a call to itself and fetch the name
funcName = foo.__name__
# print it
print 'Internal: {0}'.format(funcName)
# return it
return funcName
# you can fetch the name externally
fooName = foo.__name__
@hogjonny
hogjonny / headerFooter.py
Last active December 22, 2015 20:59
Some simple formatting for nicely logging blocks of data (takes string block, or iterable data type ... fallback is the attrs on object passed in.)
#!/usr/bin/env python
#coding:utf-8
# -- This line is 75 characters -------------------------------------------
# headerFooter.py
# author: hogjonny [at] gmail [dot] com
# -------------------------------------------------------------------------
'''
Some string formatting and generator functions,
useful for logging, etc.
@hogjonny
hogjonny / quadSphereUV.ma
Last active December 24, 2015 12:49
Maya 2011 - UV unwrapped quad sphere in maya ascii (.ma) format. - revision is optimized
//Maya ASCII 2011 scene
//Name: quad_sphere_unwrapped.ma
//Last modified: Wed, Oct 02, 2013 04:15:59 PM
//Codeset: 1252
requires maya "2011";
requires "stereoCamera" "10.0";
currentUnit -l centimeter -a degree -t film;
fileInfo "application" "maya";
fileInfo "product" "Maya 2011";
fileInfo "version" "2011";
@hogjonny
hogjonny / hogGenGradient.py
Last active December 17, 2020 19:55
Working on code to convert an image to an 8-bit heightmap along with a colorRamp.\n 1. Use a !!! duplicate !!! of your image image to create index palette, save the palette (.act file)\n 2. Run through this script\n 3. Now use the sorted palette to index palette-ize your original image\n 4. Now switch the palette to 'grayscale' ... this you save…
#!/usr/bin/env python
'''
hogGenGradient.py
~~~
A script built on PIL to convert an image to 8-bit heightmap and a
luminance sorted gradient map.
Requirements: PIL, numpy
Tested mainly in Python 2.7 (also limited tests in 2.6.4)
@hogjonny
hogjonny / maya_averageRGBA.py
Last active August 29, 2015 13:56
Maya averageRBGA
#!/usr/bin/env python
#coding:utf-8
'''Loops selection to average RGBA on vertices.'''
__author__ = 'hogjonny'
import maya
from maya import cmds,mel
global gDebug
#!/usr/bin/env python
#coding:utf-8
# -- This line is 75 characters -------------------------------------------
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# fileTemplate.py
# This is a template formatting for new files.
# version: 0.1