Skip to content

Instantly share code, notes, and snippets.

@promto-c
Created October 26, 2025 11:01
Show Gist options
  • Select an option

  • Save promto-c/119cf6a5eadb79d3cc31078914d4c26d to your computer and use it in GitHub Desktop.

Select an option

Save promto-c/119cf6a5eadb79d3cc31078914d4c26d to your computer and use it in GitHub Desktop.
A SilhouetteFX Python utility that manages the viewer’s stream mode (Left, Right, or Left-Right) and preserves selection by reselecting linked items in the opposite view.
"""Copyright (C) 2025 promto-c
Permission Notice:
- You are free to use, copy, modify, and distribute this software for any purpose.
- No restrictions are imposed on its use.
- Credit is appreciated but not required.
- Use at your own risk; this software is provided "AS IS", without any warranty — express or implied — including, but not limited to, warranties of merchantability or fitness for a particular purpose.
- This notice does not apply to any third-party libraries or dependencies; those are subject to their respective licenses.
"""
import fx
class StreamMode:
LEFT = 1
RIGHT = 2
LEFT_RIGHT = 3
class ViewerUtil:
@staticmethod
def set_stream_mode(stream_mode):
"""Set the viewer's stream mode and update the selection to match.
Args:
stream_mode (int | StreamMode): The stream mode to set.
"""
# Skip if already set
if fx.viewer.streamMode == stream_mode:
return
# Store the current selection before changing the stream mode
selection = fx.selection()
# Update viewer's stream mode
# Skip selection update if no selection
# or if the viewer is in stereo-aligned mode
fx.viewer.streamMode = stream_mode
if not selection or fx.viewer.stereoAlign:
return
# Reselect linked items from the opposite view for sync.
resolved_selection = [item.link for item in selection if item.link]
if stream_mode == StreamMode.LEFT_RIGHT:
resolved_selection += selection
fx.select(resolved_selection)
# Example Usage
# -------------
if __name__ == "__main__":
fx.bind('Shift+1', lambda: ViewerUtil.set_stream_mode(StreamMode.LEFT))
fx.bind('Shift+2', lambda: ViewerUtil.set_stream_mode(StreamMode.RIGHT))
# Disable left-right view control binding to prevent conflicts.
fx.viewer.setControlBind('leftRightView', '')
fx.bind('Shift+3', lambda: ViewerUtil.set_stream_mode(StreamMode.LEFT_RIGHT))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment