Skip to content

Instantly share code, notes, and snippets.

@ivogrig
ivogrig / cmdPrintWeights.py
Last active August 29, 2015 14:22
Modo Python API example for skin weight access
# Python API example for skin weight access
# Place this file into an lxserv folder
#
# Creates a command that takes the names of a mesh and a connected joint locator and inverts the weight values
#
# Example command usage:
# example.printJointWeights locator:"Skeleton_Joint (4)" mesh:MyCube
import lx
import lxu
@ivogrig
ivogrig / CmdSetMeshInstance.py
Created June 10, 2015 14:08
Sets a new source mesh to a mesh instance, by manipulating the 'meshInst' and 'source' graphs.
################################################################################
#
# SetMeshInstance.py
#
# Version: 0.1
#
# Author: Ivo Grigull
#
# Last Update: 10/06/2015
#
@ivogrig
ivogrig / Monitor example
Created June 23, 2015 09:26
Modo Monitor example
import time
import lx
dialog_svc = lx.service.StdDialog()
# Allocate monitor
mon = lx.object.Monitor(dialog_svc.MonitorAllocate('Calculating Center Of Mass ...'))
steps = 50
@ivogrig
ivogrig / SelectionSet.py
Created July 6, 2015 10:03
Modo Selection set
# There is no dedicated methods for the selection sets in the TD SDK as of yet.
# Currently you can only create pickMaps for vertices using the vmaps methods.
import modo
# Create a sphere
lx.eval('script.implicit "Unit Sphere Item"')
mesh = modo.Mesh('Sphere')
@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")
@ivogrig
ivogrig / CreateMeshPoints.py
Created July 15, 2015 10:14
Example of creating a mesh and adding a vertex using Modo's Python API
# Example of creating a mesh and adding a vertex using Modo's Python API
import lxu
# Get current scene
scene = lxu.select.SceneSelection().current()
# Create new mesh item
scene_service = lx.service.Scene()
mesh_type = scene_service.ItemTypeLookup(lx.symbol.sTYPE_MESH)
@ivogrig
ivogrig / meshMaterials.py
Created July 24, 2015 11:31
Example of finding materials connected to a mesh. This should become redundant as there will be convenience functions added to the TD SDK soon.
# Example of finding materials connected to a mesh. This should become redundant as
# there will be convenience functions added to the TD SDK soon.
import modo
# This gets the selected mesh if any
mesh = modo.Mesh()
if mesh:
@ivogrig
ivogrig / curveEndPoints.py
Created August 17, 2015 09:25
How to set curve endpoints with the TD SDK
import modo
# By not passing an item when initializing the Mesh object,
# it will use the selected if any
curve = modo.Mesh()
# Iterate the curve polygons and activate the endpoints
for polygon in curve.geometry.polygons.iterCurves():
polygon.accessor.SetFirstIsControlEndpoint(1)
polygon.accessor.SetLastIsControlEndpoint(1)
@ivogrig
ivogrig / CmdSetrCurveEndPoints.py
Created August 17, 2015 13:31
This command sets or gets the 'Start Control' or 'End Control' state of a curve (not a bezier curve).
'''
This command sets or gets the 'Start Control' or 'End Control' state of a curve (not a bezier curve).
# Example for querying the Start Control state for every curve polygon found in the selected mesh:
import modo
mesh = modo.Mesh()
for curvePolygonIndex in [i.index for i in mesh.geometry.polygons.iterCurves()]:
startControl = lx.eval('curve.endPoints polyIndex:{0} first:?'.format( curvePolygonIndex ))
lx.out(startControl)
@ivogrig
ivogrig / aimRotation.py
Last active March 27, 2022 04:15
Example method for turning a direction vector into an euler rotation (TD SDK)
# python
#
# Example method for turning a direction vector into an euler rotation
#
# There is a similar example using the API for this by Lukasz Pazera: https://gist.github.com/lukpazera/5994547
# This function really does the same, using the mathutils of the TD SDK
import modo
import math