Skip to content

Instantly share code, notes, and snippets.

@blockinhead
blockinhead / http_to_maya.py
Last active May 6, 2023 18:00
a simple http to maya gateway on flask
import socket
from flask import Flask, request, jsonify
MAYA_HOST = '127.0.0.1'
MAYA_MEL_PORT = 7003
HTML = f'''
<!doctype html>
<title>htom</title>
<h1>your maya command</h1>
from auth import session
import ftrack_api.event.base
def note_validator(entity):
return any(map(lambda x: x['entity_type'] in ('Task', 'AssetVersion'), entity['parents']))
def version_validator(entity):
asset_version = session.get(entity['entity_type'], entity['entityId'])
@blockinhead
blockinhead / load_ui.py
Created August 13, 2022 15:08
a function for PySide2 to load ui to self like it can be done in PyQt
from PySide2 import QtCore, QtUiTools
import os
import importlib
def load_ui(uifile, baseinstance=None):
"""
a function to load an ui file to self like this
class CreateAssetGui(QtWidgets.QDialog):
@blockinhead
blockinhead / watch_tunnel.sh
Created November 5, 2021 11:37
kills hanging rdp connections tunneled through ssh
#!/bin/bash
while true
do
tunnels=`lsof -i | grep *:3389 | wc -l`
# echo $tunnels
if [ "$tunnels" == "2" ]
then
:
# echo the tunnel is ok
@blockinhead
blockinhead / rig_a_ramp.py
Created June 8, 2021 07:49
a function to create an animated ramp to color a curve for arnold in maya
import pymel.core as pm
import random
def ramp_to_curve(curve, anim_length=20, color1=(0.01, 0.01, 0.01), color2=(1, 1, 1)):
ramp = pm.shadingNode('ramp', asTexture=True)
place2d = pm.shadingNode('place2dTexture', asUtility=True)
place2d.outUV >> ramp.uvCoord
place2d.outUvFilterSize >> ramp.uvFilterSize
ramp.cel[2].ep.set(1)
ramp.cel[0].color.set(color1)
@blockinhead
blockinhead / qt_https_client.py
Created November 3, 2020 08:37
pyside2 https client with self-signed certificate
import sys
from PySide2 import QtNetwork
from PySide2.QtCore import QCoreApplication, QUrl, QFile
class NetworkManagerWrapper(object):
def __init__(self):
print(f'{QtNetwork.QSslSocket.sslLibraryBuildVersionString()=}') # openssl version need to by installed
print(f'{QtNetwork.QSslSocket.supportsSsl()=}') # have to be true
@blockinhead
blockinhead / move_verts.py
Created October 15, 2020 13:59
pymel demo script to animate vertices of selected mesh
import pymel.core as pm
from random import uniform
def tremor_curve(src_curve, frame_step, amplitude):
num_keys = src_curve.numKeys()
min_frame = src_curve.getTime(0)
max_frame = src_curve.getTime(num_keys - 1)
for f in range(int(min_frame) + frame_step, int(max_frame), frame_step):
import random
import sys
from PySide2 import QtWidgets, QtCore
PROGRAMS = [
['ping.exe', ['google.com']],
['notepad.exe', []],
['nothing', []],
]
@blockinhead
blockinhead / qthread_research.py
Created May 10, 2020 11:26
an example of creation of a qthread and emitting custom signals
import random
import sys
import time
from PySide2 import QtWidgets, QtCore
class MyThread(QtCore.QThread):
message = QtCore.Signal(str)
@blockinhead
blockinhead / follicle_in_vertex.py
Created February 26, 2019 09:49
pymel script to grow follicle in selected vertex
import pymel.core as pm
sel = pm.selected()[0]
shape = sel.node()
follicle_shape = pm.createNode('follicle', skipSelect=True)
follicle_tr = follicle_shape.getParent()
shape.outMesh >> follicle_shape.inputMesh
shape.worldMatrix[0] >> follicle_shape.inputWorldMatrix
follicle_shape.outRotate >> follicle_tr.rotate
follicle_shape.outTranslate >> follicle_tr.translate
u, v = sel.getUV()