Skip to content

Instantly share code, notes, and snippets.

@SEVEZ
SEVEZ / PS_Attach.py
Last active February 12, 2021 22:53
Attach meshes to last selected, keeping pivots, transforms and hierarchy. Remake of script by Thomas Hamilton from here http://www.creativecrash.com/maya/script/attachmaster #WIP
import maya.cmds as mc
import string
def PS_Attach( objs ):
def dag_par( obj ):
if isinstance( obj, basestring ):
return string.join( mc.listRelatives( obj, pa=1, f=1 )[0].split('|')[:-1], '|' )
@SEVEZ
SEVEZ / MatFaceFinder.mel
Last active September 6, 2015 21:18
Select one face on an object. Run MatFaceFinder. This script will select all of the faces strictly on that object which share the same material assignment as the first face.
// SCRIPT NAME: MatFaceFinder.mel v1.1 (Maya2009 version)
// AUTHOR: Thomas Hamilton
// LAST UPDATED: November 16, 2009
// www.thomashamilton.org
//DESCRIPTION:
//Select one face on an object. Run MatFaceFinder. This script will select all of the faces
//strictly on that object which share the same material assignment as the first face.
@SEVEZ
SEVEZ / PS_perspOrthoToggl_v3.py
Last active July 5, 2025 20:07
Switch between perspective and matching orthographic view. The latest version is v3. #Release
# Latest version, uses Tumble Pivot Point viewport
# feature, and proprietary algorithm, works in all recent
# versions of Maya, Python 2.7 / 3+. Gives more predictable
# and stable results.
# Pavel Sevets 2022
import maya.cmds as mc
import maya.api.OpenMaya as om
from math import pi
@SEVEZ
SEVEZ / PS_trUV.py
Last active February 2, 2021 02:05
Transfer current uv set from last selected object to current uv sets of all others #Final
import maya.cmds as mc
sel = mc.ls( sl=1 )
sUV = mc.polyUVSet( sel[-1], q=1, cuv=1 )[0]
for d in sel[:-1]:
mc.transferAttributes( sel[-1], d, uvs=1, suv=sUV, tuv=mc.polyUVSet( d, q=1, cuv=1 )[0], col=0, spa=0, sm=3, fuv=0, clb=0, pos=0, nml=0 )
@SEVEZ
SEVEZ / Normals_from_polys.py
Created October 3, 2015 12:11
Normals from selected polygons
import maya.cmds as cmds
faces = cmds.filterExpand(sm=34, ex=True)
verts = cmds.ls((cmds.polyListComponentConversion(faces, ff=True, tv=True)), flatten=True)
normals = [[], [], []]
for v in verts:
conFaces = cmds.ls(cmds.polyListComponentConversion(v, fv=True, tf=True), flatten=True)
shaFaces = list(set(conFaces).intersection(set(faces)))
from PySide import QtCore, QtGui
from shiboken import wrapInstance
import maya.OpenMayaUI as mui
mainWin = wrapInstance(long(mui.MQtUtil.mainWindow()), QtGui.QWidget)
action = QtGui.QAction(mainWin)
action.setShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Tab))
action.setShortcutContext(QtCore.Qt.ApplicationShortcut)
import maya.OpenMaya as OpenMaya
selection = OpenMaya.MSelectionList()
OpenMaya.MGlobal.getActiveSelectionList( selection )
iterSel = OpenMaya.MItSelectionList(selection, OpenMaya.MFn.kMesh)
while not iterSel.isDone():
dag_path_object = OpenMaya.MDagPath()
iterSel.getDagPath( dag_path_object )
@SEVEZ
SEVEZ / mirror_names.py
Last active February 25, 2016 18:59
Match selected object names by their symetrical position across X. If L_arm matches R_leg, L-arm -> L_leg.
import maya.cmds as mc
eps = 1E-5
sel = mc.ls( sl=1 )
while sel:
v = mc.xform( sel[0], q=1, rp=1, ws=1 )
@SEVEZ
SEVEZ / dupMeshOnly.py
Created May 3, 2016 20:20
Duplicate only selected meshes without children, materials etc.
import maya.cmds as mc
sel = mc.ls( sl=1 )
def dupMeshOnly( obj ):
objShape = mc. listRelatives( obj, s=1 )
par = mc.duplicate( objShape[0], po=1 )
shape = mc.createNode( 'mesh', p=par[0] )
mc.connectAttr( objShape[0] + '.outMesh', shape + '.inMesh', f=1 )
@SEVEZ
SEVEZ / proximity_scaleup_expression.mel
Created May 5, 2016 12:10
Apply scale expression to selected objects. They will scale up as locator1 approximates them.
$sel = `ls -sl`;
for ( $s in $sel )
{
$s = $s;
$loc = "locator1";
$constr = "$dx = " + $loc + ".tx - " + $s + ".tx; $dy = " + $loc + ".ty - " + $s + ".ty; $dz = " + $loc + ".tz - " + $s + ".tz; $vlen = sqrt( $dx * $dx + $dy * $dy + $dz * $dz ); if ( $vlen > 5 ) " + $s + ".scaleX = 1; else " + $s + ".scaleX = ( cos( ( $vlen - 1 ) / 5 * 3.141592 ) + 1 ) / 2 * 0.35 + 1;";
expression -s $constr -o $s -ae 1 -uc all ;
$constr = "$dx = " + $loc + ".tx - " + $s + ".tx; $dy = " + $loc + ".ty - " + $s + ".ty; $dz = " + $loc + ".tz - " + $s + ".tz; $vlen = sqrt( $dx * $dx + $dy * $dy + $dz * $dz ); if ( $vlen > 5 ) " + $s + ".scaleY = 1; else " + $s + ".scaleY = ( cos( ( $vlen - 1 ) / 5 * 3.141592 ) + 1 ) / 2 * 0.35 + 1;";
expression -s $constr -o $s -ae 1 -uc all ;
$constr = "$dx = " + $loc + ".tx - " + $s + ".tx; $dy = " + $loc + ".ty - " + $s + ".ty; $dz = " + $loc + ".tz - " + $s + ".tz; $vlen = sqrt( $dx * $dx + $dy * $dy + $dz * $dz ); if ( $vlen > 5 ) " + $s + ".scaleZ = 1; else " + $s + ".scaleZ = ( co