How to convert data to Gerber274x

This example shows how to convert a loaded job in PCB-Investigator or an ODB++ job in an known directory can be converted to gerber files. Its easy to change the code to make an automated converter for ODB++, CenCad 1.4, IPC2581 or some other file formats.

  {
    /// <summary>
    /// Select the outputdirectory and save all layer as gerberfiles.
    /// </summary>
    /// <param name="window">The main PCB-Investigator window.</param>
    public void SaveJobAsGerber(IPCBIWindow window)
    {
      FolderBrowserDialog dirDLG = new FolderBrowserDialog();
      //select the output directory
      dirDLG.Description = "Select directroy for layerfiles as gerber274x.";
      if (dirDLG.ShowDialog() != DialogResult.OK)
        return;
 
      //here is possible to select your own directories
      ConvertODBToGerber(window.GetODBJobDirectory(), dirDLG.SelectedPath, window);
    }
    /// <summary>
    /// Converts all layers (without the component layers) to gerber files and save it in one directory.
    /// </summary>
    /// <param name="JobPath">The job who should be loaded.</param>
    /// <param name="GerberDirectory">Output directory for the new files.</param>
    /// <param name="window">PCB-Investigator to convert the files.</param>
    public void ConvertODBToGerber(string JobPath, string GerberDirectory, IPCBIWindow window)
    {
      //check is a job loaded, if not load an job!
      if (!window.JobIsLoaded && !window.LoadODBJob(JobPath))
        return;
 
      IStep stepCurrent = window.GetCurrentStep();
 
      if (stepCurrent == null) return;
 
      foreach (string layername in stepCurrent.GetAllLayerNames()) //check each layer and save gerber files for it.
      {
        ILayer layer = stepCurrent.GetLayer(layername);
 
        if (layer is IODBLayer)
        {
          ((IODBLayer)layer).SaveLayerAsGerber(GerberDirectory+"\\"+layername+".ger");
        }
      }
    }
  }

To load for example IPC2581 Files, you have to add the reference of PCBI_IPC2581.dll to your solution. Then you can use the interface of the Plug-In and load IPC2581 files. Here is a method to load one IPC2581 file in PCB-Investigator and use the ConvertODBToGerber method from before to save all layers as gerber274x files.

    private string tempDir = @"C:\Tests\converterTemp\";
    public void ConvertIPC2581FilesToGerber(IPCBIWindow window)
    {
      PCBI_IPC2581.IFilterIPC2581 FilterIPC = new PCBI_IPC2581.IFilterIPC2581(window);
 
      OpenFileDialog openDLG = new OpenFileDialog();
      openDLG.Filter = "IPC2581 files (*.cvg)|*.cvg|All files (*.*)|*.*";
      openDLG.Title = "Select an IPC2581 File to convert it in gerber274x";
 
      if (openDLG.ShowDialog() != DialogResult.OK)
        return;
 
      if (!FilterIPC.Load(openDLG.FileName, tempDir, true))
      {
        System.Diagnostics.Debug.WriteLine("Error, check the PCBI error log!");
        return;
      }
      //start converter with loaded job
      ConvertODBToGerber("", globalOutputDirectory, window);
    }

Here is the example code in C Sharp and VB: