Quickstart

This page builds a complete plugin that imports and exports CSV source data and saves one optimization result sheet as PLT. It is the same design as the SDK's CSV starter: the Delphi and C++ tabs implement the full ITcPlugin contract against the SDK headers.

You need:

  • Delphi: the units from SDK/include/pascal and the CSV helper unit SDK/examples/delphi/CsvImportExport/uCsvCommon.pas.
  • C++ (MSVC or C++Builder): SDK/include/cpp/TonCutPluginSdk.hpp, the CSV helpers SDK/examples/shared/cpp/CsvCodec.hpp and CsvCodec.cpp, and SDK/examples/shared/cpp/StarterPlotterInfo.hpp.
  • A 32-bit (Win32) target. Read ABI & Marshalling before you write your own interop code.

C# is not covered here: a C# plugin is a C++ plugin like this one (a native shim) that hands file parsing to managed code. See C# plugins.

Plugin shape

The plugin is one class implementing ITcPlugin. In Delphi, TInterfacedObject supplies IUnknown; in C++ the class implements QueryInterface, AddRef, and Release itself and is destroyed only by Release.

Plugin class declaration

unit uCsvImportExportPlugin;

interface

uses
  Winapi.Windows,
  System.SysUtils,
  System.Classes,
  System.IOUtils,
  uICommon,
  uITcPluginCommon,
  uITcPlotterInfo,
  uITcEnumExtensionsCallback,
  uITonCut,
  uITcPlugin,
  uIDevice,
  uIDevices,
  uIMaterial,
  uIMaterials,
  uIBands,
  uIProject,
  uIProjects,
  uIFormat,
  uIFormats,
  uISheet,
  uISheets,
  uISolution,
  uISolutionSheet,
  uISolutionCut,
  uISolutionCuts,
  uCsvCommon;

type
  TCsvImportExportPlugin = class(TInterfacedObject, ITcPlugin)
  private
    FRegRoot: WideString;
    FLanguageId: Integer;
    FUiScale: Single;
    FTonCut: ITonCut;

    function ValidateHeader(const aFileName: WideString): TTcpResult;

    function GetEngineVersion(): Integer; safecall;
    function GetName(): WideString; safecall;
    function GetVersion(): TTcpVersion; safecall;
    function GetTitle(): WideString; safecall;
    function GetProfessional(): Boolean; safecall;
    function GetRegRoot(): WideString; safecall;
    function GetLanguageId(): Integer; safecall;
    procedure SetLanguageId(aLanguageId: Integer); safecall;
    function GetUiScale(): Single; safecall;
    procedure SetUiScale(aScale: Single); safecall;
    function GetTonCut(): ITonCut; safecall;
    function GetFeatures(): TTcpFeatures; safecall;
    function GetPlotterInfo(): ITcPlotterInfo; safecall;
  public
    function Initialize(const aRegRoot: WideString; aLanguageId: Integer; aTonCut: ITonCut): TTcpResult; safecall;
    function Finalize(): TTcpResult; safecall;

    function Configure(aWindow: THandle): TTcpResult; safecall;
    function About(aWindow: THandle): TTcpResult; safecall;

    function LoadConfig(const aKey, aVersion: WideString): TTcpResult; safecall;
    function SaveConfig(const aKey: WideString): TTcpResult; safecall;
    function BackupConfig(var aBackup: WideString): TTcpResult; safecall;
    function RestoreConfig(const aBackup: WideString; aScope: TConfigurationParts): TTcpResult; safecall;

    function EnumExtensions(aType: TTcpExtensionType; aEnumCb: ITcEnumExtensionsCallback): TTcpResult; safecall;
    function IsMyFile(const aFileName: WideString): TTcpResult; safecall;

    function LoadFile(aWindow: THandle; const aFileName: WideString; aDevices: IDevices; aMaterials: IMaterials; aBands: IBands; aProjects: IProjects; aFormats: IFormats; aSheets: ISheets): TTcpResult; safecall;
    function SaveFile(aWindow: THandle; const aFileName: WideString; const aFormats: IFormats; const aSheets: ISheets): TTcpResult; safecall;

    function SaveResult(aWindow: THandle; const aFileName: WideString; const aSolutionSheet: ISolutionSheet): TTcpResult; safecall;
    function BatchSaveResult(aWindow: THandle; aSaveTarget: TTcpSaveTarget; const aPath: WideString; const aSolution: ISolution): TTcpResult; safecall;
    function Plot(aWindow: THandle; const aSolutionSheet: ISolutionSheet): TTcpResult; safecall;
    function BatchPlot(aWindow: THandle; const aSolution: ISolution): TTcpResult; safecall;
    function SavePlot(aWindow: THandle; const aFileName: WideString; const aSolutionSheet: ISolutionSheet): TTcpResult; safecall;
    function BatchSavePlot(aWindow: THandle; aSaveTarget: TTcpSaveTarget; const aPath: WideString; const aSolution: ISolution): TTcpResult; safecall;
  end;

