View Full Version : Get the selected items from a multilist ctl

12-19-2014, 01:43 PM
How does one get the selected items from a multilist ctl in python? In lscript I would use getvalue on the control item but that doesn't work in python.

I can get the items from set_select but I want the selected items because I want to execute something after hitting an execute button. Not through set_select.

01-10-2015, 10:02 PM

03-04-2015, 07:42 PM
Bump again.

03-23-2015, 07:35 PM
Bob was kind enough to update the example script.

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

This is a LightWave Generic plug-in that has the sole purpose
of testing the lwsdk.Panels 'multilist_ctl' mechanics, with all of
its callbacks.

__author__ = "Bob Hood"
__date__ = "Dec 1 2011"
__copyright__ = "Copyright (C) 2011 NewTek, Inc."
__version__ = "1.0"
__maintainer__ = "Bob Hood"
__email__ = "[email protected]"
__status__ = "Example"
__lwver__ = "11"

RESOURCE = '\04(k:"%s" c:LWPy)'

import lwsdk

# The LW Panels system does not make copies of control text elements. Therefore,
# when returning text elements to the wrapper layer from callbacks, they must have
# anchorage within Python to retain their reference counts. Returning text
# directly will cause reclamation to occcur, and garbage will be displayed on the
# interface (best case) or the application may crash (worst case).

multi_text = [ ["first", "text"], ["second", "text"], ["third", "text"] ]

class test_panels_multilist(lwsdk.IGeneric):
def __init__(self, context):
global multi_text
super(test_panels_multilist, self).__init__()

# we must keep track of selection results ourselves
self.row_select = [False for t in multi_text]

# Callbacks --------------------------------------
def name_2d(self, control, userdata, row, column):
return RESOURCE % multi_text[row][column]

def count_2d(self, control, userdata):
return len(multi_text)

def column_width(self, control, userdata, column):
if column >= len(multi_text[0]):
return 0
return 100

def multi_select_event_func(self, control, user_data, row, selecting):
if row < 0:
# list selections are being cleared
self.row_data = [False for t in multi_text]

self.row_data[row] = selecting

action = 'deselected'
if selecting:
action = action[2:]

print 'You %s: %s' % (action, ' '.join(multi_text[row]))

# LWGeneric -------------------------------------------
def process(self, generic_access):
ui = lwsdk.LWPanels()
panel = ui.create(RESOURCE % 'Test Multilist')

c1 = panel.multilist_ctl(RESOURCE % 'Multilist', 200, 10, self.name_2d, self.count_2d, self.column_width)

if panel.open(lwsdk.PANF_BLOCKING | lwsdk.PANF_RESIZE) == 0:
return lwsdk.AFUNC_OK


selected = []
for i in range(len(multi_text)):
if self.row_data[i]:
selected.append('%s' % ' '.join(multi_text[i]))
if len(selected):
print 'Your final selection is: %s' % ', '.join(selected)

return lwsdk.AFUNC_OK

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

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

03-24-2015, 09:33 AM
Is that RESOURCE format for LW2015? It looks bad in LW11.6.3 unless it's changed to:


03-24-2015, 05:54 PM
Is that RESOURCE format for LW2015? It looks bad in LW11.6.3 unless it's changed to:


TBH I don't know. It was what was just passed on to me.

03-24-2015, 08:07 PM
The RESOURCE thing is for localization in LW2015. It can be removed, or replaced as ernpchan suggested, for older versions of LW.