dsh-cad-studio 0.30.0 → 0.30.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +17 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -2748,7 +2748,7 @@ else:
2748
2748
  const dir = dirs.find((d) => existsSync(join(d, `${model}.json`))) || dirs[0]
2749
2749
  const doc = await readModel(model, dir)
2750
2750
  bridge.noteModelsDir(dir)
2751
- const exported = await exportModelStep(doc, target)
2751
+ const exported = await exportModelStep(doc, target, { unify })
2752
2752
  return { ...exported, source: `model:${model}` }
2753
2753
  }
2754
2754
  const src = shapesFrom({ source, code })
@@ -5073,17 +5073,18 @@ except Exception:
5073
5073
  : `${PRELUDE}\nP = ${JSON.stringify(doc.params ?? {})}\n${doc.script}\n`
5074
5074
  }
5075
5075
 
5076
- async function exportModelStep(doc, target) {
5076
+ async function exportModelStep(doc, target, opts = {}) {
5077
5077
  if (typeof target !== 'string' || !target) throw new Error('export 需要目标路径,例如 /path/model.step')
5078
5078
  await mkdir(dirname(target), { recursive: true })
5079
5079
  const head = doc.kind === 'features'
5080
5080
  ? featuresScript(featureOps(doc), target, { sketches: doc.sketches })
5081
5081
  : `${PRELUDE}\nP = ${JSON.stringify(doc.params ?? {})}\n${doc.script}\n`
5082
+ const unify = opts.unify !== false
5082
5083
  const code = doc.kind === 'features'
5083
5084
  ? head
5084
5085
  : `${head}import os as _os
5085
5086
  _os.makedirs(_os.path.dirname(${JSON.stringify(target)}) or ".", exist_ok=True)
5086
- Part.makeCompound([scene]).exportStep(${JSON.stringify(target)})
5087
+ ${unify ? 'try:\n if hasattr(scene, "removeSplitter"):\n _u = scene.removeSplitter()\n if _u is not None and len(_u.Solids):\n scene = _u\nexcept Exception:\n pass\n' : ''}Part.makeCompound([scene]).exportStep(${JSON.stringify(target)})
5087
5088
  __out = {"ok": True, "exported": ${JSON.stringify(target)}, "volume": round(scene.Volume, 3),
5088
5089
  "bytes": _os.path.getsize(${JSON.stringify(target)})}`
5089
5090
  // publish:false — an export is a product, not a new row in the model list.
@@ -5091,7 +5092,19 @@ __out = {"ok": True, "exported": ${JSON.stringify(target)}, "volume": round(scen
5091
5092
  if (out.ok === false) return { ...out, model: doc.name, path: target }
5092
5093
  let bytes = Number(out.bytes ?? 0)
5093
5094
  try { bytes = (await stat(target)).size } catch {}
5094
- return { ok: true, model: doc.name, path: target, bytes, valid: bytes > 200, volume: out.volume ?? null }
5095
+ // Read the written file back once: the return has to say what was actually
5096
+ // exported (solids/faces/shells), not what the script intended. Callers used
5097
+ // to have to start a second kernel just to count faces.
5098
+ let geom = null
5099
+ try {
5100
+ const probe = await bridge.run(`${PRELUDE}\n_s = Part.Shape()\n_s.read(${JSON.stringify(target)})\n__out = {"ok": True, "solids": len(_s.Solids), "faces": len(_s.Faces), "shells": len(_s.Shells), "volume": round(_s.Volume, 3)}\n`, { title: 'read back', publish: false })
5101
+ if (probe.ok && Number.isFinite(probe.faces)) geom = probe
5102
+ } catch { /* the export itself succeeded; the readback is extra evidence */ }
5103
+ return {
5104
+ ok: true, model: doc.name, path: target, bytes, valid: bytes > 200,
5105
+ volume: geom?.volume ?? out.volume ?? null,
5106
+ ...(geom ? { solids: geom.solids, faces: geom.faces, shells: geom.shells, fingerprint: { solids: geom.solids, faces: geom.faces, shells: geom.shells, volume: geom.volume } } : {}),
5107
+ }
5095
5108
  }
5096
5109
 
5097
5110
  /** One readable sentence per doc write, e.g. "改参数 高 从 20 到 30". */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-cad-studio",
3
- "version": "0.30.0",
3
+ "version": "0.30.1",
4
4
  "type": "module",
5
5
  "description": "CAD Studio — FreeCAD 桥(给 AI 的 14 个工具)+ Web 右栏 3D 面板:建模/装配/关节运动/出图/多页签查看",
6
6
  "exports": {