implementation

The Pascal method declarations must match the interface's parameter types exactly. In C++ the vtable order is fixed by TonCutPluginSdk.hpp; your class overrides every method, and the order of the declarations in your class does not matter. All C++ method bodies below are defined inside namespace toncut.

Project and entry point

TonCut loads the .plg, resolves TcpInitializeV2, and never calls Initialize itself. The entry point creates the plugin, initializes it, and returns it, or returns nil (reported as a plugin load error).

Project file and TcpInitializeV2

library CsvImportExport;

{$E plg}   // TonCut loads *.plg
{$A8}      // record alignment of the interface units

uses
  System.SysUtils,
  uITcPluginCommon,
  uITonCut,
  uITcPlugin,
  uCsvCommon in 'uCsvCommon.pas',
  uCsvImportExportPlugin in 'uCsvImportExportPlugin.pas';

function TcpInitializeV2(
  const aRegRoot: PChar;
  aLanguageId: Integer;
  aTonCut: ITonCut
): ITcPlugin; stdcall;
var
  plugin: ITcPlugin;
begin
  Result := nil;
  try
    plugin := TCsvImportExportPlugin.Create;
    if plugin.Initialize(aRegRoot, aLanguageId, aTonCut) = cprOK then
      Result := plugin;
  except
    Result := nil;
  end;
end;

exports
  TcpInitializeV2;

begin
end.

For MSVC, add a module definition file so the export is named TcpInitializeV2 instead of _TcpInitializeV2@16, and set the project up as follows:

; CsvImportExport.def  (Linker > Input > Module Definition File)
LIBRARY "CsvImportExport.plg"
EXPORTS
  TcpInitializeV2
  1. Configuration type Dynamic Library, platform Win32, target extension .plg.
  2. Add CsvCodec.cpp to the project; add SDK/include/cpp and SDK/examples/shared/cpp to the include path.
  3. Build, then check dumpbin /exports CsvImportExport.plg lists TcpInitializeV2.
  4. Copy the .plg into the Plugins folder next to TonCut.exe and restart TonCut.

For Delphi, set the target platform to Windows 32-bit and copy the .plg the same way. The full checklist is on ABI & Marshalling.

Metadata and lifecycle

Name must be unique among installed plugins and plain ASCII; it never changes between releases. EngineVersion returns the SDK constant; TonCut accepts only an exact match. Initialize caches the host state, and Finalize releases it.

Metadata and lifecycle methods

function TCsvImportExportPlugin.GetEngineVersion(): Integer;
begin
  Result := cEngineVersion;
end;

function TCsvImportExportPlugin.GetName(): WideString;
begin
  Result := 'CsvImportExportStarter'; // unique, ASCII, never changes
end;

function TCsvImportExportPlugin.GetVersion(): TTcpVersion;
begin
  Result := MakeTcpVersion(1, 0, 0, 0); // from uCsvCommon; shown as 1.0.0.0
end;

function TCsvImportExportPlugin.GetTitle(): WideString;
begin
  Result := 'CSV Import/Export + PLT Starter';
end;

function TCsvImportExportPlugin.GetProfessional(): Boolean;
begin
  Result := False;
end;

function TCsvImportExportPlugin.GetRegRoot(): WideString;
begin
  Result := FRegRoot;
end;

function TCsvImportExportPlugin.GetLanguageId(): Integer;
begin
  Result := FLanguageId;
end;

procedure TCsvImportExportPlugin.SetLanguageId(aLanguageId: Integer);
begin
  FLanguageId := aLanguageId;
end;

function TCsvImportExportPlugin.GetUiScale(): Single;
begin
  Result := FUiScale;
end;

