Skip to content

Instantly share code, notes, and snippets.

@mattcox
mattcox / previewSocketExample.py
Created August 13, 2018 13:43
This sample script demonstrates the basics for connecting to the preview socket, setting the resolution, and the pixel format, and reading back a floating point buffer of the image.
'''
This sample script demonstrates the basics for connecting to the preview
socket, setting the resolution, and the pixel format, and reading back a
floating point buffer of the image.
To test it, launch modo, and execute the command:
telnet.listen port:5678 raw:true
Then run the following in an external Python client.
'''
@mattcox
mattcox / printMeshTags.py
Last active October 4, 2018 14:56
This sample code demonstrates how to enumerate over all polygons on the active mesh layer, and print the material tag assigned to each polygon to the event log.
#python
'''
This sample code demonstrates how to enumerate over all polygons on the active
mesh layer, and print the material tag assigned to each polygon to the event
log.
'''
import lx
import lxu.command
@mattcox
mattcox / kitDumpCommand.py
Created February 14, 2019 16:39
Demonstrates how to list the kits installed in Modo, and query the version numbers. This mostly is a wrapper for the kit.version command.
#python
'''
Demonstrates how to list the kits installed in Modo, and query the version
numbers. This mostly is a wrapper for the kit.version command.
'''
import lx
@mattcox
mattcox / SetCOM.cpp
Created February 15, 2019 15:27
Demonstrates how to implement a custom Polymorph object that implements the SetCOM method. When the COM object is allocated, the SetCOM method will be passed a copy of the object, which can be useful if the allocated object needs passing to additional methods from within the COM implementation. Note: As the COM object is maintaining a pointer to…
class SomeInterface :
public CLxImpl_Foo
{
public:
class MyPolymorph :
public CLxPolymorph<SomeInterface>
{
public:
virtual void
SetCOM(
@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
@mattcox
mattcox / meshDumpCurvesCommand.py
Created November 7, 2019 10:33
Demonstrates how to print vertex information for the points on an ILxCurve.
#python
import lx
import lxifc
import lxu.command
import modo
class Command(lxu.command.BasicCommand):
def __init__(self):
lxu.command.BasicCommand.__init__(self)
@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
import Cocoa
import Foundation
let pathToImage = "/some/path/to/an/image.png"
let pathToFolders = URL(fileURLWithPath: "/Some/Folder/Path/")
guard let image = NSImage(contentsOfFile: pathToImage) else {
fatalError("Unable to load image.")
}
@mattcox
mattcox / pmodel_selectOdd.cpp
Last active August 26, 2021 14:27
Example of a simple selection operation for the Modo procedural modelling system that selects every other polygon. It demonstrates how to use thread slots, to allow selection to be evaluated from multiple threads
#include <lxsdk/lx_mesh.hpp>
#include <lxsdk/lx_pmodel.hpp>
#include <lxsdk/lx_seltypes.hpp>
#include <lxsdk/lx_thread.hpp>
#include <lxsdk/lxu_attributes.hpp>
#define SERVER_NAME "pmodel.selectEveryOther"
/*
* The Selection Operation is evaluated in parallel from multiple threads. As
@mattcox
mattcox / material_new.py
Last active November 9, 2021 08:19
Auto generates material masks for every new, unique material ptag in the scene.
#!/usr/bin/env python
'''
Auto generates material masks for every material ptag in the scene.
Usage: Put the script in a folder called lxserv inside your modo scripts
folder. Restart modo. Run the command: material.generate
'''
import lx