Skip to content

Instantly share code, notes, and snippets.

View rondreas's full-sized avatar

Andreas Rånman rondreas

View GitHub Profile
@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 / 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 / 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 / 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 / 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{}"'
# Replace selection with transform, for all selected vertices.
pm.select( [shape.getTransform() for shape in pm.ls(pm.polyListComponentConversion( fromVertex = True ))], replace = True )
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()):
@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
@rondreas
rondreas / toggleComponents.py
Created November 19, 2018 16:44
Quick script to allow hotkeying a toggle for converting selection, to imitate the default command of CTRL + F9/F10/F11.
"""
Quick script to allow hotkeying a toggle for converting selection, to imitate the default
command of CTRL + F9/F10/F11.
"""
import pymel.core as pm
class eSelection(object):
@rondreas
rondreas / fixNormals.py
Last active November 19, 2018 15:33
hardsurface modelling script to set normals for all vertices on a face.
import pymel.core as pm
def faceNormal():
""" """
# Store old selection,
selection = pm.selected()
# Convert selection to faces,
pm.mel.ConvertSelectionToFaces()