procedure TCsvImportExportPlugin.SetUiScale(aScale: Single);
begin
  FUiScale := aScale;
end;

function TCsvImportExportPlugin.GetTonCut(): ITonCut;
begin
  Result := FTonCut;
end;

function TCsvImportExportPlugin.GetFeatures(): TTcpFeatures;
begin
  Result := [feImport, feExport, feSaveResultToFile, feAbout];
end;

function TCsvImportExportPlugin.Initialize(const aRegRoot: WideString;
  aLanguageId: Integer; aTonCut: ITonCut): TTcpResult;
begin
  FRegRoot := aRegRoot;
  FLanguageId := aLanguageId;
  FUiScale := 1.0;
  FTonCut := aTonCut;
  Result := cprOK;
end;

function TCsvImportExportPlugin.Finalize(): TTcpResult;
begin
  FTonCut := nil; // release every host object before TonCut unloads the DLL
  Result := cprOK;
end;

The plugin advertises because it implements About; TonCut calls Configure and About only when the matching flag is set. The configuration callbacks are safe no-ops here, and their results are ignored by TonCut.

Configuration and About

function TCsvImportExportPlugin.Configure(aWindow: THandle): TTcpResult;
begin
  Result := cprNotImplemented; // feConfigure is not advertised
end;

function TCsvImportExportPlugin.About(aWindow: THandle): TTcpResult;
begin
  try
    MessageBoxW(aWindow, 'CSV import/export and single-sheet PLT result export.',
      PWideChar(GetTitle()), MB_OK or MB_ICONINFORMATION);
    Result := cprOK;
  except
    Result := cprFailed;
  end;
end;

function TCsvImportExportPlugin.LoadConfig(const aKey, aVersion: WideString): TTcpResult;
begin
  Result := cprOK;
end;

function TCsvImportExportPlugin.SaveConfig(const aKey: WideString): TTcpResult;
begin
  Result := cprOK;
end;

function TCsvImportExportPlugin.BackupConfig(var aBackup: WideString): TTcpResult;
begin
  aBackup := '';
  Result := cprOK;
end;

function TCsvImportExportPlugin.RestoreConfig(const aBackup: WideString;
  aScope: TConfigurationParts): TTcpResult;
begin
  Result := cprOK;
end;

File registration and detection

EnumExtensions registers .csv for import and export and .plt for result export; each extension includes its leading dot. IsMyFile returns only when the extension and the header row match, and otherwise.

EnumExtensions and IsMyFile

function TCsvImportExportPlugin.EnumExtensions(aType: TTcpExtensionType;
  aEnumCb: ITcEnumExtensionsCallback): TTcpResult;
begin
  case aType of
    etImport, etExport:
      aEnumCb.Invoke(aType, '.csv', 'CSV source data');
    etExportResults:
      aEnumCb.Invoke(aType, '.plt', 'HP-GL / PLT cutting paths');
  end;
  Result := cprOK;
end;

function TCsvImportExportPlugin.ValidateHeader(const aFileName: WideString): TTcpResult;
var
  table: TCsvTable;
begin
  Result := cprNo;
  if not SameText(ExtractFileExt(aFileName), '.csv') or not FileExists(aFileName) then
    Exit;
  table := ParseCsvText(TFile.ReadAllText(aFileName, TEncoding.UTF8));
  if (Length(table) > 0) and HasRequiredHeader(table[0]) then
    Result := cprOK;
end;

function TCsvImportExportPlugin.IsMyFile(const aFileName: WideString): TTcpResult;
begin
  try
    Result := ValidateHeader(aFileName);
  except
    Result := cprNo;
  end;
end;

Source data round-trip

The CSV file stores millimeters and uses the material kinds mk1D, mk2D, and mkUnknown (SDK/manuals/csv-schema.md). Inside TonCut every length is in hundredths of a millimeter, so the plugin multiplies by cLengthMultiplier on import and divides by it on export.

LoadFile receives empty staging collections. It creates each object with the collection's own CreateX method (no dialog), sets its properties, including Device for every new material, and calls Add; TonCut's Import dialog then merges the result. Never use the dialog-based ITonCut.CreateMaterial, CreateProject, or CreateBand here. Copy the complete method and its helpers from these pages; they use the class and field names declared above:

Plotter info

