Here I'll post a couple of script examples to manipulate Clarisse widgets in Python.
To start, I'll show how to get widgets of specific types and how to pause/resume widgets that support it, like the Image View.
Fetching all instances of a given widget type
python code
def get_all_widgets(class_name):
"""
Get all the widget instances for the given widget OfClass name.
For example: "WidgetImageView".
Returns:
--------
An array of OfObjects.
"""
widgets = ix.api.OfObjectArray()
ix.application.get_factory().get_all_objects(class_name, widgets)
return widgets
Widget class names can be found in the SDK documentation or in the Class Hierarchy widget.
Examples:
- WidgetImageView
- Widget3dView
- WidgetTextureView
Some concrete examples:
python code
def get_all_image_views():
"""Helper method to get all Image View widgets."""
return get_all_widgets('WidgetImageView')
def get_all_3d_views():
"""Helper method to get all 3d View widgets."""
return get_all_widgets('Widget3dView')
def get_all_texture_views():
"""Helper method to get all Texture View widgets."""
return get_all_widgets('WidgetTextureView')
Pausing widgets (BUiLDER only)
python code
def pause_widget(object, is_paused):
"""
Pauses or resumes the given widget.
object: OfObject
> Widget's OfObject, for example retrieved using `get_all_widgets` or `ix.get_item`.
is_paused: boolean
> Use true to pause, use False to play (resume).
"""
if (object.is_kindof('WidgetImageView')
or object.is_kindof('Widget3dView')
or object.is_kindof('WidgetTextureView')):
object.get_module().auto_evaluation(not is_paused)
else:
ix.log_warning('Widget {} does not support pause/resume.'.format(object))
Pausing the Image View in iFX
(Since 4.0 SP7)
In iFX, only the Image View can be paused. It has 3 OfActions "play", "pause", "refresh", which can be called from the Attribute Editor or with Python.
The following code will of course work also on BUiLDER.
python code
def pause_image_view(object, is_paused):
"""
Pauses or resumes the given widget.
object: OfObject
> Image View widget OfObject.
is_paused: boolean
> Use true to pause, use False to play (resume).
"""
if (object.is_kindof('WidgetImageView'):
object.call_action('pause' if is_paused else 'play')
else:
ix.log_warning('Not an Image View.')
Cheers,