Skip to content

Instantly share code, notes, and snippets.

# Python version of findRelatedSkinCluster.mel
# Based in findRelatedSkinCluster.mel MEL script file found in Maya 2020
import maya.cmds
def find_related_skin_cluster(skin_obj):
skin_shape = None
skin_shape_with_path = None
hidden_shape = None
"""
Functions for generating spline weights.
Usage:
This modules functions each take curve parameters and output control point weights. The weights are generated using
a modified version of de Boor's algorithm. These weights can be used to create a weighted sum to find a point or
tangent on a spline.
While these functions are written for usage in Autodesk Maya, they don't actually have any Maya-specific libraries.
Additionally none of these functions actually care about the data type of provided control points. This way these
@zewt
zewt / gist:73bd5f83927f3ccf20c32cf0440120a4
Created August 19, 2020 06:14
Reset bind position to joint position
# Public domain
from pymel import core as pm
import re
def resetJointOnCluster(joint, skinClusterPreMatrixPlug):
inverseMatrix = joint.attr('worldInverseMatrix').get()
curMatrix = skinClusterPreMatrixPlug.get()
if curMatrix is not None:
different = any(abs(a-b) > 0.00001 for a, b in zip(inverseMatrix, curMatrix))
@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 / 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'])
@defTechAndrew
defTechAndrew / fbx_animation_editing.py
Created April 1, 2019 22:01
Here are some useful calls I've developed for editing FBX animation files using the Python FBX SDK.
import FbxCommon
def fbx_trim_keys(scene, start, end, take_buffer=10):
"""
Uses the FBX SDK to remove unnecessary keys.
:param scene: FBX SDK scene class that hold data to edit
:param int start: start frame of animation keys to keep
:param int end: end frame of animation keys to keep
from pyfbsdk import FBSystem, FBNamespaceAction, FBPlugModificationFlag
def DeleteNameSpace(namespace):
FBSystem().Scene.NamespaceDeleteContent(namespace, FBPlugModificationFlag.kFBPlugAllContent, True)
def AddNamespace(components, namespace):
for comp in components:
comp.ProcessObjectNamespace(FBNamespaceAction.kFBConcatNamespace, namespace)
def SafeDeleteList(components):
@cyaoeu
cyaoeu / fbx_batchexport_anims.py
Created August 29, 2017 17:57
Blender script: batch export anims
import bpy
path = bpy.path.abspath('//') #path of .blend
objname = bpy.context.active_object.name #select rig
singleanim = True
if singleanim == True:
action = bpy.context.active_object.animation_data.action
@EricTRocks
EricTRocks / UpdateJointBindPose.py
Created July 21, 2016 00:24
Updates selected Maya joint's bind pose Credit to Ryan Porter (yantor3d)
# Credit to Ryan Porter (yantor3d)
from maya import cmds
for jnt in cmds.ls(sl=True, type="joint"):
matrixPlugs = cmds.listConnections(jnt + ".worldMatrix", type="skinCluster", p=True) or []
for mp in matrixPlugs:
bindPreMatrixPlug = mp.replace('matrix', 'bindPreMatrix')
if cmds.listConnections(bindPreMatrixPlug, s=True, d=False):
@jirihnidek
jirihnidek / b3d_prop_callbacks.py
Created March 19, 2015 11:27
Blender property and callbacks
"""
Example of callbacks used for Blender integer property
"""
import bpy
# Some global values
values = {}
default_value = -1