Skip to content

Instantly share code, notes, and snippets.

Avatar

Justin Israel justinfx

View GitHub Profile
@justinfx
justinfx / MImage_to_QImage.py
Created Jan 28, 2016
Passing pixel pointer from a Maya MImage to Qt's QImage
View MImage_to_QImage.py
"""
Simplified version of original forum post:
http://tech-artists.org/forum/showthread.php?4547-Passing-uchar-pointer-with-PySide-in-Maya
"""
import ctypes
import maya.OpenMaya as om
from PySide import QtCore, QtGui
# Build a test MImage
@justinfx
justinfx / cix_to_py.py
Created Jun 1, 2014
A small script to convert a .cix (codeintel schema) file into a python stub module, for use in auto-completion
View cix_to_py.py
#!/usr/bin/env python
'''
A small script to convert a .cix (codeintel schema) file into
a python stub module, for use in auto-completion.
https://community.activestate.com/faq/codeintel-cix-schema
Requires jinja2 for the output template format
'''
@justinfx
justinfx / shells.py
Created Sep 17, 2012
function for returning the selectable shells of a poly
View shells.py
def getShellFaces(poly, asString=False):
shells = set()
faces = set()
total = cmds.polyEvaluate(poly, s=True)
for f in xrange(cmds.polyEvaluate(poly, f=True)):
if len(shells) >= total:
break
if f in faces:
@justinfx
justinfx / maya_qt_error_decorator.py
Created Jan 12, 2017
A decorator to wrap Qt slots, in Maya, so that exceptions are reported to Script Editor
View maya_qt_error_decorator.py
"""
A decorator to wrap Qt slots, in Maya, so that exceptions are reported to Script Editor
Ref: https://groups.google.com/d/topic/python_inside_maya/xv7DCiocDZA/discussion
justinisrael@gmail.com
"""
#...
import sys
@justinfx
justinfx / tree_widget_drag.py
Created Feb 20, 2020
Capturing the start and end item/index information in a PySide2 QTreeWidget internal drag and drop
View tree_widget_drag.py
"""
https://groups.google.com/d/msg/python_inside_maya/1EzNG_i9Xes/Au-18UaXAwAJ
Capturing the start and end item/index information in a
PySide2 QTreeWidget internal drag and drop
"""
from __future__ import print_function
from PySide2 import QtCore, QtGui, QtWidgets
@justinfx
justinfx / maya_script_editor.py
Last active Nov 19, 2019
An example of how to use multiprocessing from within Maya, by actually running it as a subprocess and communicating back the results.
View maya_script_editor.py
"""
This code can be run from a Maya script editor
"""
import subprocess
import cPickle
print 'This value below should be a 1000:'
p = subprocess.Popen(["/path/to/multi_test.py", "-po"], stdout=subprocess.PIPE)
result = cPickle.load(p.stdout)
@justinfx
justinfx / py3_asyncore_server.py
Created Oct 24, 2017
python3 asyncore + threading socket server
View py3_asyncore_server.py
import asyncore
import socket
import threading
class ChatServer(asyncore.dispatcher):
def __init__(self, host, port):
asyncore.dispatcher.__init__(self)
@justinfx
justinfx / read_qt_process.py
Last active Jul 11, 2019
2 different examples of reading the progressive output of a process in PyQt. 1) Using a QProcess 2) Using subprocess [https://groups.google.com/d/msg/python_inside_maya/x9COZGNPGEU/gD4xpbs3S08J]
View read_qt_process.py
from functools import partial
from subprocess import Popen, PIPE
from PyQt4 import QtCore, QtGui
## testProgram.sh
"""
#!/bin/bash
@justinfx
justinfx / qt_proxy_model.py
Created Jun 17, 2019
Minimal Qt example of adding a "virtual row" via a proxy model
View qt_proxy_model.py
#!/usr/bin/env python
"""
Refs:
"[Maya-Python] Customized display of files/folders in a QTreeView that is using QFileSystemModel."
https://groups.google.com/d/topic/python_inside_maya/TaFm2yNToJ8/discussion
"""
from PySide import QtCore, QtGui
@justinfx
justinfx / mayaVertFaceSelect.py
Created Nov 27, 2011
Selecting staggered vert/face from start and stop original selection
View mayaVertFaceSelect.py
import re
import maya.cmds as cmds
def getSelectedInts():
rx = re.compile(r'\[(\d+)\]$')
intList = []
sel = cmds.ls(sl=True)
if not sel:
return "", []