PDA

View Full Version : ListChannels.py Script



GregMalick
03-01-2012, 10:06 PM
Here's something I whipped together that might help others struggling to fathom LW Python scripting.


#! /usr/bin/env python
# -*- Mode: Python -*-
# -*- coding: ascii -*-

import lwsdk

__author__ = "Greg Malick"
__date__ = "Jan 24 2012"
__copyright__ = "Copyright (C) 2012 Greg Malick."
__version__ = "0.1"
__maintainer__ = "Greg Malick"
__email__ = "[email protected]"
__status__ = "beta"
__lwver__ = "11"

class listChannels(lwsdk.IGeneric):
def __init__(self, context):
super(listChannels, self).__init__()

def findEnv(self, itemType):
id = lwsdk.LWItemInfo().first( itemType, None )
groupID = lwsdk.LWItemInfo().chanGroup( id )
chan = lwsdk.LWChannelInfo().nextChannel(groupID, None)
while chan:
channelName = lwsdk.LWChannelInfo().channelName(chan)
print("channelName:" + channelName)
chan = lwsdk.LWChannelInfo().nextChannel(groupID, chan)

def process(self, ga):
# Get all the selected Objects
item_info = lwsdk.LWItemInfo()
selected = lwsdk.LWInterfaceInfo().selected_items()
for itemID in selected:
print(" item:" + item_info.name(itemID))
self.findEnv(item_info.type(itemID))
print(" ")

return lwsdk.AFUNC_OK


ServerTagInfo = [
( "listChannels", lwsdk.SRVTAG_USERNAME | lwsdk.LANGID_USENGLISH ),
( "listChannels", lwsdk.SRVTAG_BUTTONNAME | lwsdk.LANGID_USENGLISH ),
( "Utilities/Python", lwsdk.SRVTAG_MENU | lwsdk.LANGID_USENGLISH )
]

ServerRecord = { lwsdk.GenericFactory("listChannels", listChannels) : ServerTagInfo }

Gorbag
03-02-2012, 12:31 PM
Just an FYI: You should probably use the "code" formatting when posting Python scripts, especially considering that Python is sensitive to indenting. Using "quote" drops the formatting, and your code won't run properly as presented.

GregMalick
03-03-2012, 12:55 AM
Oops - that's what I get for posting at 7am


#! /usr/bin/env python
# -*- Mode: Python -*-
# -*- coding: ascii -*-

import lwsdk

__author__ = "Greg Malick"
__date__ = "Jan 24 2012"
__copyright__ = "Copyright (C) 2012 Greg Malick."
__version__ = "0.1"
__maintainer__ = "Greg Malick"
__email__ = "[email protected]"
__status__ = "beta"
__lwver__ = "11"

class listChannels(lwsdk.IGeneric):
def __init__(self, context):
super(listChannels, self).__init__()

def findEnv(self, itemType):
id = lwsdk.LWItemInfo().first( itemType, None )
groupID = lwsdk.LWItemInfo().chanGroup( id )
chan = lwsdk.LWChannelInfo().nextChannel(groupID, None)
while chan:
channelName = lwsdk.LWChannelInfo().channelName(chan)
print("channelName:" + channelName)
chan = lwsdk.LWChannelInfo().nextChannel(groupID, chan)

def process(self, ga):
# Get all the selected Objects
item_info = lwsdk.LWItemInfo()
selected = lwsdk.LWInterfaceInfo().selected_items()
for itemID in selected:
print(" item:" + item_info.name(itemID))
self.findEnv(item_info.type(itemID))
print(" ")

return lwsdk.AFUNC_OK


ServerTagInfo = [
( "listChannels", lwsdk.SRVTAG_USERNAME | lwsdk.LANGID_USENGLISH ),
( "listChannels", lwsdk.SRVTAG_BUTTONNAME | lwsdk.LANGID_USENGLISH ),
( "Utilities/Python", lwsdk.SRVTAG_MENU | lwsdk.LANGID_USENGLISH )
]

ServerRecord = { lwsdk.GenericFactory("listChannels", listChannels) : ServerTagInfo }