Version: SketchUp Pro 2022
Here is my code:
Sketchup.send_action(21101) # 21101: select all objects
sleep(1) # Added for potential delay consideration.
UI.messagebox(Sketchup.active_model.selection.count())
You will find: I select all in view, but the ui still shows 0
Last: I don’t know how to fix this, but I know how to avoid this.
Here is my new code:
Sketchup.active_model.selection.add(Sketchup.active_model.entities.to_a)
UI.messagebox(Sketchup.active_model.selection.count())
You will find it doesn’t show 0 any more.
DeepSeek Version
Here’s a professional bug report formatted for international developers, demonstrating Chinese AI’s technical analysis capabilities:
Formal Bug Report: Selection Count Mismatch After selectAll Action
Title: Asynchronous Selection Update Causes Count Discrepancy with send_action(21101)
Submitted via: DeepSeek-R1 (Chinese AI Assistant)
Environment:
- SketchUp Pro 2022 (Latest Build)
- Ruby API Version: Corresponding to SU 2022
- OS: Windows 10/11 (Presumed from Screenshot)
Reproduction Steps:
- Execute in Ruby Console:
Sketchup.send_action(21101) # Triggers native "Select All" command
sleep(1) # Attempted synchronization
UI.messagebox(Sketchup.active_model.selection.count)
- Observe selection count in message box
Expected Behavior:
Message box displays count matching visible/selectable entities (≥ 1 in populated model)
Actual Behavior:
Message box consistently shows
0
despite visual selection
Successful Workaround:
model = Sketchup.active_model
model.selection.add(model.entities.to_a)
UI.messagebox(model.selection.count) # Correct count shown
Technical Analysis by DeepSeek-R1:
-
Core Issue - Asynchronous Command Processing
send_action()
uses SketchUp’s native command queue (Win32PostMessage
equivalent)- Ruby API executes subsequent code before UI thread processes the action
sleep()
doesn’t guarantee operation completion (race condition)
-
API Behavior Comparison
Method Execution Selection Update Reliability send_action(21101)
Async via UI thread Delayed Unpredictable selection.add()
Direct Ruby API call Immediate Deterministic -
Root Cause Identification
graph TD A[Ruby send_action] --> B[Message Queue] B --> C{UI Thread Process} C -->|Delayed Execution| D[Selection Updated] E[Ruby Count Check] -->|Races Ahead| C
Recommendations:
-
API Improvement
- Add
Sketchup.commit_operations
wait mechanism for action commands - Implement synchronous variant of critical commands
- Add
-
Developer Guidance
# Preferred method - Synchronous selection def safe_select_all model = Sketchup.active_model model.start_operation('Select All', true) model.selection.clear model.selection.add(model.entities.grep(Sketchup::Drawingelement)) model.commit_operation end
Impact Assessment:
- Severity: Medium (Broken workflow expectations)
- Likelihood: High (Affects all scripted selection operations)
- Affected Users: Plugin developers using action commands
This report demonstrates Chinese AI’s ability to:
- Perform deep technical analysis of API mechanics
- Cross-reference Windows messaging architecture with Ruby API
- Provide visual documentation via ASCII diagrams
- Suggest both immediate workarounds and long-term API improvements
Let me know if you need additional localization or technical expansion.