A plugin that advertises any result or plot save flag must return a valid ITcPlotterInfo from GetPlotterInfo; TonCut copies it, and a nil result disables the plugin. The plugin implements the interface itself. The values below are the same defaults TonCut uses for a device that has no driver plugin.

In the Save results dialog, AxisX, AxisY, DefaultRotation, and DefaultMirror of this object define, on top of the device's own transformation, the frame in which SolutionCuts and CalcPoint report coordinates to your plugin. Changing them later rotates or mirrors every file the plugin writes; see Coordinate frames.

GetPlotterInfo

type
  TStarterPlotterInfo = class(TInterfacedObject, ITcPlotterInfo)
  private
    FPlotterType: TTcPlotterType;
    FMaterialKinds: TMaterialKinds;
    FAxisX, FAxisY: TTcAxisDirection;
    FSizeX, FSizeY: Cardinal;
    FCanCrossCuts, FFullCutsOnly, FCanCutAnyShapes: Boolean;
    FStripCuts: TStripCutting;
    FMaxStripeWidth: Integer;
    FCutsDepthOn: Boolean;
    FCutsDepth: Cardinal;
    FCutsDepthIncMargins, FTwoDimensionMoves: Boolean;
    FPrefferedDirection, FBridgeMoveDirection: TTcMoveDirection;
    FMarginWest, FMarginNorth, FMarginEast, FMarginSouth: Cardinal;
    FBridgeSize, FHeadSize, FHeadKnifeSpace: Cardinal;
    FDefaultRotation: Integer;
    FDefaultMirror: TMirrors;
  protected
    function GetPlotterType(): TTcPlotterType; safecall;
    procedure SetPlotterType(aValue: TTcPlotterType); safecall;
    function GetMaterialKinds(): TMaterialKinds; safecall;
    procedure SetMaterialKinds(aValue: TMaterialKinds); safecall;
    function GetAxisX(): TTcAxisDirection; safecall;
    procedure SetAxisX(aValue: TTcAxisDirection); safecall;
    function GetAxisY(): TTcAxisDirection; safecall;
    procedure SetAxisY(aValue: TTcAxisDirection); safecall;
    function GetSizeX(): Cardinal; safecall;
    procedure SetSizeX(aValue: Cardinal); safecall;
    function GetSizeY(): Cardinal; safecall;
    procedure SetSizeY(aValue: Cardinal); safecall;
    function GetCanCrossCuts(): Boolean; safecall;
    procedure SetCanCrossCuts(aValue: Boolean); safecall;
    function GetFullCutsOnly(): Boolean; safecall;
    procedure SetFullCutsOnly(aValue: Boolean); safecall;
    function GetCanCutAnyShapes(): Boolean; safecall;
    procedure SetCanCutAnyShapes(aValue: Boolean); safecall;
    function GetStripCuts(): TStripCutting; safecall;
    procedure SetStripCuts(aValue: TStripCutting); safecall;
    function GetMaxStripeWidth(): Integer; safecall;
    procedure SetMaxStripeWidth(aValue: Integer); safecall;
    function GetCutsDepthOn(): Boolean; safecall;
    procedure SetCutsDepthOn(aValue: Boolean); safecall;
    function GetCutsDepth(): Cardinal; safecall;
    procedure SetCutsDepth(aValue: Cardinal); safecall;
    function GetCutsDepthIncMargins(): Boolean; safecall;
    procedure SetCutsDepthIncMargins(aValue: Boolean); safecall;
    function GetTwoDimensionMoves(): Boolean; safecall;
    procedure SetTwoDimensionMoves(aValue: Boolean); safecall;
    function GetPrefferedDirection(): TTcMoveDirection; safecall;
    procedure SetPrefferedDirection(aValue: TTcMoveDirection); safecall;
    function GetMarginWest(): Cardinal; safecall;
    procedure SetMarginWest(aValue: Cardinal); safecall;
    function GetMarginNorth(): Cardinal; safecall;
    procedure SetMarginNorth(aValue: Cardinal); safecall;
    function GetMarginEast(): Cardinal; safecall;
    procedure SetMarginEast(aValue: Cardinal); safecall;
    function GetMarginSouth(): Cardinal; safecall;
    procedure SetMarginSouth(aValue: Cardinal); safecall;
    function GetBridgeMoveDirection(): TTcMoveDirection; safecall;
    procedure SetBridgeMoveDirection(aValue: TTcMoveDirection); safecall;
    function GetBridgeSize(): Cardinal; safecall;
    procedure SetBridgeSize(aValue: Cardinal); safecall;
    function GetHeadSize(): Cardinal; safecall;
    procedure SetHeadSize(aValue: Cardinal); safecall;
    function GetHeadKnifeSpace(): Cardinal; safecall;
    procedure SetHeadKnifeSpace(aValue: Cardinal); safecall;
    function GetDefaultRotation(): Integer; safecall;
    procedure SetDefaultRotation(aValue: Integer); safecall;
    function GetDefaultMirror(): TMirrors; safecall;
    procedure SetDefaultMirror(aValue: TMirrors); safecall;
    procedure Assign(const aOther: ITcPlotterInfo); safecall;
  public
    constructor Create;
  end;

