Skip to content

Instantly share code, notes, and snippets.

@Farfarer
Farfarer / newClipCustomSize.py
Created August 25, 2017 11:21
Adds a new command for Modo, clip.newWithSize, which lets you specify explicit width/height of newly created images, rather than the usual square power-of-two.
#!/usr/bin/env python
import os
import lx
import modo
import lxifc
import lxu.select
import lxu.command
@Farfarer
Farfarer / renamePTag.py
Last active May 24, 2017 10:09
MODO plugin for renaming polygon tags.
#!/usr/bin/env python
import lx
import lxu
import lxifc
import lxu.command
class MeshPicker (lxu.command.BasicHints):
def __init__ (self):
scn_svc = lx.service.Scene ()
@Farfarer
Farfarer / listGraphConnections.py
Created May 8, 2017 16:23
A MODO script to lists all connections on all graphs for the selected items and their channels.
#!/usr/bin/env python
import lx
import lxu.select
cui_svc = lx.service.ChannelUI ()
graphNames = []
scene = lxu.select.SceneSelection().current()
for x in range(scene.GraphCount()):
@Farfarer
Farfarer / symbolUtils.py
Created April 24, 2017 11:18
Little MODO utility script for looking up symbol defines by value.
#python
import lx
import lx.symbol as symbols
# Save this into your MODO scripts directory.
# Example usage:
# Find symbols with value of enable
# import symbolUtils as su
@Farfarer
Farfarer / selectItemCenter.py
Last active March 1, 2017 10:59
Snippet for selecting item centers using the pyAPI in MODO.
def selectItemCenter (item, dropSelection=True):
sel_svc = lxu.service.Selection()
# Find the internal code for "center" selection type.
sel_type_center = sel_svc.LookupType (lx.symbol.sSELTYP_CENTER)
# Set up a selection packet translator for "center" selections.
# This lets us bundle up centers into selection "packets" for passing on to the selection service.
# Or read information about existing selection "packets" that we get from the selection service.
center_pkt_trans = lx.object.CenterPacketTranslation (sel_svc.Allocate (lx.symbol.sSELTYP_CENTER))
@Farfarer
Farfarer / removeSchematicNodesPYAPI.py
Created February 28, 2017 16:32
Ways to remove ALL schematic nodes via the pyAPI and TD SDK in MODO.
#pyAPI version
scene_svc = lx.service.Scene ()
scene = lxu.select.SceneSelection().current()
graph = lx.object.ItemGraph (scene.GraphLookup ('schmItem'))
itemsToRemove = set()
for t in xrange(scene_svc.ItemTypeCount()):
type = scene_svc.ItemTypeByIndex(t)
@Farfarer
Farfarer / averageRGBA.py
Created February 6, 2017 17:38
Average the selected RGBA vertex maps across each selected polygon.
#!/usr/bin/env python
import lx
import lxifc
import lxu.command
class ListMaps (lxifc.Visitor):
def __init__ (self, meshmap):
self.meshmap = meshmap
self.mapIDs = []
@Farfarer
Farfarer / polysByIsland.py
Created December 13, 2016 15:03
MODO pyAPI - Get the polygon IDs of each "island" of polygons in the active layers.
#!/usr/bin/env python
import lx
import lxu.command
import lxifc
class SetMarks (lxifc.Visitor):
def __init__ (self, acc, mark):
self.acc = acc
self.mark = mark
@Farfarer
Farfarer / expandByMaterial.py
Created November 16, 2016 17:50
Expands current polygon selection by material ID.
# Run with `ffr.expandByMat`, it will expand the current polygon selection by the material ID of the current polygon selection.
#
# An optional argument, `materialID` will expand only by a given material ID, e.g.
# `ffr.expandByMat "Default"`
#!/usr/bin/env python
import lx
import lxu.command
import lxifc
@Farfarer
Farfarer / clampRGBA.py
Created October 13, 2016 14:31
Clamps RGBA vertex map values to the 0-1 range. Stick this into a folder called "lxserv" in your user scripts directory. Restart MODO. Use "ffr.clampRGBA" to run the command.
#!/usr/bin/env python
import lx
import lxifc
import lxu.command
def vclamp (a):
b = list(a)
beenClamped = False
for x in xrange(4):