Skip to content

Instantly share code, notes, and snippets.

View lukpazera's full-sized avatar

Lukasz Pazera lukpazera

View GitHub Profile
@lukpazera
lukpazera / onIdleEvent.cpp
Last active June 20, 2019 11:17
How to set up on idle event in MODO SDK.
#include "lx_visitor.hpp"
/*
* OnIdleVisitor is used to perform On Idle Event.
* Evaluate() method will be called once the on idle event is registered.
*
* If you add more methods to this class and want to access them from outside this is how you need to do it:
* onIdleVisitorInstance.loc.method();
* You get direct access to this class contents via '.loc'.
* Don't ask me why ;).
@lukpazera
lukpazera / undoGroup.CFG
Last active June 18, 2019 15:41
This is piece of MODO config allows for defining a command (my.command) as part of undo group (myUndoGroup). 'undoPlusPrevious' means that when undoing my.command it will do one more undo step automatically. It allows for bundling multiple commands into one undo step.
http://modo.sdk.thefoundry.co.uk/wiki/Command_(lx-command.hpp)#.2814.29_SDK:_Undo_Group_Command_Example
<atom type="CommandUndoGroup">
<hash type="Command" key="my.command">myUndoGroup</hash>
<hash type="GroupBehavior" key="myUndoGroup">undoPlusPrevious</hash>
</atom>
@lukpazera
lukpazera / alignToView.py
Created June 17, 2019 08:31
This snippet can be used to align vector in world space to a current view. This could be used for something like Align To View in MODO locator shape properties. We could potentially draw a shape that is always facing view.
import lx
import lxu
import modo
scene = modo.Scene()
i = scene.item('Locator')
# Get current MODO viewport interface
vs = lx.service.View3Dport()
currentViewIndex = vs.Current()
@lukpazera
lukpazera / toolInput.cpp
Created June 10, 2019 08:34
A method to track input for tool events, thought it might be useful to others.
void input_testing(ILxUnknownID vts)
{
// setup
CLxUser_VectorStack vec(vts);
LXpToolInputEvent *input_event;
input_event = (LXpToolInputEvent *)vec.Read(offset_input);
// Tool Input Count(could be used to track number of clicks etc)
int count = input_event->count;
@lukpazera
lukpazera / meshListen.py
Created June 10, 2019 08:32
Mesh listener setup snippet from Tom Dymond, posted on Foundry coding slack channel.
import modo, lxifc
geo = modo.MeshGeometry("Cube").internalMesh
port = lx.object.ListenerPort(geo)
class mesh_listener(lxifc.MeshListener):
undoService = lx.service.Undo()
def __init__(self):
self.listenerService = lx.service.Listener()
self.COM_object = lx.object.Unknown(port)
@lukpazera
lukpazera / mergeTransforms.py
Last active April 10, 2019 09:35
Using python TDSDK to merge two rotation transform items in MODO. The assumption is that the 2nd item is zero rotation one so effectively this removes zeroed rotation from an item.
import modo
scene = modo.Scene()
i = scene.selected[0]
l = modo.LocatorSuperType(i)
rot = l.rotation
transformsStack = [xfrm for xfrm in l.transforms]
@lukpazera
lukpazera / constraintRotOffset.py
Created April 3, 2019 10:24
This gist will calculate rotation offset angle values for a rotation constraint between two items in MODO.
""" This gist will calculate rotation offset angle values for a rotation constraint
between two items in MODO. It'll be exactly the same as setting up the constraint
with compensation turned on.
This code can be useed to update existing rotation constraint setup with new offset
without reapplying the constraint again.
The process is simple.
- get the world rotation matrix of the target and invert it.
- multiply source world rotation matrix by the inverted target matrix.
@lukpazera
lukpazera / ItemPackageFormFilter.CFG
Created December 12, 2018 11:31
This is an example of a MODO config file that sets up a properties form that is only visible for an item that contains a given package. One more snatch from James O'Hare.
<atom type="Filters">
<hash type="Preset" key="ffr_morphCage.package:filterPreset">
<atom type="Name">Morph Cage View</atom>
<atom type="Enable">1</atom>
<list type="Node">1 .group 0 &quot;&quot;</list>
<list type="Node">1 packagename ffr_morphCage</list>
<list type="Node">-1 .endgroup </list>
</hash>
</atom>
@lukpazera
lukpazera / ArgumentNotifier.py
Created December 12, 2018 11:29
An example of setting up a notifier for command argument in MODO SDK. Snatched from post by James O'Hare on MODO slack coding channel.
class Notifier(lxifc.UIValueHints):
def __init__(self):
self._notifiers = [('channel.value', '+v channelName itemType'),]
def uiv_NotifierCount(self):
return len(self._notifiers)
def uiv_NotifierByIndex(self, index):
return self._notifiers[index]
@lukpazera
lukpazera / layoutWindowConfigExample.CFG
Created November 24, 2018 13:27
How to define layout in MODO config so it's available by key to the layout.window command. Snatched from Funk example on MODO slack channel.
<atom type="Frame">
<hash type="Layout" key="base.mbUVSingle_Layout" val="viewportGroup">
<atom type="IdealSize">1323 875</atom>
<list type="Port">UVmodel 0 1 0 1 TemplateUV_View</list>
<atom type="SwitcherClass">normal</atom>
<atom type="UserName">Mario UV</atom>
</hash>
<hash type="LayoutWindow" key="mbUvWindow">
<atom type="Title">Mario UV</atom>