How to set colors to net elements

This example shows how to handle net elements in an easy way. With the INet class you have the possibility to get all net items and work with them. For the example we take all nets from the first step and set a color to them.

Here is the example code in C Sharp and VB:

/// <summary>
    /// Button click event to start the example
    /// </summary>
    private void buttonNetColors_Click(object sender, EventArgs e)
    {
      IAutomation.IAutomationInit();
 
      //create a window to handle your actions
      IPCBIWindow mainWindowPCBI = IAutomation.CreateNewPCBIWindow(false);
 
      //then load a job
      mainWindowPCBI.LoadODBJob(@"C:\D\Jobs\DemoJob");
 
      SetNetColors(mainWindowPCBI);
 
      //looks better with xor colormixing, special replace same color on different layers with black
      mainWindowPCBI.IColorsetting.ColorMix = PCBI.DrawingMode.xor;
      mainWindowPCBI.Show();
    }
    /// <summary>
    /// Set colors for all nets in the first step.
    /// </summary>
    /// <param name="PCBI">The used main window.</param>
    public void SetNetColors(IPCBIWindow PCBI)
    {
      //take the fist step
      IStep firstStep = PCBI.GetCurrentStep();
 
      List<INet> allNets = firstStep.GetNets();
 
      int netcounter = 1;
      foreach (INet net in allNets)
      {
        //generate special color for this net
        Color netcolor = GetNewColor(netcounter);
 
        //go through all net elements and set the color
        foreach (IODBObject netItem in net.GetAllNetObjects(PCBI))
        {
          netItem.ObjectColor = netcolor;
        }
 
        netcounter++;
      }
    }
    /// <summary>
    /// Example method to generate different colors, limited colors but for the example ok.
    /// </summary>
    /// <param name="usedColors">counter for all used nets to generate different colors</param>
    /// <returns>Color for one net</returns>
    public Color GetNewColor(int usedColors)
    {
      switch (usedColors % 3)
      {
        case 0:
          return Color.FromArgb(usedColors % 255, 0, 32 + usedColors % 128);
          break;
        case 1:
          return Color.FromArgb(0, 64 + usedColors % 128, usedColors % 255);
          break;
        case 2:
          return Color.FromArgb(128 + usedColors % 128, usedColors % 255, 0);
          break;
      }