Skip to content

Instantly share code, notes, and snippets.

View chris-lesage's full-sized avatar

Chris Lesage chris-lesage

View GitHub Profile
@chris-lesage
chris-lesage / removeUnusedInfluences.py
Last active July 18, 2024 05:05
Snippet to removeUnusedInfluences in Autodesk Maya using Python.
import maya.cmds as cmds
'''
# EXAMPLE USAGES:
# Removes all unused influences from skinCluster1
remove_unused_influences('skinCluster1')
# Removes the two specified joints from Body_SkinCluster,
but only if they are not currently weighted to anything.
remove_unused_influences('Body_SkinCluster', ['leg_L0_5_jnt', 'leg_R0_5_jnt'])
@chris-lesage
chris-lesage / build_slerp_ramp.py
Last active September 19, 2023 03:26
Fake a multi-output lerp/slerp ramp in Autodesk Maya using remapValue nodes. Useful for twisting or interpolating objects and attributes.
import pymel.core as pm
"""
Take a collection of attributes and interpolate them along a curve.
It uses a master remapValue that drives multiple remapValues
to simulate the effect of a multi-out curve node.
References to "twist", because it was originally written for twisting ribbon IK
But it can interpolate any custom attributes you wish
Written by Chris Lesage, June 2019
@chris-lesage
chris-lesage / soft_selection_weights.py
Last active May 3, 2023 22:08
Get a list of soft selection weights in Autodesk Maya
import maya.cmds as cmds
import maya.OpenMaya as omo
# (Open Maya Old)
def soft_selection_weights():
''' create and return a list of the soft selection weights '''
#TODO: Would be nice to rewrite this using the new API. Low priority.
#TODO: Debug on multiple selections
# temporary hack. Turn off symmetry when reading MRichSelection until I learn to use symmetry.
@chris-lesage
chris-lesage / maya_manipulator_size_hotkeys.py
Created July 9, 2019 21:54
Precisely scale Maya manipulators using addition instead of multiplication
'''
In Autodesk Maya, when you hit - and = to scale the manipulator gizmos, it *multiplies* the size.
So if it is small, it takes a long time to grow. And if it is big, and move in huge increments.
So I use addition and subtraction instead.
This gives you much more precise control.
Map the original ones to shift. _ and + to move in larger increments.
Just a tiny little tweak that helps me size it exactly how I want.
I use the radius of the rotation to measure pivot placement.
'''
@chris-lesage
chris-lesage / stepDict_documentation.py
Last active June 14, 2024 07:24
This is a test mGear Shifter POST script that shows how to access the stepDict and all of its information. It's a WIP meant to also act as documentation.
import mgear.shifter.custom_step as cstp
'''
This is a test mGear Shifter POST script that shows how to access the stepDict and all of its information.
It's a WIP meant to also act as documentation.
I'll continue to update it, as I discover more. And hopefully include some of this information in the official mGear docs.
Chris Lesage - chris@rigmarolestudio.com
Justin Pedersen - justin@tcgcape.co.za
Jascha Wohlkinger - jwohlkinger@gmail.com
@chris-lesage
chris-lesage / python-challenges.md
Last active April 5, 2020 14:44
Simple Python Challenges in Maya

Intro Email:

[COMMENT: This document was originally written to introduce beginners and generalist co-workers who wanted to start using Python. It was meant to go much further than #9, but the project fizzled out.]

Write scripts that do the following, and we can talk about techniques, or ways to improve it. If they are too easy, you can also add options, or a GUI.

Please try to write nice clean code, and make comments. You will be re-using parts of your scripts in future challenges, so it is important for you to be able to read and re-use your code.

PYTHON CHALLENGES

@chris-lesage
chris-lesage / check_max_influences.py
Created January 29, 2020 23:31
Check skinClusters for too many influences per vertex in Autodesk Maya.
import maya.OpenMaya as OpenMaya
import pymel.core as pm
import maya.OpenMayaAnim as OpenMayaAnim
import maya.cmds as cmds
import maya.mel as mel
class checkMaxSkinInfluences(object):
''' This script takes a mesh with a skinCluster and checks it for N skin weights.
If it has more than N, it selects the verts, so you can edit them.
@chris-lesage
chris-lesage / eye_rigger.py
Created February 17, 2020 20:34
Alternative eye_rigger for mGear. I eventually want to submit this as a PR.
"""Rigbits eye rigger tool"""
"""
This is an alternative eye_rigger for mGear 3.2
I eventually want to submit this as a PR, but I haven't fully tested it yet.
It adds march_vertex() which helps discover the upper and lower edgeloops in the eye.
This can help fix issues on the right side of the rig, where the eye can take weird shapes.
It can also make the eye rig more stable on characters where the eye is at a tilted angle.
Chris Lesage February 2020
@chris-lesage
chris-lesage / calculate_pole_vector.py
Last active April 20, 2024 14:07
Autodesk Maya script to calculate pole vector position based on 3 input objects
import pymel.core as pm
'''
An Autodesk Maya PyMEL script that calculates a pole vector position
based on 3 input PyNode objects. example: leg, knee, ankle bones.
Chris Lesage chris@rigmarolestudio.com
'''
def calculate_pole_vector(p1, p2, p3, poleDistance=1):
"""
@chris-lesage
chris-lesage / example_usage.py
Last active April 14, 2024 20:43
A script to pin an object to a NurbsSurface in Autodesk Maya
import pymel.core as pm
'''
Here are some examples of how to use the pin_to_surface.py script.
'''
# make a nurbsPlane
oNurbs = pm.nurbsPlane(n='nurbsPlane1')
# You can specify the nurbsSurface by string, PyNode transform or PyNode shape.