Skip to content

Instantly share code, notes, and snippets.

@SEVEZ
SEVEZ / list_blendshape_targets.mel
Created July 14, 2016 12:51
List blendshape targets in their order inside blendShape node
string $sels[] = `ls -sl`;
string $selsHistory[] = `listHistory $sels[0]`;
string $findBlend[] = `ls -typ blendShape $selsHistory`;
string $findWeights[] = `listAttr -m ($findBlend[0] + ".w")`;
int $k = 2;
for ( $s in $findWeights )
{
print ( $s + "\t" + $k + "\n" );
$k ++;
@SEVEZ
SEVEZ / PS_vertexChamfer.py
Last active November 28, 2017 17:42
Custom vertex chamfer procedure, fixes the bug with multiple selected vertices #WIP
import maya.cmds as mc
import maya.mel as mel
sel = mc.ls( sl=1 )
if len( sel ) > 1:
mc.polyExtrudeVertex( sel, ch=1, d=1, w=0.25 )
mc.polyDelEdge( mc.polyListComponentConversion( mc.filterExpand( mc.polyListComponentConversion( sel, tf=1 ), ex=1, sm=34 ), te=1, internal=1 ), cv=1, ch=1 )
mc.select( cl=1 )
else:
mel.eval( 'polyChamferVtx 1 0.25 0' )
@SEVEZ
SEVEZ / make_locator_shape_from_polymesh.py
Last active September 5, 2017 15:03
Copy polymesh shape to locator #misc
import maya.OpenMaya as OpenMaya
import maya.cmds as cmds
cmds.polySphere()
cmds.spaceLocator()[0]
selection_list = OpenMaya.MSelectionList()
selection_list.add('pSphereShape1')
shape = OpenMaya.MObject()
selection_list.getDependNode(0, shape)
@SEVEZ
SEVEZ / get_selected_components.py
Last active March 9, 2020 07:06
Get selected components indices using Maya API #Snippet
import maya.OpenMaya as om
# To remove duplicates: ids = list(set(ids))
def get_selected_comp_ids():
sel = om.MSelectionList()
om.MGlobal.getActiveSelectionList(sel)
li = 0
path = om.MDagPath()
comp = om.MObject()
stat = sel.getDagPath(li, path, comp)
@SEVEZ
SEVEZ / iterate_selected_components.py
Last active March 21, 2018 18:09
Iterate throught selected components via OpenMaya #Snippet
import maya.OpenMaya as om
sel = om.MSelectionList()
om.MGlobal.getActiveSelectionList(sel)
dag = om.MDagPath()
component = om.MObject()
sel.getDagPath(0, dag, component)
if not component.isNull():
if component.hasFn(om.MFn.kMeshPolygonComponent):
import maya.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx
# Get the selection and create a selection list of all the nodes meshes
selection = OpenMaya.MSelectionList()
OpenMaya.MGlobal.getActiveSelectionList( selection );
# Create an itorator to iterate over the selection
# Use the MFn class to as a filter to filter node types
iter = OpenMaya.MItSelectionList ( selection, OpenMaya.MFn.kGeometric );
@SEVEZ
SEVEZ / access_maya_objs_from_thread.py
Last active September 7, 2017 17:48
Access internal maya objects from any thread via executeInMainThreadWithResult function #Util
import maya.cmds as mc
import maya.utils as mu
import threading
def check1():
return mc.window('MayaWindow', ex=True )
def check2():
return 'TimeSliderMenu' in mc.lsUI('MayaWindow', typ="menu")
@SEVEZ
SEVEZ / print2con.py
Last active July 13, 2019 02:32
Output python prints drectly into console window. Even if Maya freezes console always works #Util
import sys
sys.stdout = sys.__stdout__
dir(sys.stdout)
@SEVEZ
SEVEZ / rr_wrap.py
Created May 11, 2016 20:53 — forked from mclavan/rr_wrap.py
Ryan Roberts - Wrap Deformer
'''
Ryan Roberts - Wrap Deformer
rr_wrap.py
Description:
Ryan Robers created a simple function to create a wrap deformer.
The wrap deformer needs a little more than the deform command to get working.
Michael Clavan
I wanted to have the function also return the deformer to the user. So, my contributions are pretty minor.
I converted the wrap deformer into a pynode object type pm.nt.Wrap.
@SEVEZ
SEVEZ / remove_all_namespaces.py
Last active November 21, 2018 10:49 — forked from mottosso/remove_all_namespaces.py
Remove all namespaces
from maya import cmds
def scene_has_referenced_namespace():
"""Return True if scene has referenced namespace(s)"""
for reference in cmds.ls(type="reference"):
for node in cmds.referenceQuery(reference, nodes=True):
if ":" in node:
return True
return False