Skip to content

Instantly share code, notes, and snippets.

@mattcox
Last active June 22, 2017 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattcox/9a649d11de15e619c8a5 to your computer and use it in GitHub Desktop.
Save mattcox/9a649d11de15e619c8a5 to your computer and use it in GitHub Desktop.
This python plugin example defines a new package that can be added to an existing item, adding a string channel called "customData".
#python
'''
This plugin example adds a new package that can be added to
an existing item, adding a float channel called "customData".
Essentially, it's just implementing a custom item. But by not
specifying a supertype, it becomes a generic item that can be
added to an existing item to extend their functionality.
'''
import lx
import lxifc
PACKAGE_NAME = 'customData'
CHAN_CUSTOMDATA = 'customData'
class Instance (lxifc.PackageInstance):
pass
class Package (lxifc.Package):
def pkg_SetupChannels (self, addChan):
'''
The SetupChannels function is where we add any extra channels to our
custom item. We are going to be add a single channel called customData.
'''
addChan = lx.object.AddChannel (addChan)
addChan.NewChannel (CHAN_CUSTOMDATA, lx.symbol.sTYPE_STRING)
addChan.SetStorage (lx.symbol.sTYPE_STRING)
def pkg_Attach (self):
'''
The Attach function is called to create a new Instance of our item
in the scene. We simply return an instance of our Instance class.
'''
return Instance ()
def pkg_TestInterface (self, guid):
'''
The TestInterface function is called for every potential interface
that the Instance could inherit from. We need to return true when
queried for any interface that it does inherit from. We do this
by comparing the GUID that is being passed as an argument against
the GUID of the interfaces that we know our Instance inherits from.
'''
return (lx.service.GUID ().Compare( guid, lx.symbol.u_PACKAGEINSTANCE) == 0)
'''
Finally, bless the item package so that it is registered as a plugin inside
of modo. As this is a package that is added to another item and not a full
item in itself, we won't define a supertype.
'''
lx.bless (Package, PACKAGE_NAME)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment