Skip to content

Instantly share code, notes, and snippets.

@SEVEZ
SEVEZ / PS_edgeloop.py
Last active November 28, 2017 17:42
Custom edgeloop selection #WIP
from pymel.all import *
def selectEdgeLoop():
edge = ls( sl=1, fl=1 )[0]
shp = PyNode( ls( hl=1 )[0] ).getShape()
vertices = edge.connectedVertices()
newEdges = []
newEdges.append( edge )
@SEVEZ
SEVEZ / select_polystrip_ends.py
Created August 29, 2015 11:31
Select polygon strip objects ends
import maya.OpenMaya as om
import maya.cmds as cmds
def edgeCapSelector():
# Check if vertices or faces were selected.
# If True convert selection to edges.
verts = cmds.filterExpand(sm = 31, ex = True, fullPath = True)
faces = cmds.filterExpand(sm = 31, ex = True, fullPath = True)
if verts is not None or faces is not None:
cmds.ConvertSelectionToEdges()
# Create variable of special class MScriptUtil.
# WORKS ONLY IN LEGACY VIEWPORT
import maya.OpenMaya as om
import maya.OpenMayaMPx as mpx
import sys
kPluginCtxName = 'myContext'
kPluginCmdName = 'myContextCmd'
import maya.OpenMaya as OpenMaya
import maya.OpenMayaUI as OpenMayaUI
def selectAllVisibleObjectsFromScreen():
activePane=OpenMayaUI.M3dView.active3dView()
w=activePane.portWidth()
h=activePane.portHeight()
myX=OpenMaya.MScriptUtil()
myX.createFromInt(0)
def mDagPathFromName( name ):
selList = OpenMaya.MSelectionList()
selList.add( str( name ) )
mDagPath = OpenMaya.MDagPath()
selList.getDagPath( 0, mDagPath )
return mDagPath
@SEVEZ
SEVEZ / Lazy_selection.py
Created August 29, 2015 11:31
Select object objects, closest to cursor
import maya.cmds as cmds
from pymel.core import *
from pymel.core.datatypes import *
import maya.OpenMaya as om
import maya.OpenMayaUI as omui
class SamsClass():
ctx = cmds.currentCtx()
cto = cmds.contextInfo(ctx,c=1)
print cto
@SEVEZ
SEVEZ / gep_OpenGL_panel_rez.py
Created August 29, 2015 11:31
get openGL screen size
def getScreenRes(panel):
m3v = OpenMayaUI.M3dView.active3dView()
OpenMayaUI.M3dView.getM3dViewFromModelPanel(panel, m3v)
xPtr = OpenMaya.MScriptUtil().asUintPtr()
yPtr = OpenMaya.MScriptUtil().asUintPtr()
widthPtr = OpenMaya.MScriptUtil().asUintPtr()
heightPtr = OpenMaya.MScriptUtil().asUintPtr()
m3v.viewport(xPtr, yPtr, widthPtr, heightPtr)
@SEVEZ
SEVEZ / get_obj_screen_pos.py
Created August 29, 2015 11:31
Get object screen position
# Use M3dView.
def screenPositionAPI(panel, pos):
mp = OpenMaya.MPoint(pos[0], pos[1], pos[2])
m3v = OpenMayaUI.M3dView.active3dView()
OpenMayaUI.M3dView.getM3dViewFromModelPanel(panel, m3v)
xp = OpenMaya.MScriptUtil().asShortPtr()
yp = OpenMaya.MScriptUtil().asShortPtr()
ret = m3v.worldToView(mp, xp, yp)
x = OpenMaya.MScriptUtil().getShort(xp)
@SEVEZ
SEVEZ / extend_polysel_to_shell.py
Created August 30, 2015 18:16
Extend polygons selection to shell
import maya.OpenMaya as om
import maya.cmds as cmds
def expandSelection():
sel = om.MSelectionList()
om.MGlobal.getActiveSelectionList(sel)
dag = om.MDagPath()
obj = om.MObject()
# get the active object (dag) and its selected components (obj)
sel.getDagPath(0, dag, obj)
@SEVEZ
SEVEZ / ehm_flattenDeformer2.py
Created August 31, 2015 08:25
Simple flatten deformer
'''
import maya.cmds as cmds
if not cmds.pluginInfo( 'ehm_flattenDeformer2.py', l=1, q=1 ):
if cmds.loadPlugin( 'ehm_flattenDeformer2.py') == None:
cmds.warning('Failed to load plugin.')
# Apply the deformer
cmds.deformer( name="Flatten_Deform", type='ehm_flattenDeformer2' )