{"id":209,"date":"2022-10-10T10:05:40","date_gmt":"2022-10-10T08:05:40","guid":{"rendered":"http:\/\/test.pcbinvestigator.de\/en\/?page_id=209"},"modified":"2022-10-10T13:49:46","modified_gmt":"2022-10-10T11:49:46","slug":"how-to-set-colors-to-net-elements","status":"publish","type":"page","link":"https:\/\/www.pcb-investigator.com\/en\/support\/help-center\/how-to-instructions\/how-to-set-colors-to-net-elements\/","title":{"rendered":"How to set colors to net elements"},"content":{"rendered":"\n<p>This example shows&nbsp;<strong>how to handle net elements<\/strong>&nbsp;in an easy way. With the&nbsp;<strong>INet class<\/strong>&nbsp;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.<\/p>\n\n\n\n<p><strong><strong>Here is the example code in C Sharp and VB:<\/strong><\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"http:\/\/www.easylogix.de\/download\/HowTo\/Demo7VBCode.zip\" target=\"_blank\" rel=\"noopener\">download VB<\/a><\/li><li><a href=\"http:\/\/www.easylogix.de\/download\/HowTo\/Demo7CSharp.zip\" target=\"_blank\" rel=\"noopener\">download C#<\/a><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\/ &lt;summary&gt;\n    \/\/\/ Button click event to start the example\n    \/\/\/ &lt;\/summary&gt;\n    private void buttonNetColors_Click(object sender, EventArgs e)\n    {\n      IAutomation.IAutomationInit();\n \n      \/\/create a window to handle your actions\n      IPCBIWindow mainWindowPCBI = IAutomation.CreateNewPCBIWindow(false);\n \n      \/\/then load a job\n      mainWindowPCBI.LoadODBJob(@\"C:\\D\\Jobs\\DemoJob\");\n \n      SetNetColors(mainWindowPCBI);\n \n      \/\/looks better with xor colormixing, special replace same color on different layers with black\n      mainWindowPCBI.IColorsetting.ColorMix = PCBI.DrawingMode.xor;\n      mainWindowPCBI.Show();\n    }\n    \/\/\/ &lt;summary&gt;\n    \/\/\/ Set colors for all nets in the first step.\n    \/\/\/ &lt;\/summary&gt;\n    \/\/\/ &lt;param name=\"PCBI\"&gt;The used main window.&lt;\/param&gt;\n    public void SetNetColors(IPCBIWindow PCBI)\n    {\n      \/\/take the first step\n      IStep firstStep = PCBI.GetCurrentStep();\n \n      List&lt;INet&gt; allNets = firstStep.GetNets();\n \n      int netcounter = 1;\n      foreach (INet net in allNets)\n      {\n        \/\/generate special color for this net\n        Color netcolor = GetNewColor(netcounter);\n \n        \/\/go through all net elements and set the color\n        foreach (IODBObject netItem in net.GetAllNetObjects(PCBI))\n        {\n          netItem.ObjectColor = netcolor;\n        }\n \n        netcounter++;\n      }\n    }\n    \/\/\/ &lt;summary&gt;\n    \/\/\/ Example method to generate different colors, limited colors but for the example ok.\n    \/\/\/ &lt;\/summary&gt;\n    \/\/\/ &lt;param name=\"usedColors\"&gt;counter for all used nets to generate different colors&lt;\/param&gt;\n    \/\/\/ &lt;returns&gt;Color for one net&lt;\/returns&gt;\n    public Color GetNewColor(int usedColors)\n    {\n      switch (usedColors % 3)\n      {\n        case 0:\n          return Color.FromArgb(usedColors % 255, 0, 32 + usedColors % 128);\n          break;\n        case 1:\n          return Color.FromArgb(0, 64 + usedColors % 128, usedColors % 255);\n          break;\n        case 2:\n          return Color.FromArgb(128 + usedColors % 128, usedColors % 255, 0);\n          break;\n      }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This example shows&nbsp;how to handle net elements&nbsp;in an easy way. With the&nbsp;INet class&nbsp;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: download VB download [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":246,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-209","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/pages\/209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/comments?post=209"}],"version-history":[{"count":2,"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/pages\/209\/revisions"}],"predecessor-version":[{"id":354,"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/pages\/209\/revisions\/354"}],"up":[{"embeddable":true,"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/pages\/246"}],"wp:attachment":[{"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/media?parent=209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/categories?post=209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pcb-investigator.com\/en\/wp-json\/wp\/v2\/tags?post=209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}