Export, Result & Plot
TonCut Desktop supports three related but distinct output paths: exporting input data with SaveFile, saving optimization results, and driving plot-oriented workflows. The SDK examples start with one combined starter plugin that implements , , and . It round-trips source data through CSV and exports one solution sheet to .plt through SaveResult.
Export surfaces
Use the callback that matches the host action:
| Callback | Primary input |
|---|---|
SaveFile | IFormats and ISheets |
SaveResult | One ISolutionSheet |
BatchSaveResult | Entire ISolution |
Plot / BatchPlot | ISolutionSheet or ISolution |
SavePlot / BatchSavePlot | ISolutionSheet or ISolution plus file or folder target |
The shipped starter implements SaveFile and a minimal single-sheet SaveResult path. BatchSaveResult, Plot, BatchPlot, SavePlot, and BatchSavePlot still return .
CSV exporter pattern
The combined starter writes the same schema that the import side expects:
RecordType,ProjectTitle,MaterialTitle,MaterialKind,MaterialWidth,MaterialThickness,Length,Width,Quantity,Identifier,Description
In practice, the export flow is:
- Enumerate all IFormat items and write
FORMATrows. - Enumerate all ISheet items and write
SHEETrows. - Preserve the same material values needed for round-trip import.
- Save the file as UTF-8 with BOM and CRLF line endings.
SaveFile stays input-side: it knows about source projects, materials, pieces, and stock sheets. It does not know about solution placement. If you need placed coordinates, cuts, or waste, switch to result callbacks and start from ISolutionSheet or ISolution instead.
SaveFile
for i := 0 to aFormats.Count - 1 do
begin
format := aFormats[i];
if format.Material <> nil then
begin
lines.Add(BuildCsvLine([
'FORMAT',
format.Project.Title,
format.Material.Title,
MaterialKindToText(format.Material.Kind),
IntToStr(format.Material.Width),
IntToStr(format.Material.Thickness),
IntToStr(format.Length),
IntToStr(format.Width),
IntToStr(format.Quantity),
format.Identifier,
format.Description
]));
end;
end;
for i := 0 to aSheets.Count - 1 do
begin
sheet := aSheets[i];
if sheet.Material <> nil then
lines.Add(BuildCsvLine([
'SHEET', '', sheet.Material.Title,
MaterialKindToText(sheet.Material.Kind),
IntToStr(sheet.Material.Width),
IntToStr(sheet.Material.Thickness),
IntToStr(sheet.Length),
IntToStr(sheet.Width),
IntToStr(sheet.Quantity),
sheet.Identifier,
sheet.Description
]));
end;
Short helper patterns still fit inline between paragraphs:
Write the final UTF-8 file
TFile.WriteAllText(aFileName, lines.Text, TEncoding.UTF8);
Result := cprOK;
For the split C# starter, native C++ enumerates the TonCut objects and marshals plain CsvRowRecord values across the project-specific bridge. The managed library only encodes those records; it does not receive IFormats or ISheets directly.
Result and plot surfaces
The starter already crosses into result export, but it stays deliberately narrow:
SaveResultandBatchSaveResultoperate on ISolutionSheet and ISolution.Plot,SavePlot, and their batch variants usually need ITcPlotterInfo. If a deviceDrivermatches the pluginName, TonCut can apply the plugin's plotter info as the source of plugin-controlled device constraints.- Output geometry should use helpers such as
CalcEffectiveLayout,CalcPointF, andGetDirectionfrom ISolutionSheet.
Starter SaveResult as PLT
function TCsvImportExportPlugin.SaveResult(
aWindow: THandle;
const aFileName: WideString;
const aSolutionSheet: ISolutionSheet
): TTcpResult;
var
commands: TStringList;
begin
commands := TStringList.Create;
try
if not ExportSolutionSheetAsPlt(aSolutionSheet, commands) then
Exit(cprFailed);
commands.SaveToFile(aFileName, TEncoding.ASCII);
if aSolutionSheet <> nil then
aSolutionSheet.IsSaved := True;
Result := cprOK;
finally
commands.Free;
end;
end;
The shipped C# managed library has no solution interface or PLT writer. Its native shim owns SaveResult, the solution ABI, coordinate transforms, and the PLT output path.
The transform itself happens before those final writes: call CalcEffectiveLayout, iterate SolutionCuts, map every endpoint and Bezier control point through CalcPointF, then emit PU, PD, and BZ commands in plotter units.
When you move past the starter, keep SaveFile exporters separate from broader result or plot workflows in your design. The shipped example covers only a single-sheet PLT save path so the ABI and geometry basics stay easy to inspect first.