Skip to content

Instantly share code, notes, and snippets.

View lukpazera's full-sized avatar

Lukasz Pazera lukpazera

View GitHub Profile
@lukpazera
lukpazera / cmdTextValueHint.py
Created September 7, 2018 11:21
This command shows how to set up text hints for an integer command argument in python. Courtesy of James O'Hare.
#python
import lx
import lxu.command
my_hint = ( (0, 'zero' ),
(1, 'one' ),
(-1, 'minusone' ),)
class TextValueHint_Cmd(lxu.command.BasicCommand):
@lukpazera
lukpazera / printChannelPackages.py
Created August 29, 2018 09:39
Script that prints out channel package for each channel of the first selected item.
import modo
item = modo.Scene().selected[0]
chanCount = item.internalItem.ChannelCount()
chanList = []
for i in xrange(chanCount - 1, -1, -1):
try:
package = item.internalItem.ChannelPackage(i)
except LookupError:
lx.out(item.internalItem.ChannelName(i))
@lukpazera
lukpazera / item_add_name_prefix.py
Last active June 9, 2018 15:58
Very simple script that renames selected items by adding a string prefix to each item's current name.
# python
""" Short snippet demonstrating how you can edit scene item's name using MODO 701 Python API.
"""
import lx
import lxu.select
PREFIX = 'prefix_'
@lukpazera
lukpazera / wxfrmInvert.cpp
Last active February 15, 2016 13:42
Two ways to get item's inverted world transform matrix.
/*
* This snippet demonstrates two of the ways to obtain item's inverted world transform matrix.
*/
// --- METHOD 1
CLxUser_Scene scene;
item.Context (scene);
CLxUser_ChannelRead chanRead;
CLxUser_SelectionService selSvc;
@lukpazera
lukpazera / cmdMatchXfrm.py
Created July 2, 2013 11:11
This is python translation of Matt Cox's matchXfrm.cpp C++ command and was done as an exercise while learning MODO python API. Matt's original: https://gist.github.com/mattcox/4742206
#python
""" Match Item Transforms.
Command matches transforms of one item to another.
Select 2 or more items and all items will be matched to last selected one.
I'm not author of this command.
This is python translation of Matt Cox's matchXfrm.cpp C++ equivalent
and was done as an exercise while learning MODO python API.
@lukpazera
lukpazera / cmdItemArg.py
Last active January 28, 2016 14:48
One way to pass item argument to command. Doing the same by using lx.eval and passing item ident is much easier though.
import modo
item = modo.Scene().selected[0]
cmdSvc = lx.service.Command()
cmd = cmdSvc.Spawn(lx.symbol.iCTAG_NULL, 'texture.reference')
attr = lx.object.Attributes(cmd)
val = attr.Value(attr.Lookup("item"), True)
valRef = lx.object.ValueReference(val)
valRef.SetObject(item)
cmd.Execute(lx.symbol.fCMD_EXEC_DEFAULT)
@lukpazera
lukpazera / cmdItemAimAt.py
Last active December 19, 2015 17:49
Implements a simple command that replicates what Direction Constraint does. It allows to aim one item at another using third item as an up vector.
#python
""" Aim Item Command.
Command sets one item (source item) rotation so that it
points at another item (target item) with an upvector defined
by third item (up vector item).
Command essentially replicates what Direction Constraint does.
Only it just applies rotation to the source item only at a current frame and action.
@lukpazera
lukpazera / customItemDraw.py
Last active December 19, 2015 02:49
This sample implements custom item that draws a circle in viewport. Circle's size and axis can be defined using item's custom channels. You can edit these custom channels in channel list (they won't show up in properties).
# python
""" Custom item drawing a shape.
----------------------------
Implements a custom item that draws a simple shape in viewport.
The item is of Locator supertype.
"""
import lx
import lxifc
@lukpazera
lukpazera / lp_cmdListTags.py
Created May 21, 2013 13:59
Implements a simple item.listTags command that lists all string tags attached to the selected item.
#python
"""
List all Item's Tags
--------------------
Simple command that lists all tags attached to the selected item.
The output goes to Event Log.
"""
import lx
@lukpazera
lukpazera / lp_cmdListXfrm.py
Created May 21, 2013 13:10
Plugin implements item.listXfrm command that lists all selected item's transform items in Event Log.
#python
'''
List Item Transforms
--------------------
Plugin implements item.listXfrm command that lists
all selected item's transforms in Event Log
'''