Im Folgenden finden Sie ein einfaches Beispiel, wie man PCB-Investigator als Bibliothek nutzt, um eine Gerberlage zu laden und ihre Elemente zählen zu lassen. Es ist wichtig, dass sie zuerst die Referenz auf den PCB-Investigator setzen und weitere Elemente mittels PCBI.Automation hinzufügen.
Hier finden Sie den Beispielcode in C# und VB
/// <summary>
/// Create an overview how much elements on one gerberlayer.
/// </summary>
private static void CreateGerberReport()
{
IAutomation.IAutomationInit();
//create a window to handle your actions
IPCBIWindow mainWindowPCBI = IAutomation.CreateNewPCBIWindow(false);
//create a directory for ODB++ structure with one step names "pcb"
string jobPath = mainWindowPCBI.CreateNewJobDirectory(@"C:\tests\FirstTestJob", "FirstTestJob", "pcb");
//after creating the directory we have to load it
mainWindowPCBI.LoadODBJob(jobPath);
IStep firstStep = mainWindowPCBI.GetStep("pcb");
//show a dialog to select the first layer from an gerber file
OpenFileDialog openDLG = new OpenFileDialog();
openDLG.Title = "Select gerber file for demo application";
if (openDLG.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
//we load the gerberdata in one layer and remember the layername
string gerberLayerName = firstStep.AddGerberLayer(openDLG.FileName, false);
//we need the ILayer object for handling data of the gerberfile
ILayer GerberLayer = firstStep.GetLayer(gerberLayerName);
//now we make an report of all element types
int counterPads = 0;
int counterLines = 0;
int counterArcs = 0;
int counterOthers = 0;
foreach (IObject ObjOnGerber in GerberLayer.GetAllLayerObjects())
{
if (ObjOnGerber.Type == IObjectType.Pad)
counterPads++;
else if (ObjOnGerber.Type == IObjectType.Line)
counterLines++;
else if (ObjOnGerber.Type == IObjectType.Arc)
counterArcs++;
else
counterOthers++;
}
Console.WriteLine("Report Gerber File " + gerberLayerName);
Console.WriteLine("Pads: " + counterPads.ToString());
Console.WriteLine("Lines: " + counterLines.ToString());
Console.WriteLine("Arcs: " + counterArcs.ToString());
Console.WriteLine("Others: " + counterOthers.ToString());
}