Skip to content

Instantly share code, notes, and snippets.

View AndrewHazelden's full-sized avatar

Andrew Hazelden AndrewHazelden

View GitHub Profile
@AndrewHazelden
AndrewHazelden / list_icon_resources.mel
Last active December 9, 2015 11:39
Use MEL in Maya to list the active icons directories
print "Icon folders:\n";
print `xbmLangPathList`;
@AndrewHazelden
AndrewHazelden / platform_check.py
Created December 6, 2015 17:16
Use Python to check the current operating system
# Check the operating system
# Example: mxPlatform = getPlatform()
def getPlatform():
import platform
osPlatform = str(platform.system())
mxPlatform = ''
if osPlatform == 'Windows':
mxPlatform = 'Windows'
@AndrewHazelden
AndrewHazelden / read_directory_of_mxs_scenes.py
Created December 6, 2015 17:18
Use Maxwell Render's PyMaxwell tool to scan a folder for .mxs scene files
from pymaxwell import *
from math import *
import os
import sys
import datetime
mxsFileExt = 'mxs'
mxsDirPath = '/Applications/Maxwell 3/scripts/stereo/'
mxsFileList = getFilesFromPath(mxsDirPath, mxsFileExt)
@AndrewHazelden
AndrewHazelden / maxwell_lens_model.py
Last active December 9, 2015 11:39
Use Maxwell Render's PyMaxwell tool to scan the camera's lens model
# Return the lens type name as a string
# Example: it = CmaxwellCameraIterator(); camera = it.first(scene); cameraLens = cameraParams.getLensType(); lens = mxa_lensTypeName(cameraLens)
def mxa_lensTypeName(cameraLens):
lensTypeName = ''
if cameraLens[0] == TYPE_CYLINDRICAL_LENS:
lensTypeName = 'cylindrical'
elif cameraLens[0] == TYPE_EXTENSION_LENS:
lensTypeName = 'extension lens'
elif cameraLens[0] == TYPE_FISHEYE_LENS:
lensTypeName = 'fisheye'
@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'
@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 / 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 / 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 / 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_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