Channel Modifier Python Wrapper

The Python SDK in MODO 10 supports creating channel modifiers. The module is ‘’lxu.chanmod’’.

Wrapper

Here is an example channel modifier that takes one input float and outputs twice that value. The core of the code is a sub-class of lxu.chanmod.Operator which declares the channels for the modifier in initialize() and performs the computation in ‘’’eval()’’’. The wrapper code binds the channels to the Value attributes on the chans object – with the same name as the channels – which can be read and written during evaluation. The support code needed for exporting this as a server is provided by the lxu.chanmod.MetaPackage class and the lxu.chanmod.bless_server() method, which takes the client’s package class and the name of the server.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
import lx
import lxu.chanmod

class TheDoubler(lxu.chanmod.Operator):
    def initialize(self, desc):
        desc.add ("input", lx.symbol.sTYPE_FLOAT)
        desc.chmod_value (lx.symbol.fCHMOD_INPUT)

        desc.add ("output", lx.symbol.sTYPE_FLOAT)
        desc.chmod_value (lx.symbol.fCHMOD_OUTPUT)

    def eval(self, chans):
        inVal = chans.input.GetFlt()
        chans.output.SetFlt(inVal * 2)

class TheDoublerPackage(lxu.chanmod.MetaPackage):
    def operator(self):
        return TheDoubler()

lxu.chanmod.bless_server(TheDoublerPackage, "cmDoubler")

Other Bindings

In addition to Value objects, input channels can also be bound to ValueArray objects, allowing multi-link channels to be read individually.

1
2
3
4
5
6
        desc.add ("input", lx.symbol.sTYPE_FLOAT)
        desc.chmod_array (lx.symbol.fCHMOD_INPUT | lx.symbol.fCHMOD_MULTILINK)
        [...]
        sum = 0
        for v in chans.multi:
            sum += v

Channels can also be bound to Matrix objects, and writing to a Matrix output now automatically propagates to all outputs so only a single result needs to be generated.

1
2
3
4
        desc.add ("outMat", lx.symbol.sTYPE_MATRIX4)
        desc.chmod_matrix (lx.symbol.fCHMOD_OUTPUT)
        [...]
        chans.outMat.Set4 (resultMatrix)

Channel modifiers can also read from time. There’s no channel needed for this, just a float to get the result.

1
2
3
        desc.chmod_time ()
        [...]
        t = chans._time