Skip to content

Instantly share code, notes, and snippets.

View dgovil's full-sized avatar

Dhruv Govil dgovil

View GitHub Profile
@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)
@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 / 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 / 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 / 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 / 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 / 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 / windowPositions.py
Created January 21, 2017 04:08
Saving Window Positions in PyQt or PySide
# First lets import the two modules we'll need from Qt
from Qt import QtWidgets, QtCore
# Then we create our Window class, in this case from a QDialog
class MyWindow(QtWidgets.QDialog):
def __init__(self):
# We use the __init__ method to initialize it
# The super function gets the class we are inheriting from (in this case QDialog) and calls its' __init__ as well
@dgovil
dgovil / mayaFileImportNodeQuery.py
Created January 21, 2017 04:20
Finding what nodes were imported from a Maya file
# First lets import our Maya command library
from maya import cmds
# Then we import our file. In this case I'm using a hardcoded value
# But notice the returnNewNodes parameter that tells it to give us back any imported nodes
# This may contain nodes we don't want
# So we'll need to shorten it down
nodes = cmds.file('C:/Users/dhruv/Documents/maya/controllerLibrary/bigdonut.ma',
i=True, returnNewNodes=True)
@dgovil
dgovil / pyside_dynamic.py
Created April 6, 2017 00:09 — forked from cpbotha/pyside_dynamic.py
pyside_dynamic.py with minor improvements - also see http://stackoverflow.com/a/14894550/532513
#!/usr/bin/python2
# -*- coding: utf-8 -*-
# Copyright (c) 2011 Sebastian Wiesner <lunaryorn@gmail.com>
# Modifications by Charl Botha <cpbotha@vxlabs.com>
# * customWidgets support (registerCustomWidget() causes segfault in
# pyside 1.1.2 on Ubuntu 12.04 x86_64)
# * workingDirectory support in loadUi
# found this here:
# https://github.com/lunaryorn/snippets/blob/master/qt4/designer/pyside_dynamic.py