Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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
def mDagPathFromName( name ):
selList = OpenMaya.MSelectionList()
selList.add( str( name ) )
mDagPath = OpenMaya.MDagPath()
selList.getDagPath( 0, mDagPath )
return mDagPath
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)
# WORKS ONLY IN LEGACY VIEWPORT
import maya.OpenMaya as om
import maya.OpenMayaMPx as mpx
import sys
kPluginCtxName = 'myContext'
kPluginCmdName = 'myContextCmd'
@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.
@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 / enum_shells.py
Created August 29, 2015 11:30
Iterate through all the shells of mesh
from pymel.all import *
def getShellFaces( poly, str = 0 ):
shells = set()
faces = set()
total = polyEvaluate( poly, s=1)
for f in xrange( polyEvaluate( poly, f=1 ) ):
if len( shells ) >= total:
import maya.OpenMaya as OpenMaya
import pymel.core as pm
import math
#Function to get the texture name.
def GetFileTextureName(plug):
connectedPlugs = OpenMaya.MPlugArray()
plug.connectedTo(connectedPlugs, True, False)
for k in range(connectedPlugs.length()):
if (connectedPlugs[k].node().apiType() == OpenMaya.MFn.kFileTexture):