-
Notifications
You must be signed in to change notification settings - Fork 68
fix(cad): keep laptop keys when switching to a larger servo #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |||||||||||||||||||
| WORKSPACE_ID = 'FusionSolidEnvironment' | ||||||||||||||||||||
| PANEL_ID = 'SolidScriptsAddinsPanel' | ||||||||||||||||||||
| SERVO_ID_PARAM = 'servo_id' | ||||||||||||||||||||
| KEYBOARD_SKETCH = 'keyboard' | ||||||||||||||||||||
|
|
||||||||||||||||||||
| _handlers = [] | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -176,6 +177,63 @@ def _apply_servo(design, servo_data, show_errors=True): | |||||||||||||||||||
| return False | ||||||||||||||||||||
|
|
||||||||||||||||||||
| design.computeAll() | ||||||||||||||||||||
| fix_keyboard_cut(design) | ||||||||||||||||||||
| return True | ||||||||||||||||||||
|
Comment on lines
+180
to
+181
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: sed -n '130,185p' 3d_models/fusion/TinyEngineerTools/servo.py
rg -n '_apply_servo|Execute error|fix_keyboard_cut' 3d_models/fusion/TinyEngineerToolsRepository: jamro/tiny-engineer Length of output: 2643 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- servo.py helper and configurator ---'
sed -n '195,290p' 3d_models/fusion/TinyEngineerTools/servo.py | cat -n
printf '%s\n' '--- parts_exporter callers ---'
sed -n '285,315p' 3d_models/fusion/TinyEngineerTools/parts_exporter.py | cat -n
sed -n '465,495p' 3d_models/fusion/TinyEngineerTools/parts_exporter.py | cat -n
printf '%s\n' '--- relevant surrounding symbols ---'
rg -n -C 5 'def execute|_apply_servo\\(|fix_keyboard_cut\\(|Execute error|update failure|Failed to set servo parameters' 3d_models/fusion/TinyEngineerTools/servo.py 3d_models/fusion/TinyEngineerTools/parts_exporter.pyRepository: jamro/tiny-engineer Length of output: 6830 🏁 Script executed: sed -n '195,290p' 3d_models/fusion/TinyEngineerTools/servo.py
sed -n '285,315p' 3d_models/fusion/TinyEngineerTools/parts_exporter.py
sed -n '465,495p' 3d_models/fusion/TinyEngineerTools/parts_exporter.pyRepository: jamro/tiny-engineer Length of output: 5419 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- servo.py command registration and changed context ---'
rg -n -C 6 'ExecuteHandler|CommandCreatedHandler|addCommandCreated|commandCreated|fix_keyboard_cut|def _apply_servo' 3d_models/fusion/TinyEngineerTools/servo.py
printf '%s\n' '--- PR diff for servo.py ---'
git diff 8975e63ce0971d2cb8d91f0ea2071db718b58bda a7d5b9b022606596829afe7f83526ae2b113811e -- 3d_models/fusion/TinyEngineerTools/servo.py
printf '%s\n' '--- exporter outer exception handling ---'
rg -n -C 8 'try:|except Exception|_apply_servo|_restore_params|Execute error' 3d_models/fusion/TinyEngineerTools/parts_exporter.pyRepository: jamro/tiny-engineer Length of output: 14496 🏁 Script executed: rg -n -C 6 'ExecuteHandler|CommandCreatedHandler|addCommandCreated|commandCreated|fix_keyboard_cut|def _apply_servo' 3d_models/fusion/TinyEngineerTools/servo.py
git diff 8975e63ce0971d2cb8d91f0ea2071db718b58bda a7d5b9b022606596829afe7f83526ae2b113811e -- 3d_models/fusion/TinyEngineerTools/servo.pyRepository: jamro/tiny-engineer Length of output: 6543 Handle keyboard-cut failures after parameter updates.
Suggested fix design.computeAll()
- fix_keyboard_cut(design)
+ try:
+ fix_keyboard_cut(design)
+ except Exception:
+ if show_errors:
+ _error('Servo parameters applied; keyboard cut update failed')
+ return False
return True📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| def _profiles(extrude): | ||||||||||||||||||||
| """Sketch profiles an extrude uses (skips sketch text and faces).""" | ||||||||||||||||||||
| try: | ||||||||||||||||||||
| selection = extrude.profile | ||||||||||||||||||||
| except Exception: | ||||||||||||||||||||
| return [] | ||||||||||||||||||||
| items = [selection] | ||||||||||||||||||||
| if not adsk.fusion.Profile.cast(selection) and hasattr(selection, 'count'): | ||||||||||||||||||||
| items = [selection.item(i) for i in range(selection.count)] | ||||||||||||||||||||
| return [p for p in map(adsk.fusion.Profile.cast, items) if p] | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| def _keyboard_cut(design): | ||||||||||||||||||||
| """Return (sketch, extrude) for the cut that uses the keyboard sketch.""" | ||||||||||||||||||||
| for component in design.allComponents: | ||||||||||||||||||||
| sketch = component.sketches.itemByName(KEYBOARD_SKETCH) | ||||||||||||||||||||
| if not sketch: | ||||||||||||||||||||
| continue | ||||||||||||||||||||
| for extrude in component.features.extrudeFeatures: | ||||||||||||||||||||
| profiles = _profiles(extrude) | ||||||||||||||||||||
| if profiles and profiles[0].parentSketch.name == KEYBOARD_SKETCH: | ||||||||||||||||||||
| return sketch, extrude | ||||||||||||||||||||
| return None, None | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| def fix_keyboard_cut(design): | ||||||||||||||||||||
| """Re-select the keyboard cut profile after a servo size change. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| The extrude on the `keyboard` sketch cuts the deck region around the | ||||||||||||||||||||
| keys: one profile whose inner loops are the key outlines. When the key | ||||||||||||||||||||
| grid grows, Fusion also maps the new key profiles into that cut, so those | ||||||||||||||||||||
| keys vanish (#31). Reset the selection to the profile with the most loops. | ||||||||||||||||||||
| Returns True when the selection was changed. | ||||||||||||||||||||
| """ | ||||||||||||||||||||
| sketch, extrude = _keyboard_cut(design) | ||||||||||||||||||||
| if not extrude or sketch.profiles.count == 0: | ||||||||||||||||||||
| return False | ||||||||||||||||||||
|
|
||||||||||||||||||||
| deck_loops = max(p.profileLoops.count for p in sketch.profiles) | ||||||||||||||||||||
| selected = _profiles(extrude) | ||||||||||||||||||||
| if len(selected) == 1 and selected[0].profileLoops.count == deck_loops: | ||||||||||||||||||||
| return False | ||||||||||||||||||||
|
|
||||||||||||||||||||
| timeline = design.timeline | ||||||||||||||||||||
| marker = timeline.markerPosition | ||||||||||||||||||||
| extrude.timelineObject.rollTo(True) | ||||||||||||||||||||
| try: | ||||||||||||||||||||
| extrude.profile = max( | ||||||||||||||||||||
| sketch.profiles, key=lambda p: p.profileLoops.count | ||||||||||||||||||||
| ) | ||||||||||||||||||||
| finally: | ||||||||||||||||||||
| timeline.markerPosition = marker | ||||||||||||||||||||
| design.computeAll() | ||||||||||||||||||||
| return True | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: jamro/tiny-engineer
Length of output: 6148
🏁 Script executed:
Repository: jamro/tiny-engineer
Length of output: 15694
🏁 Script executed:
Repository: jamro/tiny-engineer
Length of output: 7991
Keep keyboard-cut repair failures out of the export cleanup path.
fix_keyboard_cutdoes not catch a failedextrude.profileassignment. Itsfinallyblock restores the timeline marker, but the assignment exception still propagates. Because_restore_paramsruns in the exporter'sfinally, that exception can replace the original export exception or make a completed export reportExecute error. Catch the repair failure locally so parameter restoration does not change the export result.Suggested fix
if to_set: design.modifyParameters(to_set, values) design.computeAll() - servo.fix_keyboard_cut(design) + try: + servo.fix_keyboard_cut(design) + except Exception: + pass📝 Committable suggestion
🤖 Prompt for AI Agents