Skip to content

Instantly share code, notes, and snippets.

View zhollosy's full-sized avatar

Zola zhollosy

  • EU
View GitHub Profile
@zhollosy
zhollosy / MAYA__snap_to_nearest_axes.py
Last active October 8, 2025 12:20
Snaps Maya's nearly matching transform objects together, snapping rotations to closest axes (not tested on scaled transforms)
import pymel.core as pm
obj, trg = pm.selected()
obj_mtx = obj.getMatrix(worldSpace=True)
trg_mtx = trg.getMatrix(worldSpace=True)
new_axes = []
trg_axes = [
pm.dt.Vector(trg_mtx[0][:3]).normal(),
@zhollosy
zhollosy / maya_componentTag_copy.py
Created October 11, 2024 15:25
copy component tags between two identical shape, here: from intermediate to final shape
"""
copy component tags between two identical shape
here: from intermediate to final shape
"""
import pymel.core as pm
obj = pm.selected()[0]
shp = obj.getShape()
shp_intm = [shp for shp in obj.getShapes() if shp.isIntermediate()][0]
import pymel.core as pm
jnt = pm.selected()[0]
mtx = jnt.getMatrix(worldSpace=False)
rot = mtx.rotate.asEulerRotation()
rot.unit = 'degrees'
jnt.rotate.set([0,0,0])
jnt.jointOrient.set(rot)
@zhollosy
zhollosy / Qt_Settings_to_Reg.py
Last active June 24, 2023 17:34
Class for store settings in registry for most of the simple cases.
class ToolSettings:
"""
Usage:
tool_settings = ToolSettings()
tool_settings.output_dir_path = 'c:/out_dir/'
"""
OrganizationName = "MyOrganization"
ApplicationName = "MyApplication"
def __getattr__(self, name):
@zhollosy
zhollosy / ScreenCapture.py
Created May 5, 2023 20:34
Capture image on the first screen under the selected rectangular area
import tkinter as tk
from PIL import ImageGrab
import ctypes
class ScreenCapture:
def __init__(self):
self.start_point = None
self.end_point = None
self.current_rectangles = []
self.root = tk.Tk()
@zhollosy
zhollosy / maya__match_curves.py
Last active May 2, 2023 15:07
Matching low res curve to high res (Autodesk Maya, API2, scipy, numpy)
import maya.cmds as cmds
import maya.api.OpenMaya as om2
import numpy as np
from scipy.optimize import minimize
from scipy.spatial.distance import cdist
def get_curve_cvs(curve):
curve_fn = om2.MFnNurbsCurve(get_dag_path(curve))
cvs = curve_fn.cvPositions(om2.MSpace.kWorld)
return np.array([[cv.x, cv.y, cv.z] for cv in cvs])
@zhollosy
zhollosy / openMaya_getVertexAtUV.py
Last active November 29, 2024 10:21
Finds the nearest Vertex to the given UV
import maya.api.OpenMaya as om2
import pymel.core as pm
def getVertexAtUV(obj, u, v):
"""
:param obj: geometry to search
:param u: search U
:param v: search V
:return: vertex object
@zhollosy
zhollosy / maya_build_hierarchy.py
Last active January 9, 2020 12:36
Builds or extends Maya DAG hierarchy by groups, defined in a clear, readable form.
import pymel.core as pm
def build_hierarchy(hmap):
'''
hmap = 'root' \
' controllers_GRP' \
' leftHand_CTR_GRP' \
' rightHand_CTR_GRP' \
' setup_GRP' \
' rig_GRP' \
@zhollosy
zhollosy / maya_lattice_tweaker_01.py
Last active November 5, 2019 12:35
Select latticed geometry and run script. It creates controllers for lattice control points.
"""Select latticed geometry and run script"""
import pymel.core as pm
sel = pm.selected()[0]
lattice = sel.history(type='lattice')[0]
cps = lattice.controlPoints
n = pm.getAttr(cps, size=True)
main_grp = pm.group(empty=True, name='{}_tweak_GRP'.format(sel.name()))
for i in range(n):
t = cps[i].get()
@zhollosy
zhollosy / maya_bindPoser_01.py
Last active October 9, 2023 14:08
Restore bind pose on selected transform node if stored.
"""Restore bind pose on selected transform node if stored"""
import pymel.core as pm
for obj in pm.selected(dag=True):
if hasattr(obj, 'bindPose'):
bp = obj.bindPose.get()
if bp is not None:
obj.setMatrix(bp, worldSpace=True)