Page 1 of 1

how to make a ui interactive with scene selection?

Unread postPosted: Thu Feb 13, 2020 9:43 pm
by nourseeeee
Hi there, I'm currently working on a script in clarisse and I'm struggling on making my ui interactive with my scene.

My script is creating a window that populate buttons and labels based on a list of a selection of objects. This is all working fine, however I would like to have my window updating with a new list when I make a different selection in clarisse without having to close the window and relaunch the script.

Any help of clue?

Re: how to make a ui interactive with scene selection?

Unread postPosted: Mon Feb 17, 2020 2:32 pm
by anemoff

I've made this very basic example to illustrate the usage.
It shows a GuiWindow with a GuiTextEdit, and the GuiTextEdit shows the current selection as text and reacts to selection change.

python code

class MyWidget(ix.api.GuiWindow):

def __init__(self, app, x, y, w, h):
# init the window
ix.api.GuiWindow.__init__(self, app, x, y, w, h, 'My Widget') = app

# connect to app selection change event
self.connect(app, 'EVT_ID_SELECTION_CHANGED', self.on_selection_changed)

# create ui
self.text_edit = ix.api.GuiTextEdit(self, 0, 0, w, h)

# show it
# listen to application events
# note: this loop is blocking until the widget is closed (manually or via a custom button, for example)
while self.is_shown():

def on_selection_changed(self, sender, event_id):
except Exception as e:
ix.log_warning('Exception in MyWidget.on_selection_changed:\n{}'.format(e))

def get_selection_as_text(self):
text = 'Selection:\n'
if ix.selection.is_empty():
text += '<empty>'
for i, item in enumerate(ix.selection):
text += '{} - {}\n'.format(i + 1, item)
return text

# Run it
w = MyWidget(ix.application, 0, 0, 400, 300)
except Exception as e:
ix.log_error('Script error:\n{}'.format(e))

Note: you can derive directly fromix.api EventObject if you don't want your main class to derive from a Gui class. However, deriving from EventObject is mandatory to allow your class to listen to events and use "connect".
For example, you could have "class MyTool(ix.api.EventObject)", which then creates a GuiWindow. It's just a different approach.

I hope this gets you started with what you want to do.


Re: how to make a ui interactive with scene selection?

Unread postPosted: Wed Feb 19, 2020 12:02 am
by nourseeeee
Thanks for the answer that's really helpful!!