Skip to content

Instantly share code, notes, and snippets.

@lukpazera
Last active February 17, 2023 13:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukpazera/5885271 to your computer and use it in GitHub Desktop.
Save lukpazera/5885271 to your computer and use it in GitHub Desktop.
A simple script for MODO that reads current channel selection from scene and outputs it to Event Log.
# python
""" Get Channel Selection.
There is no utility class for handling channel selection
like there is for items and scenes so it has to be done manually.
"""
import lx
selection_service = lx.service.Selection()
chan_sel_type = selection_service.LookupType(lx.symbol.sSELTYP_CHANNEL)
# Channel selection is stored in packets, like all other selections.
# Every packet contains information about one channel.
# To read channel selection we have to use ChannelPacketTranslation object
# that will decode selection packet and then we will be able to pull
# channel information from it.
# The line below initializes ChannelPacketTranslation object that is used to
# extract selection information from selection packet.
chan_transpacket = lx.object.ChannelPacketTranslation(selection_service.Allocate(lx.symbol.sSELTYP_CHANNEL))
# To see how many elements of a given type are selected in scene
# we use selection service's Count method.
# We pass integer selection type code to the method,
# in our case it's channel selection type code.
chan_n = selection_service.Count(chan_sel_type)
# Now we're going to loop through all channel packets and read them by index.
# To do that we're using selection service's ByIndex method passing it
# channel selection code and an index of a packet we want to get.
# The method returns a pointer to the packet. We're going to pass this pointer
# to translaction packet to extract single channel selection.
for x in xrange(chan_n):
packet_pointer = selection_service.ByIndex(chan_sel_type, x)
if not packet_pointer:
lx.out('Bad selection packet, skipping...')
continue
# Channel selection is 2 elements:
# item object the channel belongs to and a channel index.
# To pull this information out from packet we use Item and Index methods
# from ChannelPacketTranslation interface (that we already initialized) and
# we pass packet pointer to these methods.
item = lx.object.Item(chan_transpacket.Item(packet_pointer))
chan_idx = chan_transpacket.Index(packet_pointer)
# Show selection info in Event Log
lx.out('%s : %s' % (item.UniqueName(), item.ChannelName(chan_idx)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment