How to load files with different file formats

This example shows how to use PCB-Investigator plug-ins to load data from GenCad 1.4, IDF or IPC2581 files. You need the references of all these plug-ins and a reference for PCB-Investigator.

Use Add Reference for “PCBI_GenCad”, “PCBI_IPC2581” and “PCBI IDF_Import”, you find this dlls in the PlugIn subdirectory of your PCB-Investigator installation (Demo too).

Here is the example code in C Sharp and VB:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PCBI.Automation;
using System.IO;
 
namespace HowToUseImportPlugIns
{
  public partial class FormexampleImports : Form
  {
    //where should the temp data saved?
    internal string WorkingDirectory = Path.GetTempPath() + "tests" + Path.DirectorySeparatorChar;
 
    public FormexampleImports()
    {
      InitializeComponent();
    }
    /// <summary>
    /// In the click event the genCadFilter will be created and load gencad files.
    /// </summary>
    private void buttonGenCad_Click(object sender, EventArgs e)
    {
      OpenFileDialog openGenCad = new OpenFileDialog();
      openGenCad.Title = "Select GenCad 1.4 File";
 
      if (openGenCad.ShowDialog() == System.Windows.Forms.DialogResult.OK)
      {
        IPCBIWindow parentPCBI = IAutomation.CreateNewPCBIWindow(true); //In this window we show the loaded data
        PCBIGenCadFilter.IPNLFilter gencadFilter = new PCBIGenCadFilter.IPNLFilter(parentPCBI);
 
        //hiere is the real load call:
        gencadFilter.LoadGenCadFile(openGenCad.FileName, WorkingDirectory + "GenCadData");
      }
    }
    /// <summary>
    /// Show an open file dialog and select a IPC2581 file, with the IFilterIPC2581 it's possible to load the file.
    /// </summary>
    private void buttonIPC_Click(object sender, EventArgs e)
    {
      OpenFileDialog openIPC = new OpenFileDialog();
      openIPC.Title = "Select IPC2581 File";
      if (openIPC.ShowDialog() == System.Windows.Forms.DialogResult.OK)
      {
        IPCBIWindow parentPCBI = IAutomation.CreateNewPCBIWindow(true); //window to show the loaded data
      
        PCBI_IPC2581.IFilterIPC2581 ipcFilter = new PCBI_IPC2581.IFilterIPC2581(parentPCBI);
 
        if (!ipcFilter.Load(openIPC.FileName, WorkingDirectory + "IPCData", false))
          Console.WriteLine("Can't load file..."); //if there was an error...
      }
    }
    /// <summary>
    /// There its a little bit different, you need two files to load the IDF data.
    /// </summary>
    private void buttonIDF_Click(object sender, EventArgs e)
    {
      OpenFileDialog openIDF = new OpenFileDialog();
      openIDF.Title = "Select IDB file and IDL-file";
      openIDF.Multiselect = true;
 
      if (openIDF.ShowDialog() == System.Windows.Forms.DialogResult.OK)
      {
        if (openIDF.FileNames.Count() > 1) //hope user select correct pair of files
        {
          LoadIDF(openIDF.FileNames[0], openIDF.FileNames[1]);
        }
        else
        {
          //its possible that only the ending has to change
          LoadIDF(openIDF.FileName, openIDF.FileName.Replace(".idb", ".idl"));
        }
      }
    }
    internal void LoadIDF(string fullPathIDB, string fullPathIDL)
    {
      IPCBIWindow parentPCBI = IAutomation.CreateNewPCBIWindow(true); //as in the other examples we need an window for output
      PCBI___IDF_Import.IFilterIDF filter = new PCBI___IDF_Import.IFilterIDF();
      try
      {
        StringBuilder errors = new StringBuilder(); //the importIDF method write errors in this StringBuilder
        if (!filter.ImportIDF(parentPCBI, WorkingDirectory + "IDFData", fullPathIDB, fullPathIDL, ref errors))
          Console.WriteLine(errors.ToString());
      }
      catch (Exception ex)
      {
        Console.WriteLine("Can't open IDF Data, because " + ex.ToString());
      }
    }
  }
}