Skip to content

Instantly share code, notes, and snippets.

@Onefabis
Onefabis / duplicateComponents
Last active May 10, 2018 17:06
duplicate selected components
import maya.api.OpenMaya as om2
import maya.cmds as mc
try:
# get selected components
sel = om2.MGlobal.getActiveSelectionList()
for s in xrange( sel.length() ):
dp, comp = sel.getComponent( s )
# get parent transform node from selected polygons
parentNode = om2.MFnDagNode(dp).parent(0)
@Onefabis
Onefabis / shellsToUVs
Last active February 15, 2024 21:28
Convert UV shells to hard edges
import maya.api.OpenMaya as om2
import maya.cmds as mc
sel = om2.MSelectionList()
sel = om2.MGlobal.getActiveSelectionList()
for s in range( sel.length() ):
dp, comp = sel.getComponent( s )
mItVtx = om2.MItMeshPolygon( sel.getDagPath(s) )
uvsCount = om2.MFnMesh(sel.getDagPath(s)).numUVs()
dag = sel.getDagPath(s).extendToShape()
import math
from mpmath import *
def euclidean_distance(p1, p2):
return math.sqrt(sum([(a - b) ** 2 for a, b in zip(p1, p2)]))
p1 = ( -1.0, 0.0, 1.0 )
p2 = ( 1.0, 0.0, -1.0 )
p3 = ( 1.0, 0.0, 1.0 )
r1 = [ 90.0, 0.0, 0.0 ]
@Onefabis
Onefabis / playBlIncrement
Created April 13, 2018 15:14
Playblast Icrement
playblastPath = mc.optionVar( q='playblastFile')
if len(playblastPath.rsplit('/',1))==1:
playblastPath = mc.workspace( q=1, dir=1 ) + playblastPath
clNum = playblastPath.rsplit('/',1)[-1].rsplit('_',1)
if len(clNum)==1:
playblastPath = playblastPath + '_' + str(1).zfill(4)
else:
playblastPath = playblastPath.rsplit('/',1)[0] + '/' +clNum[0] + '_' + str(int(clNum[-1])+1).zfill(4)
@Onefabis
Onefabis / TransferUVsToSkinned
Last active December 16, 2021 11:09
Transfer UVs from unskinned to skinned mesh
import maya.cmds as mc
'''
Just copy and paste this code into script editor, select the source mesh with correct UVs, then select target skinned mesh and execute the code
If you run transfetUVs(1) if will transfer UVs according to the mesh topology, if you will run it with transfetUVs(0) it will transfer UVs according to the
mesh components. It may not work correctly if the vertex order somehow changed, so keep in mind that 'Topology' method works more correct, hence recommended usage is
transfetUVs(1). Also keep in mind that it works in 99.5% cases, but is is not silver bullet in cases where topology and components are different, so check every mesh after
UV transferring.
'''
@Onefabis
Onefabis / playAdvanced
Created March 1, 2018 22:13
Advanced playback for maya
'''
Just assign to any hotkey short commented code below
import playAdvanced
mods = mc.getModifiers()
if mods == 1:
playAdvanced.playFromTheBeginning()
elif mods == 4:
playAdvanced.loadSteppedScript( 4 )
else:
@Onefabis
Onefabis / Parent_Creator
Last active June 29, 2018 15:08
Fast parent creator for rig controllers
import maya.cmds as mc
'''
Creates new attribute 'Parent_To', name of attribute will be assigned
from exact names of selected Parents
parentSet( 1 ) - means that you need to select parents first and then only the child.
Script will create the rest setup for you
parentSet( 0 ) - means that you need to select parents, then the child parent node
(group that will be assigned by constraint and will be triggered between parents) and
lastly the child node
@Onefabis
Onefabis / AutoRibbon
Last active September 27, 2018 20:30
Create ribbon from selection
'''
1. Launch the script with the command:
import ribb_on
ribb_on.makeRibbSurface()
This will create NURBS surface which goes through all selected objects that need to be snapped to that surface.
After that you will be able to correct the shape of this surface by rotating the profile curve (or maybe scale it). After that you can delete both curves (profile and path)
2. Launch the second script:
import ribb_on
ribb_on.ribbMake( 3, 'parent', 1, 0 )
Where:
/* OctoWS2811 movie2serial.pde - Transmit video data to 1 or more
Teensy 3.0 boards running OctoWS2811 VideoDisplay.ino
http://www.pjrc.com/teensy/td_libs_OctoWS2811.html
Copyright (c) 2013 Paul Stoffregen, PJRC.COM, LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
name = mc.keyframe( q=1, n=1, sl=1 )
objs = mc.ls( sl=1, l=1 )
global glAnCurves
try:
glAnCurves
except:
glAnCurves = []
if len( glAnCurves ) >0 :
mc.selectionConnection( 'graphEditor1FromOutliner', e=1, clr=1 )
allCh = [ g.rsplit( '.', 1 )[0] for g in glAnCurves ]