Skip to content

Instantly share code, notes, and snippets.

View AndrewHazelden's full-sized avatar

Andrew Hazelden AndrewHazelden

View GitHub Profile
@AndrewHazelden
AndrewHazelden / padded_frame_number.mel
Last active December 9, 2015 11:39
A MEL script for generating a frame padded number. In this case the source value that is frame padded with leading zeros is the start frame value from the Maya Render Settings window
// Add zero digit padding to an int value
global proc string pvr_zeroPadding(int $num, int $padding){
// Tip from the blog post: http://ldunham.blogspot.ca/2012/01/melpython-adding-number-padding.html
int $lengthNum=size(string($num));
string $padString;
if($lengthNum<$padding){
for($i=0;$i<($padding-$lengthNum);$i++){
$padString=$padString+"0";
@AndrewHazelden
AndrewHazelden / progress_bar_demo.mel
Last active February 4, 2022 20:19
A MEL script for updating a progress bar as a task is running. If the escape key is pressed the task stops and the progress bar is hidden.
int $startFrame = `getAttr "defaultRenderGlobals.startFrame"`;
int $endFrame = `getAttr "defaultRenderGlobals.endFrame"`;
// The $frameStep variable is used to implement frame skipping using the "By Frame" render settings attribute.
int $frameStep = `getAttr "defaultRenderGlobals.byFrameStep"`;
string $progressText = "";
if($startFrame != $endFrame){
// Show a rendering progress bar
@AndrewHazelden
AndrewHazelden / print_env.mel
Last active December 12, 2015 14:39
A MEL command for checking what the operating system's environment path variable is when launching child processes using system() on Windows.
// Windows
system("echo %PATH%");
// Mac & Linux
system("echo $PATH");
@AndrewHazelden
AndrewHazelden / print_env.py
Last active December 9, 2015 11:36
A Python script to check the system's environment path variable
import os
print '[System ENV PATH] ' + os.environ['PATH']
# Result: [System ENV PATH] /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
@AndrewHazelden
AndrewHazelden / check_batch_mode.py
Last active May 9, 2023 07:38
A python script to check if Maya is running in Batch mode or with a GUI
# Check if Maya is running in Batch mode or with a GUI
# A return value of 1 means Batch Mode, 0 means GUI mode
def checkMayaGuiBatchMode():
"""
Maya tip on detecting Maya Batch mode is from Michael Scarpa's blog post "MEL Sillyness":
http://www.scarpa.name/2010/12/16/mel-sillyness/
"""
# Check if Maya is running in batch mode or with a GUI
import maya.OpenMaya
@AndrewHazelden
AndrewHazelden / file_exists.py
Last active December 9, 2015 11:36
Use Python to check if a file exists on disk
import os
# File to check
mxsFilePath = 'C:/Program Files/Next Limit/Maxwell 3/scripts/stereo/CubeX.mxs'
# See if the file exists
if os.path.exists(mxsFilePath):
print('[MXS File] ' + mxsFilePath)
else:
print('[MXS File Not Found] ' + mxsFilePath)
@AndrewHazelden
AndrewHazelden / check_camera.py
Last active December 9, 2015 11:37
Use Maxwell Render's PyMaxwell tool to check the active camera's name and resolution settings
from pymaxwell import *
# Maxwell .mxs scene file
mxsFilePath = 'C:/Program Files/Next Limit/Maxwell 3/scripts/stereo/CubeX.mxs'
# Load the mxs scene
scene = Cmaxwell(mwcallback)
scene.readMXS(mxsFilePath)
# Read the active camera's name and resolution settings
@AndrewHazelden
AndrewHazelden / date_time.py
Last active March 1, 2016 22:23
Use Python to generate a date and time stamp as a string
import datetime
# Get the current time
now = datetime.datetime.now()
# Make a note of the date and time in a string
# Example: 2015-12-05 12:34:24 PM
textDocument = '# Scene Generated: ' + now.strftime('%Y-%m-%d %H:%M:%S %p') + '\n'
print textDocument
@AndrewHazelden
AndrewHazelden / get_filename.py
Last active December 9, 2015 11:37
Use Python to separate a filepath into the base directory, the file, and the filename without an extension
import os
mxsFilePath = 'C:/Program Files/Next Limit/Maxwell 3/scripts/stereo/CubeX.mxs'
# Find out the current scene file
dirName = os.path.dirname(mxsFilePath)
sceneName = os.path.basename(mxsFilePath)
scenePathNoExt = os.path.splitext(mxsFilePath)[0]
@AndrewHazelden
AndrewHazelden / maxwell_color_space.py
Last active December 9, 2015 11:40
Use Maxwell Render's PyMaxwell tool to read the active color space
# Get the Color Space
# Example: scene = Cmaxwell(mwcallback); colorSpace = mxa_getColorSpace(scene)
def mxa_getColorSpace(scene):
colorSpace = ''
colorSpaceValue = scene.getColorSpace()
if colorSpaceValue == COLOR_SPACE_SRGB:
colorSpace = 'sRGB IEC61966-2.1'
elif colorSpaceValue == COLOR_SPACE_ADOBE98:
colorSpace = 'Adobe RGB'