Color Channel with an initial color

From The Foundry MODO SDK wiki
Jump to: navigation, search


Modo GUI Controls

In Modo many GUI controls are channels shown in forms with the command.

One of them are the color channels. Like the ones shown on a Locator when it's Draw Options are active.

Color Channels.jpg

In many situations you want to create this channel and gave it an initial color by default. If you don't do it, the channel will be created with a black color [0.0, 0.0, 0.0]


This snippet shows how to create a color channel and set up it's default color inside of the pkg_SetupChannels function of a Package class:

def pkg_SetupChannels(self, addChan):
            The SetupChannels function is called the first time an instance of this
            package is to be created, allowing the package to define the set of channels
            that it wants. Channels are given by name and type, and optional settings
            may be applied to each one.
            We are adding several channels to our item as an example.
        # Cast AddChannel
        addChannel = lx.object.AddChannel(addChan)
        # Name of the channel
        CHAN_LCOLOR = 'LeftColor'
        # A green Fluorescent color
        #It will be the default initial color for the channel
        CHDEFVAL_LCOLOR = [0.7843, 0.9647, 0.0000]
        #Create the channel 
        addChannel.NewChannel(CHAN_LCOLOR, lx.symbol.sTYPE_COLOR1)
        # Use lx.symbol.sCHANVEC_RGBA to get an Alpha Value
        # Create a storage object
        defaultValue =
        # Set it's type to double, this type is NOT defined on lx.symbol is missing
        # Set it's size to store 3 doubles
        # Set the values
        # Set the default vector to the storage object

This is the result of that snippet:

Color Channel Fluorescent Green.jpg

To show that channel on the interface you add a control inside of your Form that uses the command in Modo.

        <list type="Control" val="cmd {your_item_name_here$LeftColor} ?">
	    <atom type="Label">Left Color</atom>
	    <atom type="Tooltip">Color used for the markers at the left side of the Guide.</atom>
	    <atom type="Desc">Color used for the markers at the left side of the Guide.</atom>
	    <atom type="StartCollapsed">0</atom>
	    <atom type="Hash">57575632771:control</atom>

Note: This snippet will not work if you copy paste it on any of your forms.

Storage Objects

Storage objects are a way to pass certain data between Python and Modo.

If you introspect the __doc__ of some method of the api:


The docs will indicate that this method needs a storage object:

        SetDefaultVec(double[] defVec)

The [] symbol after the type (double) is indicating you need a storage object passed to this method.

The has the following methods:

        # Read out the contents of the buffer as a tuple, either the full length or the specified length 
        (tuple) =
        # Set or read the offset in the buffer 
        # Read
        offset =
        # Set
        # Assign a tuple to fill the buffer
        # Set the number of elements in the buffer
        # Set the element type for buffer: float, double, int, byte, unsigned, pointer 'float' | lx.symbol.sTYPE_FLOAT, 
                                   'double',                             # NOT defined in lx.symbol.sTYPE
                                   'interger' | lx.symbol.sTYPE_INTEGER,
                                   'byte',                               # NOT defined in lx.symbol.sTYPE
                                   'unsigned',                           # NOT defined in lx.symbol.sTYPE
                                   'pointer'                             # NOT defined in lx.symbol.sTYPE )
        # Return the size of the buffer
        size =
        # Read out the contents of the buffer as a string
        string =