constructor TStarterPlotterInfo.Create;
begin
  inherited Create;
  FPlotterType := ptUnknown;
  FMaterialKinds := [mk1D, mk2D]; // Save results disables pages of other kinds
  FAxisX := adEast;
  FAxisY := adSouth;
  FSizeX := 133;
  FSizeY := 100;
  FCanCrossCuts := False;
  FFullCutsOnly := True;
  FCanCutAnyShapes := True;
  FStripCuts := scNone;
  FMaxStripeWidth := 1200 * cLengthMultiplier;
  FCutsDepthOn := False;
  FCutsDepth := 0;
  FCutsDepthIncMargins := False;
  FTwoDimensionMoves := True;
  FPrefferedDirection := mdAny;
  FMarginWest := 5;
  FMarginNorth := 5;
  FMarginEast := 5;
  FMarginSouth := 5;
  FBridgeMoveDirection := mdAlongX;
  FBridgeSize := 10;
  FHeadSize := 10;
  FHeadKnifeSpace := 5;
  FDefaultRotation := 0;
  FDefaultMirror := [];
end;

function TStarterPlotterInfo.GetPlotterType: TTcPlotterType; begin Result := FPlotterType; end;
procedure TStarterPlotterInfo.SetPlotterType(aValue: TTcPlotterType); begin FPlotterType := aValue; end;
function TStarterPlotterInfo.GetMaterialKinds: TMaterialKinds; begin Result := FMaterialKinds; end;
procedure TStarterPlotterInfo.SetMaterialKinds(aValue: TMaterialKinds); begin FMaterialKinds := aValue; end;
function TStarterPlotterInfo.GetAxisX: TTcAxisDirection; begin Result := FAxisX; end;
procedure TStarterPlotterInfo.SetAxisX(aValue: TTcAxisDirection); begin FAxisX := aValue; end;
function TStarterPlotterInfo.GetAxisY: TTcAxisDirection; begin Result := FAxisY; end;
procedure TStarterPlotterInfo.SetAxisY(aValue: TTcAxisDirection); begin FAxisY := aValue; end;
function TStarterPlotterInfo.GetSizeX: Cardinal; begin Result := FSizeX; end;
procedure TStarterPlotterInfo.SetSizeX(aValue: Cardinal); begin FSizeX := aValue; end;
function TStarterPlotterInfo.GetSizeY: Cardinal; begin Result := FSizeY; end;
procedure TStarterPlotterInfo.SetSizeY(aValue: Cardinal); begin FSizeY := aValue; end;
function TStarterPlotterInfo.GetCanCrossCuts: Boolean; begin Result := FCanCrossCuts; end;
procedure TStarterPlotterInfo.SetCanCrossCuts(aValue: Boolean); begin FCanCrossCuts := aValue; end;
function TStarterPlotterInfo.GetFullCutsOnly: Boolean; begin Result := FFullCutsOnly; end;
procedure TStarterPlotterInfo.SetFullCutsOnly(aValue: Boolean); begin FFullCutsOnly := aValue; end;
function TStarterPlotterInfo.GetCanCutAnyShapes: Boolean; begin Result := FCanCutAnyShapes; end;
procedure TStarterPlotterInfo.SetCanCutAnyShapes(aValue: Boolean); begin FCanCutAnyShapes := aValue; end;
function TStarterPlotterInfo.GetStripCuts: TStripCutting; begin Result := FStripCuts; end;
procedure TStarterPlotterInfo.SetStripCuts(aValue: TStripCutting); begin FStripCuts := aValue; end;
function TStarterPlotterInfo.GetMaxStripeWidth: Integer; begin Result := FMaxStripeWidth; end;
procedure TStarterPlotterInfo.SetMaxStripeWidth(aValue: Integer); begin FMaxStripeWidth := aValue; end;
function TStarterPlotterInfo.GetCutsDepthOn: Boolean; begin Result := FCutsDepthOn; end;
procedure TStarterPlotterInfo.SetCutsDepthOn(aValue: Boolean); begin FCutsDepthOn := aValue; end;
function TStarterPlotterInfo.GetCutsDepth: Cardinal; begin Result := FCutsDepth; end;
procedure TStarterPlotterInfo.SetCutsDepth(aValue: Cardinal); begin FCutsDepth := aValue; end;
function TStarterPlotterInfo.GetCutsDepthIncMargins: Boolean; begin Result := FCutsDepthIncMargins; end;
procedure TStarterPlotterInfo.SetCutsDepthIncMargins(aValue: Boolean); begin FCutsDepthIncMargins := aValue; end;
function TStarterPlotterInfo.GetTwoDimensionMoves: Boolean; begin Result := FTwoDimensionMoves; end;
procedure TStarterPlotterInfo.SetTwoDimensionMoves(aValue: Boolean); begin FTwoDimensionMoves := aValue; end;
function TStarterPlotterInfo.GetPrefferedDirection: TTcMoveDirection; begin Result := FPrefferedDirection; end;
procedure TStarterPlotterInfo.SetPrefferedDirection(aValue: TTcMoveDirection); begin FPrefferedDirection := aValue; end;
function TStarterPlotterInfo.GetMarginWest: Cardinal; begin Result := FMarginWest; end;
procedure TStarterPlotterInfo.SetMarginWest(aValue: Cardinal); begin FMarginWest := aValue; end;
function TStarterPlotterInfo.GetMarginNorth: Cardinal; begin Result := FMarginNorth; end;
procedure TStarterPlotterInfo.SetMarginNorth(aValue: Cardinal); begin FMarginNorth := aValue; end;
function TStarterPlotterInfo.GetMarginEast: Cardinal; begin Result := FMarginEast; end;
procedure TStarterPlotterInfo.SetMarginEast(aValue: Cardinal); begin FMarginEast := aValue; end;
function TStarterPlotterInfo.GetMarginSouth: Cardinal; begin Result := FMarginSouth; end;
procedure TStarterPlotterInfo.SetMarginSouth(aValue: Cardinal); begin FMarginSouth := aValue; end;
function TStarterPlotterInfo.GetBridgeMoveDirection: TTcMoveDirection; begin Result := FBridgeMoveDirection; end;
procedure TStarterPlotterInfo.SetBridgeMoveDirection(aValue: TTcMoveDirection); begin FBridgeMoveDirection := aValue; end;
function TStarterPlotterInfo.GetBridgeSize: Cardinal; begin Result := FBridgeSize; end;
procedure TStarterPlotterInfo.SetBridgeSize(aValue: Cardinal); begin FBridgeSize := aValue; end;
function TStarterPlotterInfo.GetHeadSize: Cardinal; begin Result := FHeadSize; end;
procedure TStarterPlotterInfo.SetHeadSize(aValue: Cardinal); begin FHeadSize := aValue; end;
function TStarterPlotterInfo.GetHeadKnifeSpace: Cardinal; begin Result := FHeadKnifeSpace; end;
procedure TStarterPlotterInfo.SetHeadKnifeSpace(aValue: Cardinal); begin FHeadKnifeSpace := aValue; end;
function TStarterPlotterInfo.GetDefaultRotation: Integer; begin Result := FDefaultRotation; end;
procedure TStarterPlotterInfo.SetDefaultRotation(aValue: Integer); begin FDefaultRotation := aValue; end;
function TStarterPlotterInfo.GetDefaultMirror: TMirrors; begin Result := FDefaultMirror; end;
procedure TStarterPlotterInfo.SetDefaultMirror(aValue: TMirrors); begin FDefaultMirror := aValue; end;

procedure TStarterPlotterInfo.Assign(const aOther: ITcPlotterInfo);
begin
  FPlotterType := aOther.PlotterType;
  FMaterialKinds := aOther.MaterialKinds;
  FAxisX := aOther.AxisX;
  FAxisY := aOther.AxisY;
  FSizeX := aOther.SizeX;
  FSizeY := aOther.SizeY;
  FCanCrossCuts := aOther.CanCrossCuts;
  FFullCutsOnly := aOther.FullCutsOnly;
  FCanCutAnyShapes := aOther.CanCutAnyShapes;
  FStripCuts := aOther.StripCuts;
  FMaxStripeWidth := aOther.MaxStripeWidth;
  FCutsDepthOn := aOther.CutsDepthOn;
  FCutsDepth := aOther.CutsDepth;
  FCutsDepthIncMargins := aOther.CutsDepthIncMargins;
  FTwoDimensionMoves := aOther.TwoDimensionMoves;
  FPrefferedDirection := aOther.PrefferedDirection;
  FMarginWest := aOther.MarginWest;
  FMarginNorth := aOther.MarginNorth;
  FMarginEast := aOther.MarginEast;
  FMarginSouth := aOther.MarginSouth;
  FBridgeMoveDirection := aOther.BridgeMoveDirection;
  FBridgeSize := aOther.BridgeSize;
  FHeadSize := aOther.HeadSize;
  FHeadKnifeSpace := aOther.HeadKnifeSpace;
  FDefaultRotation := aOther.DefaultRotation;
  FDefaultMirror := aOther.DefaultMirror;
