Skip to content

Instantly share code, notes, and snippets.

@Onefabis
Onefabis / ConnectionsInspector
Last active May 10, 2022 13:49
Look for any node connections for selected objects in Maya
'''
Select any object and run the script, it will select any node, specified in the list of the "getDG" nType array
Some api node type examples:
Camera = camera
Parent Constraint = parentConstraint
Point Constraint = pointConstraint
Orient Constraint = orientConstraint
Aim Constraint = aimConstraint
Scale Constraint = scaleConstraint
Skin Cluster = skinCluster
@Onefabis
Onefabis / placeLoc
Created December 9, 2019 20:15
place locators in space of selected object
import maya.cmds as mc
locResult = mc.promptDialog( title='Insert Locators', message='Locator count:', button=['OK', 'Cancel'], defaultButton='OK', cancelButton='Cancel', dismissString='Cancel')
if locResult == 'OK':
locCount = mc.promptDialog( q=1, text=1)
if not locCount or not int(locCount) :
locCount = 1
sel = mc.ls( sl=1 )
for s in sel:
pos = mc.xform( s, q=1, t=1, ws=1 )
for l in xrange( int( locCount ) ):
@Onefabis
Onefabis / colorAttributes
Created October 3, 2019 16:21
Plugin for colorizer script in order to attribute color in the channel box
import ast
import sys
import maya.api.OpenMaya as om2
import maya.cmds as mc
import colorsys
# Plug-in information:
kPluginNodeName = 'colorAttributes'
kPluginNodeClassify = 'utility/general'
kPluginNodeId = om2.MTypeId( 0x86025 )
import maya.cmds as mc
selDrivers = mc.textScrollList( "driverObjects", q=1, si=1 )
if not selDrivers:
selDrivers = mc.ls( sl=1 )
outPlug = mc.listConnections( selDrivers, c=1, d=1, s=0 )
if outPlug:
animCurves = outPlug[1::2]
animCurvesU = [ a for a in animCurves if 'animCurveU' in mc.ls( a, st=1)[-1] ]
if animCurvesU:
drivens = mc.listConnections( animCurvesU, c=1, d=1, s=0 )
@Onefabis
Onefabis / fastTextureReplacePath
Last active August 30, 2019 22:17
Fast replace textures paths for maya in case textures folders was changed
import os.path
import maya.cmds as mc
'''
you can call script from this command at the end of the code
fastTextureReplacePath()
it will search based on the path of your scene, i.e., it will seek inside subfolders in the folder where your scene is
@Onefabis
Onefabis / GameExpFromTimelineMarkers
Created August 6, 2019 13:13
Autofill game exporter from timelineMarkers data
import maya.mel as mel
import maya.cmds as mc
import os
import json
path = mc.file(q=1, sn=1).rsplit( '/', 1 )[0]
stored = mc.fileInfo( "timelineMarkers", q=1 )
if stored: info = json.loads( stored[ 0 ].replace( '\\"', '"') )
else: info = dict()
frames = info.get( "frames" ) or []
@Onefabis
Onefabis / GrowSkinWeights
Created June 3, 2019 14:22
Grow Skin Weights from selected vertices to adjacent vertices
import maya.api.OpenMaya as om2
import maya.api.OpenMayaAnim as oma2
import maya.cmds as mc
class growSkinWeights(object):
def __init__(self):
self.cIds = None
def growSkinDo(self, mode):
@Onefabis
Onefabis / GrowSkinWeights
Created June 3, 2019 14:22
Grow Skin Weights from selected vertices to adjacent vertices
import maya.api.OpenMaya as om2
import maya.api.OpenMayaAnim as oma2
import maya.cmds as mc
class growSkinWeights(object):
def __init__(self):
self.cIds = None
def growSkinDo(self, mode):
@Onefabis
Onefabis / spaceObjects
Created April 13, 2019 03:58
space objects evenly
import maya.cmds as mc
import maya.api.OpenMaya as om2
def spread(x,objType='spaceLocator'):
sel = mc.ls( sl=1 )
if len(sel) != 2:
mc.warning('Please select two objects')
return
pos1 = mc.xform( sel[0], q=1, ws=1, t=1 )
@Onefabis
Onefabis / addToGroup.py
Last active April 10, 2019 20:41
Quickly add selected objects into empty group for every selected object
import re
import maya.cmds as mc
def addToGroup( *args ):
post,replacePost,postIndex,dupIgnore = parseArgs( args )
allObj = mc.ls( sl=1, l=1 )
rootNode = [ a.rsplit('|',a.count('|')-1 )[0] if a.count('|') > 1 else a for a in allObj ]
newHi = sum( ( [ k for k in mc.listRelatives( m, ad=1, typ='transform', f=1 ) ] + [m] if mc.listRelatives( m, ad=1, typ='transform', f=1 ) else [m] for m in list( set( rootNode ) ) ), [] )
hiSel = [ x for x in newHi if x in allObj ]
newNObjects = []
for a in hiSel: