From ebd0d4d9a9dcc2602a431a5132b5c5eac8982e9f Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Mon, 30 Nov 2026 19:55:59 -0500 Subject: [PATCH] feat(mcp): export DXF/SVG, post G-code, set sheet outlines Agents could bring drawings in but only save .nest files, and could not describe an irregular sheet. New tools: export_plate and export_drawing (DXF/SVG/placement text, as File > Export), list_posts and post_nest (behind the same pre-post verification gate as desktop and console, with consent per call), and set_plate_outline (as the console's --outline). The shipped posts now copy to Posts/ beside the server on build and publish. Co-Authored-By: Claude Opus 5.5 --- .../McpOutputToolsTests.cs | 186 +++++++++++ OpenNest.Mcp/OpenNest.Mcp.csproj | 32 ++ OpenNest.Mcp/Tools/OutputTools.cs | 307 ++++++++++++++++++ docs/irregular-stock.md | 3 +- docs/post-verification.md | 9 +- docs/svg-import-export.md | 2 +- 6 files changed, 536 insertions(+), 3 deletions(-) create mode 100644 OpenNest.FrontEnd.Tests/McpOutputToolsTests.cs create mode 100644 OpenNest.Mcp/Tools/OutputTools.cs diff --git a/OpenNest.FrontEnd.Tests/McpOutputToolsTests.cs b/OpenNest.FrontEnd.Tests/McpOutputToolsTests.cs new file mode 100644 index 00000000..3a45f4c3 --- /dev/null +++ b/OpenNest.FrontEnd.Tests/McpOutputToolsTests.cs @@ -0,0 +1,186 @@ +using OpenNest.Mcp; +using OpenNest.Mcp.Tools; + +namespace OpenNest.FrontEnd.Tests; + +/// +/// The MCP tools that take work out of the session (DXF/SVG export and posted CNC output) and +/// make a plate an irregular sheet from a file. +/// +public sealed class McpOutputToolsTests : IDisposable +{ + private readonly string directory = Path.Combine(Path.GetTempPath(), "opennest-mcp-output-" + Guid.NewGuid()); + + public McpOutputToolsTests() => Directory.CreateDirectory(directory); + + public void Dispose() + { + try { Directory.Delete(directory, true); } catch (Exception ex) when (ex is IOException or UnauthorizedAccessException) { } + } + + private static (NestSession Session, OutputTools Output) FilledSession() + { + var session = new NestSession(); + new InputTools(session).CreateDrawing("square", "rectangle", 10, 10); + new SetupTools(session).CreatePlate(48, 48, partSpacing: 1); + new NestingTools(session).FillPlate(0, "square", quantity: 4); + Assert.Equal(4, session.GetPlate(0)!.Parts.Count); + return (session, new OutputTools(session)); + } + + [Fact] + public void ExportPlateWritesDxfAndSvgAndRefusesToOverwrite() + { + var (_, output) = FilledSession(); + var dxf = Path.Combine(directory, "plate.dxf"); + var svg = Path.Combine(directory, "out", "plate.svg"); + + Assert.StartsWith("Exported plate 0 (4 parts)", output.ExportPlate(0, dxf)); + Assert.StartsWith("Exported plate 0", output.ExportPlate(0, svg)); + Assert.Contains(" 0); + + var before = File.ReadAllBytes(dxf); + Assert.Contains("already exists", output.ExportPlate(0, dxf)); + Assert.Equal(before, File.ReadAllBytes(dxf)); + Assert.StartsWith("Exported", output.ExportPlate(0, dxf, overwrite: true)); + + Assert.StartsWith("Error", output.ExportPlate(0, Path.Combine(directory, "plate.png"))); + Assert.StartsWith("Error", output.ExportPlate(0, Path.Combine(directory, "plate.dxf2"))); + Assert.StartsWith("Error", output.ExportPlate(0, Path.Combine(directory, "laser.dxf"), forLaserSoftware: true)); + Assert.StartsWith("Error: plate 3 not found", output.ExportPlate(3, Path.Combine(directory, "none.dxf"))); + Assert.StartsWith("Error", output.ExportPlate(0, "relative.dxf")); + } + + [Fact] + public void OutlineFromExportedDrawingMakesAnIrregularSheetAndCanBeRemoved() + { + var session = new NestSession(); + var input = new InputTools(session); + input.CreateDrawing("remnant", "l_shape", 60, 40); + var output = new OutputTools(session); + var file = Path.Combine(directory, "remnant.dxf"); + Assert.StartsWith("Exported drawing 'remnant'", output.ExportDrawing("remnant", file)); + new SetupTools(session).CreatePlate(10, 10); + + var result = output.SetPlateOutline(0, file); + + var plate = session.GetPlate(0)!; + Assert.True(plate.Outline != null, result); + Assert.Equal(60, System.Math.Max(plate.Size.Width, plate.Size.Length), 3); + Assert.Equal(40, System.Math.Min(plate.Size.Width, plate.Size.Length), 3); + Assert.True(plate.Outline!.Area < 60 * 40); + Assert.Contains("engine Irregular", result); + Assert.StartsWith("Error: Fill strategies need a rectangular sheet", new NestingTools(session).FillPlate(0, "remnant")); + + // The Irregular engine nests on the outline: only the L's material holds these squares. + input.CreateDrawing("small", "rectangle", 5, 5); + var nested = new NestingTools(session).AutoNestPlate(0, "small", "3", "Irregular"); + Assert.True(plate.Parts.Count == 3, nested); + plate.Parts.Clear(); + + Assert.StartsWith("Removed the outline of plate 0", output.SetPlateOutline(0)); + Assert.Null(plate.Outline); + Assert.Equal(60, System.Math.Max(plate.Size.Width, plate.Size.Length), 3); + } + + [Fact] + public void OutlineRefusesAnOccupiedPlateAndAFileWithoutAClosedContour() + { + var (session, output) = FilledSession(); + var file = Path.Combine(directory, "square.dxf"); + output.ExportDrawing("square", file); + + Assert.Contains("has parts", output.SetPlateOutline(0, file)); + Assert.Null(session.GetPlate(0)!.Outline); + + new SetupTools(session).CreatePlate(20, 20); + var empty = Path.Combine(directory, "empty.dxf"); + File.WriteAllText(empty, "not a drawing"); + Assert.StartsWith("Error", output.SetPlateOutline(1, empty)); + Assert.Null(session.GetPlate(1)!.Outline); + Assert.Equal(20, session.GetPlate(1)!.Size.Width); + } + + [Fact] + public void PostIsBlockedByVerificationWarningsUntilThisCallAcknowledgesThem() + { + var (_, output) = FilledSession(); + var posts = Path.Combine(directory, "Posts"); + Directory.CreateDirectory(posts); + File.Copy(typeof(FakePost).Assembly.Location, Path.Combine(posts, "Fake.Posts.dll")); + var cnc = Path.Combine(directory, "job.cnc"); + + Assert.Contains(FakePost.PostName, output.ListPosts(posts)); + Assert.Contains("not found", output.PostNest("No Such Post", cnc, postsDir: posts)); + Assert.StartsWith("Error: outputPath", output.PostNest(FakePost.PostName, "job.cnc", postsDir: posts)); + + // The fake post does not declare it keeps the placed order, so verification always warns. + var blocked = output.PostNest(FakePost.PostName, cnc, postsDir: posts); + Assert.Contains("Posting blocked", blocked); + Assert.False(File.Exists(cnc)); + + var posted = output.PostNest(FakePost.PostName, cnc, acknowledgeRisks: true, postsDir: posts); + Assert.Contains($"Post: {FakePost.PostName} -> {cnc}", posted); + Assert.Equal("plates=1 parts=4", File.ReadAllText(cnc)); + + // Consent is per call: the next attempt is checked again, and the file is not replaced unasked. + Assert.Contains("Posting blocked", output.PostNest(FakePost.PostName, cnc, postsDir: posts)); + Assert.Contains("already exists", output.PostNest(FakePost.PostName, cnc, acknowledgeRisks: true, postsDir: posts)); + } + + [Fact] + public void PostRefusesASessionWithNoParts() + { + var session = new NestSession(); + new SetupTools(session).CreatePlate(48, 48); + var posts = Path.Combine(directory, "Posts"); + Directory.CreateDirectory(posts); + File.Copy(typeof(FakePost).Assembly.Location, Path.Combine(posts, "Fake.Posts.dll")); + + var result = new OutputTools(session).PostNest(FakePost.PostName, Path.Combine(directory, "x.cnc"), true, postsDir: posts); + + Assert.Equal("Error: no plate has parts; nothing to post", result); + } + + [Fact] + public void SaveNestKeepsTheLoadedNestsMachineSettings() + { + var session = new NestSession + { + Nest = new Nest("job") + { + CommonLineUsage = CommonLines.CommonLineUsage.Whenever, + MinimumRemnantDimension = 7, + }, + }; + session.Nest.Drawings.Add(new Drawing("square", new CNC.Program())); + + var snapshot = session.Snapshot(null); + + Assert.Equal("job", snapshot.Name); + Assert.Equal(CommonLines.CommonLineUsage.Whenever, snapshot.CommonLineUsage); + Assert.Equal(7, snapshot.MinimumRemnantDimension); + } + + internal sealed class FakePost : IPostProcessor + { + public const string PostName = "MCP Test Post"; + + public string Name => PostName; + public string Author => "Tests"; + public string Description => "Writes plate and part counts"; + + public void Post(Nest nest, Stream outputStream) + { + using var writer = new StreamWriter(outputStream); + writer.Write($"plates={nest.Plates.Count} parts={nest.Plates.Sum(p => p.Parts.Count)}"); + } + + public void Post(Nest nest, string outputFile) + { + using var stream = File.Create(outputFile); + Post(nest, stream); + } + } +} diff --git a/OpenNest.Mcp/OpenNest.Mcp.csproj b/OpenNest.Mcp/OpenNest.Mcp.csproj index 419fa489..3ebe95f9 100644 --- a/OpenNest.Mcp/OpenNest.Mcp.csproj +++ b/OpenNest.Mcp/OpenNest.Mcp.csproj @@ -19,4 +19,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OpenNest.Mcp/Tools/OutputTools.cs b/OpenNest.Mcp/Tools/OutputTools.cs new file mode 100644 index 00000000..89c68a76 --- /dev/null +++ b/OpenNest.Mcp/Tools/OutputTools.cs @@ -0,0 +1,307 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using ModelContextProtocol.Server; +using OpenNest.Desktop; +using OpenNest.Diagnostics; +using OpenNest.IO; + +namespace OpenNest.Mcp.Tools +{ + /// + /// What leaves the session besides a .nest file: a plate or drawing as DXF or SVG, and CNC + /// output through a post processor, behind the same pre-post verification the desktop and + /// console run. Also the irregular sheet outline, which only a file can describe. + /// + [McpServerToolType] + public class OutputTools + { + private readonly NestSession _session; + + public OutputTools(NestSession session) + { + _session = session; + } + + /// Where post DLLs are looked for when a call names no directory. + internal static string DefaultPostsDirectory => Path.Combine(AppContext.BaseDirectory, "Posts"); + + [McpServerTool(Name = "set_plate_outline")] + [Description( + "Make an empty plate an irregular sheet (a remnant, a drop or a damaged sheet) from a DXF, DWG or SVG " + + "file: its largest closed contour is the sheet and closed contours inside it are areas to keep " + + "empty. The plate's size becomes the outline's bounding box. Only autonest_plate and autonest_job " + + "with engine Irregular nest on an outlined sheet. Omit path to make the plate rectangular again " + + "(it keeps the outline's bounding box as its size)." + )] + public string SetPlateOutline( + [Description("Index of the empty plate")] int plateIndex, + [Description("Absolute path to the DXF, DWG or SVG outline; omit to remove the plate's outline")] + string path = null, + [Description("How many of an SVG's units make an inch; required only when the file does not state its real-world size")] + double? svgUnitsPerInch = null + ) + { + var plate = _session.GetPlate(plateIndex); + if (plate == null) + return $"Error: plate {plateIndex} not found"; + if (plate.Parts.Count != 0) + return $"Error: plate {plateIndex} has parts; clear it first. Nothing changed."; + if (plate.CutOffs.Count != 0) + return $"Error: plate {plateIndex} has cutoff definitions. Nothing changed."; + + if (string.IsNullOrWhiteSpace(path)) + { + if (plate.Outline == null) + return $"Plate {plateIndex} is already rectangular: {plate.Size.Width:F2} x {plate.Size.Length:F2}"; + plate.Outline = null; + return $"Removed the outline of plate {plateIndex}; it is a {plate.Size.Width:F2} x {plate.Size.Length:F2} rectangle."; + } + + if (!File.Exists(path)) + return $"Error: file not found: {path}"; + + SheetOutline outline; + try + { + var import = CadImporter.Import( + path, + new CadImportOptions + { + DrawingUnits = _session.Nest?.Units ?? default, + SvgUserUnitsPerInch = svgUnitsPerInch, + } + ); + outline = SheetOutline.FromGeometry(import.Entities); + } + catch (Exception ex) + { + return $"Error: no sheet outline from '{path}': {ex.Message} Nothing changed."; + } + + plate.Outline = outline; + var work = plate.WorkArea(); + var sb = new StringBuilder(); + sb.AppendLine($"Plate {plateIndex} is now an irregular sheet: {outline}"); + sb.AppendLine($" Size (bounding box): {plate.Size.Width:F2} x {plate.Size.Length:F2}"); + sb.AppendLine($" Material area: {outline.Area:F2}"); + sb.AppendLine($" Areas to keep empty: {outline.Obstacles.Count}"); + sb.AppendLine($" Work area (bounding box): {work.Width:F2} x {work.Length:F2}"); + sb.AppendLine("Nest it with autonest_plate or autonest_job using engine Irregular."); + return sb.ToString(); + } + + [McpServerTool(Name = "export_plate")] + [Description( + "Write one plate to a file in the format its extension names: .dxf (the plate and its parts' " + + "geometry), .svg (in the nest's units) or .txt (one line per part: drawing path | X,Y | rotation). " + + "The plate is only read." + )] + public string ExportPlate( + [Description("Index of the plate to export")] int plateIndex, + [Description("Absolute path of the .dxf, .svg or .txt file to write")] string path, + [Description("For .svg only: write what laser software such as LightBurn needs (only cut and marked " + + "geometry, each kind in its own layer color)")] + bool forLaserSoftware = false, + [Description("Replace the file if it already exists")] bool overwrite = false + ) + { + var plate = _session.GetPlate(plateIndex); + if (plate == null) + return $"Error: plate {plateIndex} not found"; + + var format = PlateExport.FromPath(path); + if (format is null or PlateExportFormat.Image) + return "Error: the path must end in .dxf, .svg or .txt"; + if (forLaserSoftware) + { + if (format != PlateExportFormat.Svg) + return "Error: forLaserSoftware applies only to .svg"; + format = PlateExportFormat.SvgForLaser; + } + + if (PrepareDestination(path, overwrite) is { } refusal) + return refusal; + + try + { + PlateExport.Write(plate, _session.Nest?.Units ?? default, path, format.Value, writeImage: null); + } + catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidOperationException or NotSupportedException) + { + return $"Error: failed to write '{path}': {ex.Message}"; + } + + return $"Exported plate {plateIndex} ({plate.Parts.Count} parts) to {path}"; + } + + [McpServerTool(Name = "export_drawing")] + [Description( + "Write one drawing's cut program to a .dxf or .svg file (SVG in the nest's units). The drawing is only read." + )] + public string ExportDrawing( + [Description("Name of the drawing")] string drawing, + [Description("Absolute path of the .dxf or .svg file to write")] string path, + [Description("Replace the file if it already exists")] bool overwrite = false + ) + { + var found = _session.GetDrawing(drawing); + if (found == null) + return $"Error: drawing '{drawing}' not found"; + + var extension = Path.GetExtension(path ?? "").ToLowerInvariant(); + if (extension is not (".dxf" or ".svg")) + return "Error: the path must end in .dxf or .svg"; + + if (PrepareDestination(path, overwrite) is { } refusal) + return refusal; + + try + { + if (extension == ".svg") + Svg.ExportProgram(found.Program, path, _session.Nest?.Units ?? default); + else + Dxf.ExportProgram(found.Program, path); + } + catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidOperationException or NotSupportedException) + { + return $"Error: failed to write '{path}': {ex.Message}"; + } + + return $"Exported drawing '{found.Name}' to {path}"; + } + + [McpServerTool(Name = "list_posts")] + [Description("List the post processors post_nest can use, from the Posts folder beside this server or postsDir.")] + public string ListPosts( + [Description("Folder holding post processor DLLs (default: Posts beside this server)")] string postsDir = null + ) + { + var directory = postsDir ?? DefaultPostsDirectory; + var loaded = PostProcessorLoader.Load(directory); + + var sb = new StringBuilder(); + if (loaded.PostProcessors.Count == 0) + sb.AppendLine($"No post processors found in: {directory}"); + else + { + sb.AppendLine($"Post processors ({directory}):"); + foreach (var post in loaded.PostProcessors) + sb.AppendLine($" {post.Name}: {post.Description}"); + } + foreach (var failure in loaded.Failures) + sb.AppendLine($" Failed to load {failure}"); + return sb.ToString(); + } + + [McpServerTool(Name = "post_nest")] + [Description( + "Write CNC output (G-code) for every plate in the session through a post processor. Pre-post " + + "verification runs first, as on the desktop: with any warning nothing is written unless " + + "acknowledgeRisks is true for this call. Plan cutting (plan_cutting, apply_cutting_plan) first so " + + "parts have lead-ins and a cut order. The post uses its saved settings on this PC." + )] + public string PostNest( + [Description("Post processor name, as list_posts shows it")] string post, + [Description("Absolute path of the CNC file to write; a multi-file post derives its files from it")] + string outputPath, + [Description("Explicitly accept the verification warnings this call reports, including possible head " + + "crashes and machine or material damage, and post anyway. Applies to this call only.")] + bool acknowledgeRisks = false, + [Description("Replace output files that already exist")] bool overwrite = false, + [Description("Folder holding post processor DLLs (default: Posts beside this server)")] string postsDir = null, + CancellationToken cancellationToken = default + ) + { + if (string.IsNullOrWhiteSpace(outputPath) || !Path.IsPathFullyQualified(outputPath)) + return "Error: outputPath must be an absolute path"; + + var directory = postsDir ?? DefaultPostsDirectory; + var loaded = PostProcessorLoader.Load(directory); + var processor = loaded.PostProcessors.FirstOrDefault(p => + string.Equals(p.Name, post, StringComparison.OrdinalIgnoreCase)); + if (processor == null) + { + var available = loaded.PostProcessors.Count == 0 + ? $"No post processors found in: {directory}" + : $"Available: {string.Join(", ", loaded.PostProcessors.Select(p => p.Name))}"; + return $"Error: post processor '{post}' not found. {available}"; + } + + var nest = PostedNest(); + if (!nest.Plates.Any(p => p.Parts.Count != 0)) + return "Error: no plate has parts; nothing to post"; + + if (processor is IPostProcessorNestAware nestAware) + nestAware.PrepareForNest(nest); + + // A common line cut once needs a post that writes it; none falls back to cutting it twice. + try + { + CNC.CommonLineCuts.EnsurePostable(nest, processor); + } + catch (InvalidOperationException ex) + { + return $"Error: {ex.Message} No output was written."; + } + + // Verification runs fresh on every call; its consent never outlives this call. + var verification = PostVerificationAnalyzer.AnalyzeForPost(nest, processor, cancellationToken); + var sb = new StringBuilder(); + sb.AppendLine(verification.ToDisplayText()); + if (!verification.CanPost(acknowledgeRisks)) + { + sb.AppendLine("Posting blocked: review these warnings. No output was written. To accept the risks, " + + "including possible head crashes and machine or material damage, call post_nest again with " + + "acknowledgeRisks=true."); + return sb.ToString(); + } + + var outputs = processor is IMultiFilePostProcessor multiFile + ? multiFile.GetOutputFiles(nest, outputPath).ToList() + : new List { outputPath }; + if (!overwrite && outputs.FirstOrDefault(File.Exists) is { } existing) + return sb + $"Error: {existing} already exists. Pass overwrite=true to replace it. No output was written."; + + var dir = Path.GetDirectoryName(outputPath); + if (!string.IsNullOrEmpty(dir)) + Directory.CreateDirectory(dir); + + try + { + processor.Post(nest, outputPath); + } + catch (Exception ex) when (ex is InvalidOperationException or IOException or UnauthorizedAccessException) + { + return sb + $"Error: {processor.Name} failed: {ex.Message}"; + } + + foreach (var file in outputs) + sb.AppendLine($"Post: {processor.Name} -> {file}"); + return sb.ToString(); + } + + /// The loaded nest when it is the whole session; otherwise a nest of everything in it. + private Nest PostedNest() => + _session.Nest != null && _session.Plates.Count == 0 && _session.Drawings.Count == 0 + ? _session.Nest + : _session.Snapshot(null); + + private static string PrepareDestination(string path, bool overwrite) + { + if (string.IsNullOrWhiteSpace(path) || !Path.IsPathFullyQualified(path)) + return "Error: path must be an absolute path"; + if (!overwrite && File.Exists(path)) + return $"Error: {path} already exists. Pass overwrite=true to replace it."; + + var dir = Path.GetDirectoryName(path); + if (!string.IsNullOrEmpty(dir)) + Directory.CreateDirectory(dir); + return null; + } + } +} diff --git a/docs/irregular-stock.md b/docs/irregular-stock.md index 2758972c..2c18a4cf 100644 --- a/docs/irregular-stock.md +++ b/docs/irregular-stock.md @@ -61,7 +61,8 @@ snapshots go through the same writer and reader, so a restore rebuilds the outli rectangle to Default may well land on the rectangle: Default keeps the cheaper valid layout. - Auto Nest's stock-options grid offers rectangles only; an outlined sheet is nested through the target plate (no options), or through `NestPlateStock` directly: the console's `--outline`, - or API callers that set `NestPlateStock.Outline`. MCP has no outline input. With **Plates: + or API callers that set `NestPlateStock.Outline`. MCP's `set_plate_outline` gives an empty + plate an outline from a DXF, DWG or SVG file (or removes it), as `--outline` reads one. With **Plates: Current plates**, an empty outlined plate is offered as itself (only Irregular places on it); an outlined plate that already holds parts is skipped, since leftover fill needs a rectangle. - The stored polygon is inside the true material by up to the chord tolerance (0.001) on diff --git a/docs/post-verification.md b/docs/post-verification.md index 8503ecb1..e32c5c57 100644 --- a/docs/post-verification.md +++ b/docs/post-verification.md @@ -225,9 +225,16 @@ must pass or be acknowledged before either nest saving or CNC writing. Nest-save and CNC destinations must differ; collisions are refused even with acknowledgment. Without `--post`, ordinary nest saving is unchanged; `--no-save` skips that save. +MCP's `post_nest` runs the same gate on every call: `PrepareForNest` (as the desktop does), +the common-line check, then `AnalyzeForPost`. With any finding it writes nothing unless that +call passes `acknowledgeRisks=true`; the next call is checked again. It refuses to replace an +existing output file unless asked (`overwrite=true`). Posts load from `Posts/` beside the +server (the build and publish copy the shipped posts there) or a `postsDir` argument, and use +their saved settings on that PC; there is no configuration dialog. + The raw `IPostProcessor` plugin interface remains a low-level writer. Third-party callers must apply their own review/consent flow using `PostVerificationAnalyzer`; -the gate is installed at OpenNest's desktop and console posting entry points. +the gate is installed at OpenNest's desktop, console and MCP posting entry points. ## Selected post and cut order diff --git a/docs/svg-import-export.md b/docs/svg-import-export.md index 83284b4e..3a56a4fc 100644 --- a/docs/svg-import-export.md +++ b/docs/svg-import-export.md @@ -34,7 +34,7 @@ Import takes path centerlines: `path`, `rect` (with rounded corners), `circle`, ## What export writes -`ExportProgram`, `ExportPlate` and `ExportEntities` write one `` per layer; the `ExportEntities` overload that takes bends adds a `BEND` group with each bend's `line` and `data-bend-*` attributes, plus its note as text for people. `width` and `height` are in the given units and match the `viewBox`, so one user unit is one drawing unit and the file needs no scale prompt. Arcs stay `A` commands. The plate outline and edge spacing go on `PLATE`. Plate export leaves out the rapids DXF draws between parts. +`ExportProgram`, `ExportPlate` and `ExportEntities` write one `` per layer; the `ExportEntities` overload that takes bends adds a `BEND` group with each bend's `line` and `data-bend-*` attributes, plus its note as text for people. `width` and `height` are in the given units and match the `viewBox`, so one user unit is one drawing unit and the file needs no scale prompt. Arcs stay `A` commands. The plate outline and edge spacing go on `PLATE`. Plate export leaves out the rapids DXF draws between parts. MCP's `export_plate` and `export_drawing` write the same files (`export_plate` takes `forLaserSoftware` for the laser-software SVG below). ### For laser software