Skip to content

Instantly share code, notes, and snippets.

View dgovil's full-sized avatar

Dhruv Govil dgovil

View GitHub Profile
@dgovil
dgovil / initExplanation.py
Created January 20, 2017 04:05
Explaining Class and Instance variables
# You can ignore this. It's just so I can use print like it is in Python 3
from __future__ import print_function
# This is an object. This is one of Python's most basic types and what all classes should inherit from eventually.
# So even if your class inherits from another class which in turn inherits from another class, eventually if you follow it all the way back it should inherit from object
myObject = object()
# Object has a method called __init__
print(myObject.__init__) # <method-wrapper '__init__' of object object at 0x000001F746C1F0A0>
@dgovil
dgovil / mayaCustomMarkers.py
Last active October 21, 2018 04:29
Allows a user to create custom markers in maya.Based off of this pastebin: http://pastebin.com/Uc8S4QPx (which may further be from createive Crash) and further work by https://github.com/achayan and his pasteBin http://pastebin.com/JGJZ5uu1
from PyQt4 import QtGui, QtCore
import maya.cmds as cmds
import maya.OpenMayaUI as mui
import sip
def convertToQT(controlName):
controlPoniter = mui.MQtUtil.findControl(controlName)
if controlPoniter is not None:
return sip.wrapinstance(long(controlPoniter), QtCore.QObject)
@dgovil
dgovil / dgCameraDisplayFilter.py
Created April 11, 2014 18:59
Snippet to go through all the cameras, turn off joints and IK handles, and only show curves in the default cameras
import maya.cmds as mc
panels = mc.getPanel(typ='modelPanel')
for pan in panels:
cam = mc.modelPanel(pan, q=1, camera=1)
startup = mc.camera(cam, q=1, sc=1)
mc.modelEditor(pan, e=1, joints=0, nurbsCurves=startup, ikHandles=0)
@dgovil
dgovil / shelfOrder.py
Created October 12, 2013 23:37
Order Maya Shelves. The pref keyword is set to xxx but you can set it to whatever and it'll keep any shelves that start with it in the front
import maya.cmds as mc
import maya.mel as mm
gshelf = mm.eval("$temp = $gShelfTopLevel")
shelves = mc.tabLayout(gshelf,q=1,childArray=1)
sTotal = len(shelves)
pref = 'xxx'
sShelf = sorted([s for s in shelves if s.startswith(pref)]) + sorted([s for s in shelves if not s.startswith(pref)])
@dgovil
dgovil / ScaleX2ScaleZ.py
Last active December 19, 2015 04:39
Copies all mesh scale X values to scale Z
import maya.cmds as mc
objList = mc.ls(sl=1)
objList = mc.listRelatives(objList,ad=1,typ="mesh")
objList = mc.listRelatives(objList,type='transform',p=True)
for obj in objList:
mc.setAttr(obj+".sz",mc.getAttr(obj+".sx"))
@dgovil
dgovil / Conform Keys.py
Created June 3, 2013 01:08
Set whatever object you want as the master object. It'll clean up all the other selected controllers to only have keyframes when the master controller does.
masterObject = "controllerName"
import maya.cmds as mc
objs = mc.ls(sl=1)
keyframes = mc.keyframe(masterObject,q=1)
fs = int( mc.playbackOptions(q=1, ast=1 ) )
fe = int( mc.playbackOptions(q=1, aet=1 ) )
keyframes = sorted( [k for k in set(keyframes) if k>=fs and k<=fe] )
@dgovil
dgovil / gist:5600960
Last active December 17, 2015 11:19
Create maya key pairs
import maya.cmds as mc
objs = mc.ls(sl=1)
keyframes = mc.keyframe(objs,q=1)
fs = int( mc.playbackOptions(q=1, ast=1 ) )
fe = int( mc.playbackOptions(q=1, aet=1 ) )
keyframes = sorted( [k for k in set(keyframes) if k>=fs and k<=fe] )
for k in keyframes:
mc.setKeyframe(objs,t=[k],i=True)