Skip to content

Instantly share code, notes, and snippets.

View davidlatwe's full-sized avatar
:shipit:
Awesome

David Lai davidlatwe

:shipit:
Awesome
View GitHub Profile
"""Testing generator that yields within a context and interrupt by error
Looks like the context is being closed by the python garbage collection if
error raised during the iteration.
https://stackoverflow.com/a/19825163/4145300
"""
import sys
from contextlib import contextmanager
@davidlatwe
davidlatwe / README.md
Created February 7, 2020 13:07
Weird Maya bug that involves referencing shared unknown nodes and threading

Maya version: 2018 update 6 OS: Windows 10

  1. Save those two .ma file in a folder.
  2. Open work.ma, it should have upstream.ma referenced.
  3. Execute the script crash.py.
  4. Save the scene and Maya will crash.
@davidlatwe
davidlatwe / pyblish_qml_post_collect_demo.py
Created February 6, 2020 08:48
An example for demoing Pyblish-QML new feature "Post Collect"
import os
import pyblish.api
import pyblish_qml
class CreateToy(pyblish.api.ContextPlugin):
order = pyblish.api.CollectorOrder - 0.2
def process(self, context):
instance = context.create_instance("Bear")
@davidlatwe
davidlatwe / demo.py
Created February 4, 2020 19:28
Demonstrate how QQmlContext's property may be garbage collected before QML component gets destroyed and leads to "TypeError: Cannot read property 'foobar' of null" in PySide2
import sys
from PySide2 import QtCore, QtGui, QtQuick
class Data(QtCore.QObject):
color = QtCore.Property(str, fget=lambda _: "purple", constant=True)
if __name__ == '__main__':
@davidlatwe
davidlatwe / get_user_knobs.py
Last active November 29, 2019 07:40
[Nuke] Listing all user defined knobs in given node
import nuke
import re
def list_user_knobs(node):
"""Get user defined knobs
Args:
node (nuke.Node): Nuke node object
@davidlatwe
davidlatwe / plugins.py
Created September 1, 2019 10:17
Maya scene modification aware via Pyblish
"""Implement scene modification awareness
By tracking Maya's undo queue, if there are any undo command that is not
a simple select after collecting completed, consider this scene has been
modified and require to reset Pyblish.
"""
import collections
# -*- coding: utf-8
import os
import pyblish.api
import pyblish_qml
import pyblish_qml.settings
class CreateInstances(pyblish.api.ContextPlugin):
"""Create instance"""
from avalon.vendor.Qt import QtWidgets, QtCore, QtGui
from avalon.vendor import qtawesome
from avalon import tools, style
import logging
import threading
import time
main_logger = logging.getLogger()
@davidlatwe
davidlatwe / maya_get_visible_in_frame_range.py
Created August 8, 2019 07:24 — forked from BigRoy/maya_get_visible_in_frame_range.py
An optimized Maya function that returns the dag node names that are at least visible once on whole frames between requested start and end frame, this accounts for animated visibilities of the nodes and their parents.
import maya.api.OpenMaya as om2
import maya.cmds as mc
import contextlib
from colorbleed.maya.lib import iter_parents
@contextlib.contextmanager
def maintained_time():
ct = cmds.currentTime(query=True)
@davidlatwe
davidlatwe / forceElement_failed_demo.py
Last active August 21, 2020 06:38
Maya command `sets -forceElement` failed cases
"""
Maya command `sets -forceElement` failed cases
"""
from maya import cmds
CUBE = None