Skip to content

Instantly share code, notes, and snippets.

View justsh's full-sized avatar

Justin Sheehy justsh

View GitHub Profile
@justsh
justsh / README.md
Created September 19, 2024 22:17 — forked from bjesus/README.md
Weather widget for waybar
@justsh
justsh / userSetup.mel
Created August 31, 2024 07:55
Workaround userSetup file for viz/pipeline
// HACK: Workaround since a maya project's scripts folder is not added
// to the PYTHONPATH by default
// WARN: only one userSetup.mel is loaded.
// using this script will prevent several viz scripts from running
// Github issue has been logged and will be resolved on the viz/pipeline end
// given that a userSetup script should be available to... well, users.
// HACK: sourcing a mel file that sources other files is known to cause
@justsh
justsh / mkshelf.bash
Created August 31, 2024 07:55
make a new maya shelf (solo projects only). uses a template file in $MY_PROJECT/aux if it exists
#!/bin/bash
if [ -z "$1" ]; then
printf "%bPlease pass a name for the new shelf (e.g. model_tools)%b\n" "${FG_RED}" "${NORMAL}"
exit 1
fi
name=$1
generate_shelf_empty() {
cat << EOF > ${new_shelf}
@justsh
justsh / mprint.py
Created August 31, 2024 07:55
uses the mel-based print function to print from python
# Not all print statements in maya show up in Command Line output bar
# This is an alternative to pymel's display* print statements
import pymel.core as pm
def mprint(*args):
print_args = ("//",) + args + ("//\n",)
pm.mel.mprint(*print_args)
@justsh
justsh / deferOnlyInteractive.py
Created August 31, 2024 07:55
Only execute the given (deferred) command in Interactive mode. Based on pymel.mayautils.executeDeferred
import maya.utils
import maya.OpenMaya
def deferOnlyInteractive(func, *args, **kwargs):
if maya.OpenMaya.MGlobal.mayaState() == maya.OpenMaya.MGlobal.kInteractive:
maya.utils.executeDeferred(func, *args, **kwargs)
else:
print("Execution of interactive function {0} was skipped in non-interactive mode"
"".format(func.__name__))
@justsh
justsh / commandPortWrapper.py
Created August 31, 2024 07:55
Wrap pm.commandPort with defaults set for the MayaSublime plugin
from __future__ import print_function
import pymel.core as pm
def openPort(port=":7002", **kwargs):
print("Opening command port", port)
commandPortWrapper(port, False, **kwargs)
def closePort(port=":7002", **kwargs):
@justsh
justsh / pymel_boilerplate.py
Created August 31, 2024 07:55
PyMEL boilerplate
from __future__ import print_function
import pymel.core as pm
import pymel.core.nodetypes as nt
from pymel.core import (PyNode, MayaAttributeError, MayaNodeError)
cmds = pm.cmds
@justsh
justsh / objQuickImport.py
Created August 31, 2024 07:55
Import objs from the OBJ subfolder of the current asset's project folder
from __future__ import print_function
import pymel.core as pm
objPath = pm.workspace.path.joinpath("OBJ", "exports")
for obj in objPath.files():
pm.importFile(obj, gr=False, type="OBJ", options="mo=1;lo=0")
@justsh
justsh / move_pivots.py
Created August 31, 2024 07:55
Move an object's pivots to the world position of a second object
from __future__ import print_function
import pymel.core as pm
driver, driven = pm.selected()
# NOTE: PyNode.Attribute.rotatePivot.set() may be equivalent
pm.move(driven.rotatePivot, *driver.getTranslation(worldSpace=True))
pm.move(driven.scalePivot, *driver.getTranslation(worldSpace=True))
@justsh
justsh / removeStudent.bash
Created August 31, 2024 07:55
Changes the fileInfo license line in Maya ASCII files from "education" to "student"
#!/bin/bash
main() {
usage="${FG_CYAN}usage: removeStudent filename.ma${NORMAL}"
if [ -z "${1}" ]; then
echo -e "${FG_RED}Filename not given${NORMAL}"
echo -e ${usage}
elif [ ! -e "${1}" ]; then
echo -e "${FG_RED}Filename ${1} does not exist${NORMAL}"