Skip to content

Instantly share code, notes, and snippets.

@lukpazera
lukpazera / setupChannels.py
Created August 21, 2019 11:44
This is how to read evaluated setup channels using MODO python SDK. The crucial bit is using scene.SetupChannels() in line 11. Stolen from Foundry's coding slack channel.
scene_svc = lx.service.Scene()
sel_svc = lx.service.Selection()
pkt_trans = lx.object.ItemPacketTranslation(sel_svc.Allocate(lx.symbol.sSELTYP_ITEM))
sel_type = sel_svc.LookupType(lx.symbol.sSELTYP_ITEM)
for i in xrange(sel_svc.Count(sel_type)):
pkt = sel_svc.ByIndex(sel_type, i)
item = pkt_trans.Item(pkt)
scene = item.Context()
@lukpazera
lukpazera / getPolyUnderMouse.py
Last active May 23, 2020 09:30
Gets mesh and and an index of a polygon that is under the mouse in MODO viewport.
# python
import lx
import modo
# This snippet queries polygon that is under a mouse.
# Querying polygon only works correctly on active meshes.
# That means that if mouse is over the mesh that is not active
# (was not selected prior to entering component mode),
@mattcox
mattcox / getReferenceScenesAndItems.py
Created July 24, 2018 11:57
Collect reference items in the selected scene.
import lxu.select
class ReferencedItems:
def __init__(self, scene):
self.mScene = lx.object.Scene(scene)
self.mSceneFilename = self.mScene.Filename()
self.mItems = []
def AddItem(self, item):
print item
@ivogrig
ivogrig / ImagePixel.py
Last active August 3, 2020 11:37
Loading an image clip and reading a pixel
import lxu
import lxu.select
def loadImage(filepath, width, height):
'''
Loads an image as clip and returns it's image interface object.
'''
if not os.path.exists(filepath):
raise AttributeError("Path does not exist")
@lukpazera
lukpazera / getChannelSelection.py
Last active February 17, 2023 13:15
A simple script for MODO that reads current channel selection from scene and outputs it to Event Log.
# python
""" Get Channel Selection.
There is no utility class for handling channel selection
like there is for items and scenes so it has to be done manually.
"""
import lx
selection_service = lx.service.Selection()
@mattcox
mattcox / shapeDraw.py
Last active April 16, 2020 08:08
Python example demonstrating how to modify GL drawing of an item.
#python
'''
Shape Draw python example. This python plugins demonstrates how to create
a Package that can be added to existing items, that controls how they draw
in the GL viewport. We will simply draw a circle. A radius channel and an
sides channel will control how the circle is drawn.
To use, add the python script to an lxserv folder in your scripts directory.
Select an locator item and enter: item.addPackage shape.draw. To remove the