Skip to content

Instantly share code, notes, and snippets.

View RedForty's full-sized avatar
😸
Ship it

Daniel Klug RedForty

😸
Ship it
  • California
View GitHub Profile
@RedForty
RedForty / parentConstraint_connect.py
Created December 24, 2018 03:18
A better parent constraint that will put the attributes of the constraint on the parent
# A better parent constraint
sel = cmds.ls(sl=1)
source = sel[0]
target = sel[-1]
constraint = cmds.parentConstraint(source, target, maintainOffset=True)[0]
cmds.addAttr(source, longName='blendParent', attributeType='float3', hidden=0, keyable=1, proxy=target + '.blendParent1')
cmds.addAttr(source, longName='constraint', attributeType='float3', hidden=0, keyable=1, proxy=constraint + '.w0')
cmds.addAttr(target, longName='constraint', attributeType='float3', hidden=0, keyable=1, proxy=constraint + '.w0')
@RedForty
RedForty / userSetup.py
Last active December 24, 2018 07:23
Adds an icon path to your environment variable for relative icon path access in Maya
# ---------------------------------------------------------------------------- #
# Custom Icon Paths
import os
icon_paths = [ # Mind the lack of comma after the last item in the list!
'F:/Dropbox/Code/Maya/KlugTools/Icons',
'F:/Dropbox/Code/Maya/ForeignTools/Icons' # No comma!
]
os.environ['XBMLANGPATH'] += os.pathsep + (os.pathsep).join(icon_paths)
@RedForty
RedForty / spine2Chest.py
Last active May 29, 2018 07:21
Spine2Chest
from maya import cmds
from maya import mel
# If you want to mess with the Char_Anim globals, here you go. Not necessary, though.
# namespace, char = mel.eval('$tempVar = $char').split(':')
# namespace = mel.eval('$tempVar = stringArrayToString($namespc, " ")').split(" ")[0]
sel = cmds.ls(sl=True)
toon = sel[0].rpartition(':')[0]
chest_control = cmds.ls(toon + ':*_ac_cn_chest')[0]
import maya.cmds as cmds
import selectedAttributes
sel = cmds.ls(selection=True)
if cmds.scaleKey(attribute=True): # Is a key/curve selected?
keys = cmds.keyframe(sel, query=True, selected=True) or []
attributes = cmds.keyframe(sel, query=True, selected=True, name=True) or []
first_key = min(keys)
last_key = max(keys)
@RedForty
RedForty / betFitPlane.py
Created November 26, 2017 21:22
Create a best fit plane in maya
import maya.cmds as cmds
import maya.api.OpenMaya as api
def bestFitPlane(points, plane=False):
"""
Takes an array of points (transforms)
Returns a plane located at the centroid of the points
It is oriented as a best fit plane using this method:
http://www.ilikebigbits.com/blog/2017/9/24/fitting-a-plane-to-noisy-points-in-3d
@RedForty
RedForty / shelfBase.py
Created November 7, 2017 20:10 — forked from vshotarov/shelfBase.py
Maya base class for building custom shelves.
import maya.cmds as mc
def _null(*args):
pass
class _shelf():
'''A simple class to build shelves in maya. Since the build method is empty,
it should be extended by the derived class to build the necessary shelf elements.
import maya.cmds as cmds
import selectedAttributes
sel = cmds.ls(selection=True)
if cmds.scaleKey(attribute=True): # Is a key/curve selected?
keys = cmds.keyframe(sel, query=True, selected=True) or []
attributes = cmds.keyframe(sel, query=True, selected=True, name=True) or []
first_key = min(keys)
last_key = max(keys)
@RedForty
RedForty / gist:1096ea845e0302b345506f045c8ecdda
Created October 9, 2017 06:02
Working with relative paths in the reference editor
import os.path
import maya.cmds as cmds
import maya.mel as mel
import maya.OpenMaya as OpenMaya
mel.eval('string $MyScenes; \
putenv $MyScenes "C:/Users/Admin/Desktop/fairy/"')
def foo(retCode, fileObject, clientData):
print "Callback was given %s" % fileObject.rawFullName()
rel = "$MyScenes/"
rel = rel + (os.path.basename(fileObject.rawFullName()))
@RedForty
RedForty / gist:10a6eef9f08aa016f6e4b68f6184e1fb
Created October 9, 2017 05:45
Working with maya.env environment variables
import os
# os.environ is a dict. Key is variable name and value is value.
print os.environ['MAYA_PLUG_IN_PATH']
from PySide2 import QtWidgets
QtWidgets.qApp.setStyleSheet("""
QWidget {
background: #2a2a2a;
color: #999;
}
""")