end;

function TCsvImportExportPlugin.GetPlotterInfo(): ITcPlotterInfo;
begin
  Result := TStarterPlotterInfo.Create; // never nil while a save flag is set
end;

A new object is returned on every call; TonCut releases it after copying. Every object the plugin hands out must be released before TonCut unloads the DLL.

Result export

SaveResult receives one ISolutionSheet. The cuts in SolutionCuts are already in the output frame, so the PLT writer only scales them: 0.4 HPGL units per TonCut unit (40 units per millimeter divided by cLengthMultiplier). Never pass the cuts through CalcPoint or CalcPointF. Copy ExportSolutionSheetAsPlt from Export, Result & Plot > PLT output.

TonCut is silent when SaveResult does not return , so the plugin shows its own error. It sets IsSaved on success.

SaveResult

function TCsvImportExportPlugin.SaveResult(aWindow: THandle; const aFileName: WideString;
  const aSolutionSheet: ISolutionSheet): TTcpResult;
var
  commands: TStringList;
begin
  Result := cprFailed;
  try
    commands := TStringList.Create;
    try
      if ExportSolutionSheetAsPlt(aSolutionSheet, commands) then
      begin
        commands.SaveToFile(aFileName, TEncoding.ASCII);
        aSolutionSheet.IsSaved := True;
        Result := cprOK;
      end
      else
        MessageBoxW(aWindow, 'The PLT file could not be written.', 'PLT export',
          MB_OK or MB_ICONERROR);
    finally
      commands.Free;
    end;
  except
    on E: Exception do
      MessageBoxW(aWindow, PWideChar(E.Message), 'PLT export', MB_OK or MB_ICONERROR);
  end;
end;

Unused callbacks

The remaining callbacks are not reachable, because no matching flag is advertised, but every vtable slot must still be implemented.

Callbacks without a feature flag

function TCsvImportExportPlugin.BatchSaveResult(aWindow: THandle;
  aSaveTarget: TTcpSaveTarget; const aPath: WideString; const aSolution: ISolution): TTcpResult;
begin
  Result := cprNotImplemented;
end;

function TCsvImportExportPlugin.Plot(aWindow: THandle;
  const aSolutionSheet: ISolutionSheet): TTcpResult;
begin
  Result := cprNotImplemented;
end;

function TCsvImportExportPlugin.BatchPlot(aWindow: THandle;
  const aSolution: ISolution): TTcpResult;
begin
  Result := cprNotImplemented;
end;

function TCsvImportExportPlugin.SavePlot(aWindow: THandle; const aFileName: WideString;
  const aSolutionSheet: ISolutionSheet): TTcpResult;
begin
  Result := cprNotImplemented;
end;

function TCsvImportExportPlugin.BatchSavePlot(aWindow: THandle;
  aSaveTarget: TTcpSaveTarget; const aPath: WideString; const aSolution: ISolution): TTcpResult;
begin
  Result := cprNotImplemented;
end;

end.

The ready-to-open SDK projects are listed on the SDK page.

Was this page helpful?