Skip to content

Add CAD-style cross selection as the default for Bonsai tools#8153

Open
theoryshaw wants to merge 2 commits into
v0.8.0from
cross_select_integration
Open

Add CAD-style cross selection as the default for Bonsai tools#8153
theoryshaw wants to merge 2 commits into
v0.8.0from
cross_select_integration

Conversation

@theoryshaw

Copy link
Copy Markdown
Member

Introduce bim.cross_select, a Rhino/CAD-style box selection operator, and route every Bonsai workspace tool's selection through it. Dragging the box left-to-right selects only fully-enclosed elements (window); right-to-left selects anything the box touches (crossing). Works in Object and Edit Mesh modes; plain click, Shift (add) and Ctrl (subtract) behave as expected, and clicking empty space deselects.

Selection logic is ported from the GPL-3.0 Blender-Cross-Select add-on (RARA, CYX, Witty.Ming, Shuimeng), reduced to box-only mode and adapted to read its colors and line width from Bonsai's add-on preferences.

A new "Cross Select" add-on preference (CrossSelectPreferences) toggles the behavior. Because a WorkSpaceTool's bl_keymap is baked at import, the shared selection keymap is split into cross-select vs native variants and applied via apply_cross_select_preference(), which rebuilds each tool's keymap and re-registers all selection tools in place. Toggling the preference re-applies live via a deferred timer, and the saved preference is applied on startup. When disabled, tools fall back to Blender's native view3d.select_box / view3d.select.

  • tool/blender.py: split native/cross-select keymaps, pref-driven get_default_selection_keypmap, apply_cross_select_preference re-registration
  • bim/module/model/workspace.py: bim.cross_select operator and geometry/draw helpers
  • bim/ui.py: CrossSelectPreferences group, preferences UI, live-toggle callback
  • bim/init.py: register preference group, apply saved preference on startup
  • bim/module/model/init.py: register CrossSelect operator

Generated with the assistance of an AI coding tool.

theoryshaw and others added 2 commits June 7, 2026 17:33
Introduce bim.cross_select, a Rhino/CAD-style box selection operator, and route
every Bonsai workspace tool's selection through it. Dragging the box left-to-right
selects only fully-enclosed elements (window); right-to-left selects anything the
box touches (crossing). Works in Object and Edit Mesh modes; plain click, Shift
(add) and Ctrl (subtract) behave as expected, and clicking empty space deselects.

Selection logic is ported from the GPL-3.0 Blender-Cross-Select add-on
(RARA, CYX, Witty.Ming, Shuimeng), reduced to box-only mode and adapted to read
its colors and line width from Bonsai's add-on preferences.

A new "Cross Select" add-on preference (CrossSelectPreferences) toggles the
behavior. Because a WorkSpaceTool's bl_keymap is baked at import, the shared
selection keymap is split into cross-select vs native variants and applied via
apply_cross_select_preference(), which rebuilds each tool's keymap and
re-registers all selection tools in place. Toggling the preference re-applies
live via a deferred timer, and the saved preference is applied on startup. When
disabled, tools fall back to Blender's native view3d.select_box / view3d.select.

- tool/blender.py: split native/cross-select keymaps, pref-driven
  get_default_selection_keypmap, apply_cross_select_preference re-registration
- bim/module/model/workspace.py: bim.cross_select operator and geometry/draw helpers
- bim/ui.py: CrossSelectPreferences group, preferences UI, live-toggle callback
- bim/__init__.py: register preference group, apply saved preference on startup
- bim/module/model/__init__.py: register CrossSelect operator

Generated with the assistance of an AI coding tool.
…NG modal

Blender fires all matching tool-keymap entries' invoke() even after an
earlier entry returned RUNNING_MODAL.  When cross-select is enabled,
bim.cross_select (bl_options BLOCKING) goes modal on every LMB press
alongside bim.click_nearest_dimension_anchor.  Its BLOCKING flag causes
it to win the RELEASE event, selecting the background object instead of
activating the anchor dot.

Fix: CrossSelect.invoke() now calls _near_dimension_dot() before going
modal.  If a parametric dimension anchor dot is within 15 px of the
cursor it returns PASS_THROUGH, yielding to ClickNearestDimensionAnchor.

Also fixes apply_cross_select_preference to preserve pre-selection
entries (e.g. ClickNearestDimensionAnchor) when rebuilding tool keymaps:
replaces _tool_extra_keymap (which assumed the selection block starts at
index 0) with _split_tool_keymap, which searches for the selection block
by operator name and returns (pre, post) slices independently.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant