Dieses Beispiel zeigt, wie man Elementtypen zählen, sowie das kleinste Element auf jeder Signallage auffinden lassen kann.
Wichtig dabei ist es, eine extra Klasse mit einem Index für jede Lage zu haben, da das Beispiel andernfalls schnell überfüllt und damit verwirrend wirken kann, da man viele int-Werte benötigen würde, die die Ergebnisse beinhalten.

Hier finden Sie den Beispielcode in C# und VB:

private void buttonCreateHistogram_Click(object sender, EventArgs e)
    {
      IStep step = mainWindowPCBI.GetCurrentStep();
      if (step == null)
      {
        MessageBox.Show("Please load a job first to use this demo.", "No Job Loaded!", MessageBoxButtons.OK, MessageBoxIcon.Information);
        return;
      }
 
      //for example we take all signal layer
      IMatrix matrix = mainWindowPCBI.GetMatrix();
      List<ResultForHistogram> ResultOverviewList = new List<ResultForHistogram>();
      foreach (string layerName in matrix.GetAllSignalLayerNames())
      {
        ILayer relevantLayer = step.GetLayer(layerName);
        if (relevantLayer == null) continue; //if job is modified it is possible wrong names in the matirx
 
        List<IObject> layerObjectList = relevantLayer.GetAllLayerObjects();
        //is there a elemt on the layer?
        if (layerObjectList.Count == 0) return;
 
        double smallestArea = double.MaxValue; //for beginning we use the highest value
        IODBObject smallesObject = null;
 
        ResultForHistogram layerHistogram = new ResultForHistogram();
        layerHistogram.LayerName = layerName;
 
        foreach (IODBObject relevantObject in layerObjectList)
        {
          //check area is possible smaller?
 
          if (relevantObject.Type == IObjectType.Pad)
          {
            layerHistogram.CountPads++;
            IPadSpecificsD pad = (IPadSpecificsD)relevantObject.GetSpecificsD();
 
            if (pad.Type == PCBI.Symbol_Type.rect) //special case for area
            {
              //rect has easiest way to calculate area
              PCBI.MathUtils.RectangleD boundsRelevanObject = relevantObject.GetBoundsD();
 
              double areaOfPad = boundsRelevanObject.Width * boundsRelevanObject.Height;
 
              if (areaOfPad < smallestArea)
              {
                //new smallest
                smallesObject = relevantObject;
                smallestArea = areaOfPad;
              }
            }
            else if (pad.Type == PCBI.Symbol_Type.r) //round pads are easy too
            {
              double areaOfPad = Math.Pow(pad.Diameter / 2, 2) * Math.PI;
 
              if (areaOfPad < smallestArea)
              {
                //new smallest
                smallesObject = relevantObject;
                smallestArea = areaOfPad;
              }
            }
            else
            {
              double areaOfPad = relevantObject.CalculateArea(true);
              if (areaOfPad < smallestArea)
              {
                //new smallest
                smallesObject = relevantObject;
                smallestArea = areaOfPad;
              }
            }
          }
          else
          {
            if (relevantObject.Type == IObjectType.Arc)
              layerHistogram.CountArcs++;
            else if (relevantObject.Type == IObjectType.Line)
              layerHistogram.CountLines++;
            else if (relevantObject.Type == IObjectType.Surface)
              layerHistogram.CountSurfaces++;
            else if (relevantObject.Type == IObjectType.Text)
              layerHistogram.CountText++;
 
            double areaOfPad = relevantObject.CalculateArea(true);
            if (areaOfPad < smallestArea)
            {
              //new smallest
              smallesObject = relevantObject;
              smallestArea = areaOfPad;
            }
          }
        }
        if (smallesObject != null)
        {
          smallesObject.Select(true); //mark as selected
          layerHistogram.SmallesElementArea = smallestArea;
        }
 
        ResultOverviewList.Add(layerHistogram);
      }
      //something went wrong?
      string errorLog = IAutomation.GetErrorLog();
      if (errorLog.Length > 0)
        System.Diagnostics.Debug.WriteLine(errorLog);
 
      if (ResultOverviewList.Count>0) //if there is a layer with elements show messagebox
      {
        StringBuilder sb = new StringBuilder();
 
        foreach (ResultForHistogram resultLayerHistogram in ResultOverviewList)
          sb.AppendLine(resultLayerHistogram.ToString());
 
        MessageBox.Show("Overview all signal layers "+Environment.NewLine + sb.ToString() , "Layer Histogram", MessageBoxButtons.OK, MessageBoxIcon.Information);
      }
      else
        MessageBox.Show("No results found, this demo works only for signal layers!", "No Layer Histogram", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
 
    }
    /// <summary>
    /// Special class to count informations and create report string.
    /// </summary>
    public class ResultForHistogram
    {
      public string LayerName = "";
 
      public int CountLines = 0;
      public int CountArcs = 0;
      public int CountSurfaces = 0;
      public int CountText = 0;
      public int CountPads = 0;
      public double SmallesElementArea = double.MaxValue;
 
      public override string ToString()
      {
        return LayerName + ": L " + CountLines + ", A " + CountArcs + ", S " + CountSurfaces + ", T " + CountText + ", P " + CountPads + " - smallest elemts size: " + SmallesElementArea.ToString() + " mils²";
      }
    }