export-cad
Prep the selected curves for CAD and export DWG/DXF. Script next to this file:
exportcad_prep.py (dry-run by default, CAD_APPLY=True to apply). Two prep steps then an export
command.
Steps
- Model safety — ask each run (AskUserQuestion): work on a SaveAs copy (
_-SaveAsa new.3dmviarun_command, then operate there) or the current doc (prep is destructive: z-flatten + curve replacement). User's standing choice for exports is "ask every run". - Select the curves to export (or
_SelAllthen filter to curves — the script ignores non-curves). - Dry-run.
Reports selected curve count + how many are off z=0.exec(open(r"<ABS>\exportcad_prep.py").read()) - Apply prep.
Flattens every curve to z=0 (CAD_APPLY=True; exec(open(r"<ABS>\exportcad_prep.py").read())Transform.PlanarProjection(Plane.WorldXY)) and converts to arcs+lines (Curve.ToArcsAndLines) so CAD gets clean geometry, not dense NURBS. Reports flattened / converted. - Export.
run_command('_-Export "C:\\path\\plan.dwg" _Enter'). Pick a scheme:R12 Lines & Arcs— fewest vertices, arcs preserved (good for CAM/clean linework).FromIni— deterministic/headless: configure a scheme inAcadSchemes, export it to an.ini, setCurrentOption=y, then reference that.ini. Verify the exact scheme-name token against the live-Exportprompt before hardcoding a macro (tokens vary by version/locale). Prefer_Englishtokens.
Gotchas (verified where noted)
- Flatten + convert are deterministic RhinoCommon (no dialog):
Transform.PlanarProjection+Curve.ToArcsAndLines(tol, angleTol, 0, 0). Verified: a z=50 arc flattens to z=0; a wiggly NURBS becomes ~42 arc/line segments; straight/arc curves stay as they are. ToArcsAndLinesreturns None for some already-simple curves — the script keeps the flattened curve in that case (newc = pc if pc else c).- Prep is destructive (
Objects.Replace) — hence the copy-vs-current prompt in step 1. - The
-Exportstep is not fully auto-verifiable unattended (writes a file); run it with a known output path and confirm the scheme prompt live the first time.
Not yet implemented
- Auto-picking/creating the DWG scheme
.ini(currently a documented manual/one-time step). - Non-curve export (hatches/text/dims) — this skill is curve-focused; combine with
export-*strip helpers if needed.
Reference
Built 2026-07-01 (task 6 of the 6-task suite). Flatten + arc/line APIs verified live on
260629 main ms.3dm. See memory rhino-export-mechanics and the plan.