Dieses Beispiel demonstriert, wie ein Microsoft Excel Plug-in erstellt werden kann, das die Lagenliste mit der Objektanzahl und den Lagentypen in Tabellenform generiert.
Durch das Öffnen eines neuen Auftrags wird die Excel-Tabelle befüllt und alle relevanten Daten werden evaluiert.
public partial class ThisWorkbook
{
IPCBIWindow window;
private void ThisWorkbook_Startup(object sender, System.EventArgs e)
{
window = IAutomation.CreateNewPCBIWindow(true); //create one instance of PCB-Investigator
window.PCBINewJobOpend += new EventHandler(window_PCBINewJobOpend);
}
void window_PCBINewJobOpend(object sender, EventArgs e) //on opening an job we fill the excel sheet
{
Excel.Sheets sheets;
Excel._Worksheet sheet;
try
{
try
{
//Get a reference to the first sheet of the workbook. By changing the index we can write the report in other worksheets
sheets = this.Worksheets;
sheet = (Excel._Worksheet)sheets.get_Item(1);
}
catch (Exception exSheet)
{
MessageBox.Show(exSheet.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (sheet != null)
{
IStep step = window.GetCurrentStep();
IMatrix matrix = window.GetMatrix();
if (step != null)
{
int runIndex =2;
sheet.Cells[1, 1].Value = "Layerlist";
sheet.Cells[1, 2].Value = "Objectcount";
sheet.Cells[1, 3].Value = "Layertype";
foreach(string layername in step.GetAllLayerNames()) //all layer
{
sheet.Cells[runIndex, 1].Value = layername;
ILayer layer = step.GetLayer(layername);
sheet.Cells[runIndex, 2].Value = layer.GetAllLayerObjects().Count; //how much elements on the layer?
sheet.Cells[runIndex, 3].Value = matrix.GetMatrixLayerType(layername).ToString(); //which type is this layer?
runIndex++;
}
sheet.Activate(); //show the filled list
}
}
}
catch (Exception exError)
{
MessageBox.Show(exError.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void ThisWorkbook_Shutdown(object sender, System.EventArgs e)
{
if (window != null)
IAutomation.ClosePCBIWindow(window);
}