Skip to content

Instantly share code, notes, and snippets.

import maya.cmds as cmds
import maya.api.OpenMaya as om2
import maya.api.OpenMayaAnim as omAnim2
def setNewBindPose():
sel = om2.MGlobal.getActiveSelectionList()
jntMObj = sel.getDependNode(0)
jntDepNode = om2.MFnDependencyNode(jntMObj)
jntWMtxPlug = jntDepNode.findPlug("worldMatrix", False).elementByLogicalIndex(0)
@EricTRocks
EricTRocks / Maya_RemoveUnusedInfluencesOM2.py
Created August 16, 2017 01:14
Get unused influences via OM2 and remove them using cmds
import maya.cmds as cmds
import maya.api.OpenMaya as om2
import maya.api.OpenMayaAnim as omAnim2
def getSkinCluster():
sel = om2.MGlobal.getActiveSelectionList()
shapeDagPath = sel.getDagPath(0).extendToShape()
shapeMeshFn = om2.MFnMesh(shapeDagPath)
inMeshPlug = shapeMeshFn.findPlug('inMesh', False)
@EricTRocks
EricTRocks / Fabric_SetNodeMetaData.py
Created June 14, 2017 17:13
How to set metadata on Canvas nodes through Python
import FabricEngine.Core
import pymel.core as pm
from maya import cmds
# Create Maya Canvas Node and preset instance
nodeName = cmds.createNode('canvasNode', name='myGraph')
dummyVec3NodeName = cmds.FabricCanvasInstPreset(
mayaNode=nodeName,
execPath="",
@EricTRocks
EricTRocks / fabric_registerExtFromPath.py
Created December 22, 2016 20:39
Loads a Fabric Engine extension from a file path after the client has been created and after the FABRIC_EXTS_PATH has been set. This also shows how to use the new getExtensionsDesc() method.
import FabricEngine.Core
import json
client = FabricEngine.Core.createClient({'guarded': True})
client.registerExtensions("C:\\temp\\Exts")
client.loadExtension('EricTools')
extData = json.loads(client.getExtensionsDesc())
for k, v in extData.iteritems():
if k == 'EricTools':
@EricTRocks
EricTRocks / Fabric_CreateDictionary.kl
Created October 12, 2016 21:31
Create Dictionaries in Fabric Engine KL
require Math;
operator entry() {
// String to Vec3 Dict
Vec3 myDict[String];
myDict['bob'] = Vec3(1,2,3);
report(myDict['bob']);
// Integer to String Dict
@EricTRocks
EricTRocks / Fabric_Create2DArray.kl
Created October 12, 2016 21:26
Create a 2D array of Vec3 values in Fabric Engine KL
require Math;
operator entry() {
Vec3 myArray[][];
Vec3 array1[];
array1.push(Vec3(1,2,3));
Vec3 array2[];
array2.push(Vec3(3,2,1));
@EricTRocks
EricTRocks / Max_CreateFabMatrixCtrl.py
Last active October 3, 2016 22:07
Create Fabric Matrix Controller in Max
import MaxPlus
import pymxs
rt = pymxs.runtime
obj = MaxPlus.Factory.CreateHelperObject(MaxPlus.ClassIds.Point)
node = MaxPlus.Factory.CreateNode(obj, 'thing')
fabMatrixCtrlClassID = MaxPlus.Class_ID(0x06a53772, 0x7c2c7c4b)
fabMatrixCtrl = MaxPlus.Factory.CreateMatrix3Controller(fabMatrixCtrlClassID)
@EricTRocks
EricTRocks / SymmetrizeModel.py
Created September 30, 2016 19:55
Duplicate, scale -1 in X, unparent, freeze again
import maya.cmds as cmds
import pymel.core as pm
import pymel.core.datatypes as dt
sel = pm.ls(selection=True)
shapeNode = pm.listRelatives(sel[0])[0]
pm.constructionHistory(shapeNode)
pm.makeIdentity(sel[0], apply=True, t=True, r=True, s=True)
@EricTRocks
EricTRocks / Max_GetCustAttrCtnrParams.py
Created September 22, 2016 16:44
Get custom attribute containers and parameters and print data
import MaxPlus
node = MaxPlus.SelectionManager.GetNodes()[0]
# Add Attr Holder to selected object
#~ attrHolder = MaxPlus.Factory.CreateObjectModifier(MaxPlus.ClassIds.EmptyModifier)
#~ attrHolder.SetName(MaxPlus.WStr('myObjAttrs'))
#~ node.AddModifier(attrHolder)
# Find Modifier Programmatically
@EricTRocks
EricTRocks / Max_GetCustomAttributesAttrHolder.py
Created September 20, 2016 22:09
Get Custom Parameters on Attribute Holder
import MaxPlus
# Selected object should have Attribute Holder on it
for n in MaxPlus.SelectionManager.Nodes:
mod = n.GetModifier(0)
attrContainer = mod.GetCustomAttributeContainer()[0]
for p in attrContainer.ParameterBlock.Parameters:
print p.GetName()