Skip to content

Instantly share code, notes, and snippets.

@huadingjin
huadingjin / Simple_MayaDockingClass.py
Created October 3, 2023 13:03 — forked from liorbenhorin/Simple_MayaDockingClass.py
Simple way to Docking Qt widgets to Maya 2017+
'''
Template class for docking a Qt widget to maya 2017+.
Author: Lior ben horin
12-1-2017
'''
import weakref
import maya.cmds as cmds
import maya.OpenMayaUI as omui
@huadingjin
huadingjin / MayaDockingClass.py
Created October 3, 2023 13:01 — forked from liorbenhorin/MayaDockingClass.py
Maya 2017 PySide2 Docking Qt QMainWindow
"""
This is what you need to do in order to get a qt window to dock next to maya channel box,
In all maya versions, including 2017 with PySide2
"""
__author__ = "liorbenhorin@gmail.com"
import sys
import os
import logging
import xml.etree.ElementTree as xml
@huadingjin
huadingjin / Bake transformation to Offset Parent Matrix
Created January 6, 2022 10:00 — forked from Muream/bake_to_opm.py
This script bakes the transformation of a node to its offset parent matrix which then acts as its rest matrix. Only works with maya 2020 and up.
import maya.api.OpenMaya as om
import maya.cmds as cmds
TRANSFORM_NODETYPES = ["transform", "joint"]
def has_non_default_locked_attributes(node):
locked_attributes = []
for attribute in ["translate", "rotate", "scale", "jointOrient"]:
default_value = 1 if attribute == "scale" else 0
for axis in "XYZ":
#F. Hiba, C. Mendes, B. Lefebvre, P. Hubert
import maya.api.OpenMaya as om
import maya.cmds as cmds
from math import radians, degrees, sin, cos
from random import gauss, random, uniform, shuffle
from copy import copy
#4 utilities function related to transformations
#give the quaternion corresponding to the rottion from vector 1 to vector 2
@huadingjin
huadingjin / getCurveNormal.py
Created January 19, 2021 11:15 — forked from hdlx/getCurveNormal.py
Maya get curve normal
import maya.api.OpenMaya as om
import maya.cmds as cmds
#Returns normal, tangent, at a given point on a curve, given the curve and a position in space.
#result as a list of openmaya MVector()
def getCurveNormal(mayaCurve, pos=[0,0,0]):
selectionList = om.MSelectionList()
selectionList.add(mayaCurve)
dPath= selectionList.getDagPath(0)
mCurve=om.MFnNurbsCurve (dPath)
@huadingjin
huadingjin / getClosestVertex.py
Created January 19, 2021 11:15 — forked from hdlx/getClosestVertex.py
Maya get closest vertex
import maya.api.OpenMaya as om
import maya.cmds as cmds
#returns the closest vertex given a mesh and a position [x,y,z] in world space.
#Uses om.MfnMesh.getClosestPoint() returned face ID and iterates through face's vertices.
def getClosestVertex(mayaMesh,pos=[0,0,0]):
mVector = om.MVector(pos)#using MVector type to represent position
selectionList = om.MSelectionList()
selectionList.add(mayaMesh)
dPath= selectionList.getDagPath(0)