{“content”:”---\nname: freecad-cli-batch\ncategory: productivity\ndescription: FreeCAD CLI for batch processing 3D models (stone tabletop workflow)\n---\n\n# FreeCAD CLI — Batch Processing\n\n## Environment (Updated 2026-04-21)\n- PC: FreeCAD 1.1.0 portable extracted to D:\n- Path: D:\\FreeCAD\\FreeCAD_1.1.0-Windows-x86_64-py311\\bin\\freecadcmd.exe\n- SSH: ssh [email protected] (PC)\n- Note: winget -l parameter does NOT work for FreeCAD — use 7z portable instead (see below)\n\n## FreeCAD Installation on D: (when C: is full)\nwinget 安装 FreeCAD 时 -l D:\\FreeCAD 参数不会生效(bug)。正确方法:\n\n1. 下载便携版 .7z:\n bash\n # Get download URL from GitHub API\n Invoke-RestMethod -Uri 'https://api.github.com/repos/FreeCAD/FreeCAD/releases/tags/1.1.0' -TimeoutSec 15 | Select-Object -ExpandProperty assets | Where-Object {$_.name -like '*Windows*7z*'}\n # URL: https://github.com/FreeCAD/FreeCAD/releases/download/1.1.0/FreeCAD_1.1.0-Windows-x86_64-py311.7z\n \n\n2. 下载并解压(需要 7-Zip):\n bash\n curl -L -o D:\\FreeCAD.7z \"<URL>\"\n \"C:\\Program Files\\7-Zip\\7z.exe\" x D:\\FreeCAD.7z -oD:\\FreeCAD -y\n \n\n3. 实际路径在子文件夹:D:\\FreeCAD\\FreeCAD_1.1.0-Windows-x86_64-py311\\bin\\freecadcmd.exe\n\n## Critical Limitation: SSH Cannot Launch FreeCAD GUI\n- Start-Process FreeCAD.exe via SSH does not show GUI on user’s desktop — FreeCAD exits immediately or shows “not responding”\n- SSH sessions run in a different session context (Session 0 isolation on Windows Server/SSH)\n- Workaround: FreeCAD CLI creates .fcstd files successfully, but user must manually open files via Windows Explorer\n- To verify files: scp [email protected]:'D:\\hermes\\tmp\\*.fcstd' ./ to download locally\n\n## Execution Method (Correct)\npowershell\n# FreeCAD CLI does NOT use --run flag. Pass script path directly as argument.\n# IMPORTANT: Both exe and script path must be double-quoted, with the whole command in outer quotes\nssh [email protected] 'cmd /c \\\"\\\"D:\\\\FreeCAD\\\\FreeCAD_1.1.0-Windows-x86_64-py311\\\\bin\\\\freecadcmd.exe\\\" \\\"D:/path/to/script.py\\\" 2>&1\\\"'\n\n\n## Workflow: Run Python Script via SSH to Windows PC\n1. Write Python script locally (use ~/.hermes/ as staging in Termux home)\n2. SCP to PC: scp script.py [email protected]:'D:\\hermes\\tmp\\script.py'\n3. Execute via the cmd/c double-quote pattern above\n4. Stdout/stderr returned to terminal\n\n## Verified FreeCAD Python API (v1.1.0)\n- FreeCAD.newDocument() - create document\n- doc.saveAs(\"D:/path/file.fcstd\") - save document to FreeCAD format\n- Arch.makeWall(line, width=T, height=H) - create wall from line\n- Draft.makeLine(p1, p2) - create line\n- doc.addObject(\"Part::Box\", name) - create box, set .Length/.Width/.Height/.Placement\n- Draft.makeDimension(p1, p2) - DEPRECATED in 1.1.0, shows warnings but still works\n- Draft.make_linear_dimension(p1, p2) - replacement API (verify parameters)\n- Part.export([doc.Objects], 'path.step') - export to STEP\n- doc.recompute() - recalculate document\n\n## Save + Launch Workflow\nbash\n# 1. Create script with doc.saveAs() at the end\nscp script.py [email protected]:'D:\\hermes\\tmp\\script.py'\n# 2. Run with freecadcmd (saves .fcstd)\nssh [email protected] 'cmd /c \\\"\\\"D:\\FreeCAD\\...\\freecadcmd.exe\\\" \\\"D:/hermes/tmp/script.py\\\" 2>&1\\\"'\n# 3. User manually opens D:\\hermes\\tmp\\file.fcstd via Windows Explorer\n\n\n## Common Pitfalls\n- freecadcmd.exe -c \\\"python code\\\" does NOT work — must use script file\n- Inline PowerShell with heredocs over SSH fails due to quoting complexity\n- Base64 encoded commands hit Windows MAX_ARGUMENT_LENGTH limit (~32KB)\n- SCP + remote execution is the reliable pattern\n- Start-Process via SSH cannot display GUI on user’s desktop\n\n## Common Tasks\n- Open file + export STL: Part.export(shape, 'output.stl')\n- Run macro: Gui.ActiveDocument=Gui.getDocument('name')\n- Batch convert FCstd → STEP/OBJ: loop over files with import Mesh, Part\n\n## Typical Workflow (Sozo use case)\nStone tabletop 3D models (FCstd) → batch export STL for CAM/printing\n\n## Verification\nbash\nssh [email protected] \"cmd /c \\\"D:\\FreeCAD\\FreeCAD_1.1.0-Windows-x86_64-py311\\bin\\freecadcmd.exe\\\" --version\"\n\n”}