Skip to content

Instantly share code, notes, and snippets.

@boredstiff
Created March 17, 2015 02:52
Show Gist options
  • Save boredstiff/ff1ce4bcd606a700ffc8 to your computer and use it in GitHub Desktop.
Save boredstiff/ff1ce4bcd606a700ffc8 to your computer and use it in GitHub Desktop.
meshSelListener.py
#python
import lx
import lxu.object
import lxu.command
import lxifc
class AwSelListener(lxifc.SelectionListener):
running = False
existing = None
def __init__(self):
if AwSelListener.existing is None:
self.listenerService = lx.service.Listener()
self.listenerService.AddListener(self)
AwSelListener.existing = self
self.mesh = ''
@staticmethod
def Stop():
AwSelListener.running = False
lx.out('My Selection Listener is now stopped')
@staticmethod
def Start():
AwSelListener.running = True
lx.out('My Selection Listener is now running')
def Status():
# Tells you whether it's running or not
return AwSelListener.running
def selevent_Add(self, type, subtType):
if AwSelListener.running:
scn_srv = lx.service.Scene()
typename = scn_srv.ItemTypeName(subtType)
if typename == 'mesh':
lx.out('I have selected a mesh')
# the rest of your code
# Various other methods
def selevent_Current(self, type):
pass
def selevent_Remove(self, type, subtType):
pass
def selevent_Time(self, time):
pass
def selevent_TimeRange(self, type):
pass
# Turns your listener on or off - you would pass the command toggle.selListener(below)
# to something to turn the event on or off. For example, in a kit that I built, I turned
# it on whenever Modo started up, and when I dropped in presets, I made sure to turn
# if off, because it would interfere(how I built it would). It all depends what you're
# needing out of it.
class AwToggleSelectionListener(lxu.command.BasicCommand):
def basic_Execute(self, msg, flags):
if AwSelListener.Status() is True:
AwSelListener.Stop()
else:
AwSelListener.Start()
lx.bless(AwToggleSelectionListener, "toggle.selListener")
@boredstiff
Copy link
Author

Ignore the spacing, I don't know what the problem is right now. It won't copy correctly through my clipboard for some reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment