← Commit history

Publish 1.9.220

John Lauer ·6b75b829b6 ·1mo ago ·parent 642e605
2 files changed +58−11
addin/AdomBridge/commands/modeling.py+51−1
@@ -22,6 +22,49 @@ import adsk.core import adsk.fusion  +# ── Raw Fusion API errors -> stable codes + actionable hints ──────────────────+# Oliver, PR #34 item 3 / PR #38 (opened 2026-07-27 and 2026-08-10, and I left both+# unanswered for weeks - see the reply on those PRs). A modelling script that fails+# returns Fusion's raw exception text, which for the three failures below says nothing+# about what to DO. The Part-vs-Assembly one in particular is undocumented and cost a+# real session hours: the script is correct, the DESIGN is in the wrong mode.+#+# Matching is on substrings because Fusion's wording varies by version, and every rule+# FALLS BACK to the raw error rather than swallowing it - a misclassification must never+# hide the real message. Codes are stable; the raw text always rides along.+_MODELING_ERROR_RULES = [+    (("single component", "part design", "assembly design", "design type"),+     "part_design_single_component",+     "This design is in Fusion's SINGLE-COMPONENT (Part Design) mode, which forbids "+     "creating components - the script is fine, the design mode is wrong. Switch the "+     "design to Assembly Design (right-click the root in the browser, or set the design "+     "type), or model directly into the root component instead of adding one."),+    (("root component", "cannot be renamed", "name of the root"),+     "root_component_rename",+     "Fusion will not rename the ROOT component from the API - its name follows the "+     "DOCUMENT name. Rename the document instead (save-as with the name you want), or "+     "rename a child occurrence rather than the root."),+    (("object is invalid", "no longer valid", "has been deleted", "referenced object"),+     "deleted_entity_reference",+     "The script referenced an entity that no longer exists - Fusion invalidates handles "+     "when a feature is deleted, rolled back, or recomputed. Re-fetch the object from its "+     "collection immediately before use rather than holding a handle across operations."),+]+++def _classify_modeling_error(err_text: str):+    """(errorCode, hint) for a raw Fusion exception, or (None, None) when unrecognised.++    Unrecognised is a legitimate answer: inventing a code for an error we do not+    understand would be worse than saying nothing, because a caller would branch on it.+    """+    t = (err_text or "").lower()+    for needles, code, hint in _MODELING_ERROR_RULES:+        if any(n in t for n in needles):+            return code, hint+    return None, None++ def handle_run_modeling_script(app: adsk.core.Application, args: dict) -> dict:     script = args.get("script") or args.get("code") or ""     if not script:@@ -53,10 +96,17 @@ def handle_run_modeling_script(app: adsk.core.Application, args: dict) -> dict:         with contextlib.redirect_stdout(buf):             exec(script, ns)     except Exception as e:-        return {"success": False, "error": str(e),+        _code, _hint = _classify_modeling_error(str(e))+        _out = {"success": False, "error": str(e),                 "data": {"traceback": traceback.format_exc(), "stdout": buf.getvalue()},                 "_hint": "Modeling-script error (a code/geometry problem, NOT the Fusion license). "                          "Read-only Fusion still creates geometry in memory; only cloud-save is blocked."}+        if _code:+            # The raw error STAYS in `error`; the classification is additive, so a caller+            # that does not know this code still sees exactly what it saw before.+            _out["errorCode"] = _code+            _out["_hint"] = _hint + " (Fusion's own message is in `error`.)"+        return _out      res = ns.get("result")     # Keep the return JSON-safe.
page.json+7−10
@@ -11,10 +11,6 @@     "uninstall": "./uninstall.sh"   },   "tags": [-    "ab",-    "bridge",-    "fusion",-    "desktop-app",     "fusion360",     "autodesk",     "cad",@@ -79,10 +75,7 @@     "build a basic parts library",     "add a 3d model to a component",     "make a fusion 360 library with 3d",-    "set up the fusion bridge",-    "fusion dashboard",-    "fusion status page",-    "open the fusion launch page"+    "set up the fusion bridge"   ],   "discovery_pitch": "Use the Adom Bridge Fusion 360 bridge when the user wants to DRIVE Autodesk Fusion 360 from the cloud: open/search their team's Fusion cloud designs, lay out a PCB or do electronics, export STEP/IGES/STL/Gerbers/BOM, or build a component library with real rendering 3D. It runs Fusion on the user's own machine via Adom Bridge. NOT for web/browser/login/form-filling (that's the native-browser extension) and NOT for KiCad (that's the kicad bridge).",   "brief": "Drive Autodesk Fusion 360 from the cloud via Adom Bridge: component libraries, IPC package generation, board layout, exports (STEP/Gerbers/BOM/CPL), fast APS cloud search, and parametric modeling.",@@ -111,5 +104,9 @@       "label": "Part volume",       "prompt": "How much material does each printed part in this assembly use?"     }-  ]-}+  ],+  "author": {+    "name": "John Lauer",+    "email": "[email protected]"+  }+}\ No newline at end of file