Skip to content

Instantly share code, notes, and snippets.

View tpoveda's full-sized avatar
🏠
Working from home

Tomás Poveda tpoveda

🏠
Working from home
View GitHub Profile
@tpoveda
tpoveda / close_disable_maya_node_editors.py
Last active June 11, 2021 18:45
Functions to close/disable Maya Node Editors
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
This gist contains:
- Function to close all currently opened Node Editors
- Python context that allows to disable new nodes addition to Node Editor while a function is being executed
"""
import contextlib
@tpoveda
tpoveda / mobu_startup_qt_defer.py
Created May 6, 2021 12:57
MotionBuilder Python startup "Deferred" Qt script
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
"Hacky" example that shows how to use OnUIIdle callback to defer a function call until MotionBuilder UI is properly
"""
from __future__ import print_function, division, absolute_import
try:
@tpoveda
tpoveda / mobu_year_version.py
Created April 2, 2021 21:53
MotionBuilder - Returns version as year
import math
import pyfbsdk
def get_mobu_version_as_year():
"""
Returns current MotionBuilder instance version as year
:return: MotionBuilder year version (2019, 2020, 2022 ...)
:rtype: str
@tpoveda
tpoveda / mobu_qt_menu.py
Created March 26, 2021 01:51
MotionBuilder - Custom Menu
# Creates a new QMenu and attaches to main MotionBuilder menu bar
try:
from PySide2.QtWidgets import QApplication, QMenuBar, QMenu, QAction
except ImportError:
from PySide.QtGui import QApplication, QMenuBar, QMenu, QAction
def get_main_qt_window():
parent = QApplication.activeWindow()
grand_parent = parent
@tpoveda
tpoveda / pymxs_forceNewFile.py
Last active January 21, 2021 02:30
PyMxs - Forces the creation of a new 3ds Max scene without prompting any UI
def force_new_scene():
"""
Forces the creation of a new 3ds Max scene without prompting any UI
"""
mxs_function = """fn mf = (
local windowHandle = DialogMonitorOPS.GetWindowHandle()
if (windowHandle != 0) then (
UIAccessor.PressButtonByName windowHandle "Do&n't Save"
)
# Python version of findRelatedSkinCluster.mel
# Based in findRelatedSkinCluster.mel MEL script file found in Maya 2020
import maya.cmds
def find_related_skin_cluster(skin_obj):
skin_shape = None
skin_shape_with_path = None
hidden_shape = None
@tpoveda
tpoveda / MaxPlusFindSkinInfluences.py
Created June 19, 2018 09:04
Returns all skin influences of the given Skin Modifier
import MaxPlus
def find_skin_influences(skin_modifier):
"""
Return influence nodes of a given skin modifier
:param skin_modifier: MaxPlus.Modifier (Skin)
:return: generator<INode>
"""
for ref in skin_modifier.Refs:
@tpoveda
tpoveda / MaxPlusAllSceneNodes.py
Last active June 19, 2018 09:05
MaxPlus - Get all scene nodes
import MaxPlus
def get_scene_nodes():
"""
Return all nodes in current scene
:return: generator<INode>
"""
stack = [MaxPlus.Core.GetRootNode()]
while stack:
@tpoveda
tpoveda / MaxPlusModDeps.py
Last active June 19, 2018 08:59
MaxPlus - Get modifier dependant nodes
import MaxPlus
def get_scene_nodes():
"""
Return all nodes in current scene
:return: generator<INode>
"""
stack = [MaxPlus.Core.GetRootNode()]
while stack:
@tpoveda
tpoveda / PySideScrollbarHandleSize.py
Last active June 19, 2018 09:00
Get handle size of QScrollBar
opt = QStyleOptionSlider()
self.view.horizontalScrollBar().initStyleOption(opt)
style = self.view.horizontalScrollBar().style()
handle = style.subControlRect(style.CC_ScrollBar, opt, style.SC_ScrollBarSlider)
sliderPos = handle.center()