Skip to content

Instantly share code, notes, and snippets.

View rondreas's full-sized avatar

Andreas Rånman rondreas

View GitHub Profile
@rondreas
rondreas / eSelection.py
Created November 20, 2018 16:03
snippet for blog post on toggleComponent
class eSelection(object):
""" Enum for selection convertion. """
object = 0
face = 1
edge = 2
vert = 3
def getActive():
""" Check current selection to find if we're currently only selecting a specific component. """
if all(isinstance(x, pm.MeshFace) for x in pm.selected()):
return eSelection.face
if all(isinstance(x, pm.MeshEdge) for x in pm.selected()):
return eSelection.edge
if all(isinstance(x, pm.MeshVertex) for x in pm.selected()):
# Replace selection with transform, for all selected vertices.
pm.select( [shape.getTransform() for shape in pm.ls(pm.polyListComponentConversion( fromVertex = True ))], replace = True )
@rondreas
rondreas / countScriptCtx.py
Created December 7, 2018 11:55
Count the number of scriptCtx in scene, checking only default named ones.
"""
Count the number of scriptCtx in scene, checking only default named ones.
"""
import pymel.core as pm
def countScriptCtx():
count = 0
mel_command = 'scriptCtx -ex "scriptCtx{}"'
@rondreas
rondreas / SelectionService.py
Created June 4, 2019 09:29
Quick reminder of how to deal with some quirks of Modo
# python
"""
Snippets for dealing with Modo's Selection Service
"""
__author__ = "AndreasR"
@rondreas
rondreas / PurgeTags.py
Created June 10, 2019 14:04
Purge tags for selected items
#python
"""
Remove all tags for selected items.
In Modo run:
> @PurgeTags.py
"""
@rondreas
rondreas / p4_multithreadded.py
Created October 17, 2019 08:49
Test to see that that official p4 api can be executed multithreadded
"""
Test to see that the official p4 api can be executed multithreadded
"""
# Get time so we can cause a delay, and uniform to set it to a random float,
from time import sleep
from random import uniform
@rondreas
rondreas / get_visible_meshes.py
Created October 28, 2019 12:36
Modo function for getting all visible meshes in current scene
import modo
# Anonymous function to wrap the lx query
is_visible = lambda item: bool(lx.eval('layer.setVisibility {} ?'.format(item.id)))
def get_visible_meshes():
meshes = modo.Scene().items(itype='mesh') # Get all mesh items in scene
return [mesh for mesh in meshes if is_visible(mesh)]
@rondreas
rondreas / list_kit_scripts.py
Last active November 6, 2019 14:08
Modo script to print all fire and forget scripts for the given kit to log.
# python
"""
Modo script to print all fire and forget scripts for the given kit to log.
Example::
@list_kit_scripts.py my_kit
@rondreas
rondreas / texel_density.py
Last active February 22, 2023 06:54
Functions for getting and setting texel density in Maya
"""
Functions for editing the texel density
https://80.lv/articles/textel-density-tutorial/
"""
import math
import maya.cmds as mc