Skip to content

Instantly share code, notes, and snippets.

@SEVEZ
SEVEZ / vertex_normals_from_sel_faces.py
Created August 29, 2015 11:23
Sets the vertex normals of a face selection, averaging normals shared by multiple selected faces.
# ---------------------------------------------------------------------------------------
# - pompVertNormFaceAvg
#
# - Sets the vertex normals of a face selection,
# averaging normals shared by multiple selected faces.
#
#
# - by Pontus Karlsson 2013 (www.pomperi.com)
# ---------------------------------------------------------------------------------------
@SEVEZ
SEVEZ / resize_tex.py
Last active September 7, 2017 17:49
Resize textures using python #Util
import maya.cmds as cmds
import maya.OpenMaya as om
fileNodes = cmds.ls(sl=1)
width = 1024
height = 1024
image = om.MImage()
for i in fileNodes:
filePath = cmds.getAttr(i+'.fileTextureName')
@SEVEZ
SEVEZ / open_temp_dir.py
Last active September 7, 2017 17:49
Open Temp directory #Util
import os
import tempfile
os.startfile( tempfile.gettempdir() )
@SEVEZ
SEVEZ / PyQT4_to_PySide.py
Last active September 5, 2017 15:04
PyQT4 to PySide conversion #misc
# PyQt
from PyQt4 import QtCore, QtGui
import sip
long(sip.unwrapinstance( obj ))
sip.wrapinstance(long(ptr), QtCore.QObject)
sip.wrapinstance(long( OpenMayaUI.MQtUtil.mainWindow() ), QtCore.QObject )
# PySide
from PySide import QtGui, QtCore
import shiboken
@SEVEZ
SEVEZ / select_all_by_type_in_hierarchy.py
Created August 29, 2015 11:23
Select all object by type within hierarchy
cmds.select(cmds.ls(dag=1, ap=1, sl=1, type="joint"))
cmds.select(cmds.ls(dag=1, ap=1, sl=1, type="nurbsCurve"))
cmds.select(cmds.ls(dag=1, ap=1, sl=1, type="constraint"))
@SEVEZ
SEVEZ / RGB_hue_shift_on_RYB_wheel.js
Created August 29, 2015 11:23
Shift RGB colors along RYB artistic color wheel
// Preview online
// http://www.deathbysoftware.com/colors/index.html
function rgb2ryb ( iRed, iGreen, iBlue )
{
// Remove the white from the color
var iWhite = Math.min( iRed, iGreen, iBlue );
iRed -= iWhite;
iGreen -= iWhite;
import pymel.all as pm
def get_selected_uv_shells():
sel = pm.selected(o = True)[0]
selected_uvs = set(uv for uv in pm.selected() if isinstance(uv, pm.MeshUV))
# getUvShellsIds returns a list of shell_ids, and the number of shells
uv_shell_ids, num_shells = sel.getUvShellsIds()
# You still need to actually get the MeshUVs yourself
# Using sets instead of sublists because checking if an item is in a set is much faster
all_shells = [set() for i in xrange(num_shells)]
def getUVShells(shape, uvSet=None):
uvSets = cmds.polyUVSet(shape, q=True, allUVSets=True)
if not uvSet or uvSet not in uvSets:
uvSet = cmds.polyUVSet(shape, q=True, cuv=True)[0]
selectionList = om.MSelectionList()
selectionList.add(shape)
mDag = om.MDagPath()
@SEVEZ
SEVEZ / check_ref_obj.py
Created August 29, 2015 11:26
Check if object is referenced
selection = cmds.ls(sl = True)
for model in selection:
refcheck = cmds.referenceQuery(model, inr = True)
if (refcheck == 1):
reftodel = cmds.referenceQuery(model, f = True)
cmds.file(reftodel, rr = True)
cmds.file(newfile, r=True)
else:
cmds.delete(model)
cmds.file(newfile, i=True)
import maya.cmds as cmds
def dragAttr( attr_names ):
if not cmds.dragAttrContext('dragAttributeCtx', ex=True):
cmds.dragAttrContext('dragAttributeCtx')
cmds.dragAttrContext( 'dragAttributeCtx', e=True, ct=attr_names )
cmds.setToolTo( 'dragAttributeCtx' )
dragAttr( "Push_Deform2.inflation" )