Counting connections in xPCB Layout?

I'm working on a C# plugin that will count the number of connections in xPCB Layout and generate a report similar to Output -> Design Status. However, I can't seem to get the same connection count as design status. I've tried three different methods:

The difference between your count and the DesignStatus might be based on the interpretation of a "connection" as a netline. If you have a two pin net, it really represents one connection, while a three pin net would have two connections, etc. In coding terms, take your count and subtract the number of nets that have multiple pins, then see if that matches the DesignStatus. Or, using your second method, replace the last line with:

retval.Connections += (net.Pins.Count - 1);

Regarding formatting, I always have trouble on this site pasting tabs, which turn out as single spaces. Windows newlines (CR-LF) paste just fine, but Unix newlines (LF) may not.

That logic is sound (two pins = 1 connection, 3 pins = 2 connections, etc), however, the count is now lower than the design status report. I'm now investigating a way to use the Subnet property...the PCB Automation Reference seems to indicate it has something to do with the number of connected conductive items, but it seems like there are 9 different object types that could be connected (BondPad, ConductiveArea, Marker, MetalizationArea, MountingHole, MultiVia, Pin, Trace, Via). I also plan to try setting one or more values for the ConnectionCountOption on the doc object before getting the ConnectionCountNets from it.

- Setting the doc.ConnectionCountOption throws an exception, so I don't think doc.ConnectionCountNets.Count will provide meaningful info until I can set that properly. The documentation does not provide hints on how to set ConnectionCountOption properly, and does not describe what a sortChannel is.

- No obvious combination of net.{BondPad, ConductiveArea, Marker, MountingHole, Pin, Trace, Via} is the same as the reported Connections. For MetalizationArea I used PlaneShapes, and there's no net.MultiVias property (perhaps there's a way to calculate this from net.Vias?).

To get the pins that are connected to planes is more complicated. I loop through all the plane assignments and determine which net is assigned to it. From there, I add the connected pins, and in the nets loop, skip nets that are assigned to planes (because they are already counted):

// Get the list of all the nets regardless of the namenets = doc.Nets[MGCPCB.EPcbSelectionType.epcbSelectAll, true, "*"];

// Get the number of nets (note that Net0 is included in this count, but is a fake net. Subtract 1 from the total nets)int numNets = nets.Count - 1;int numGuides = 0;foreach(MGCPCB.Net net in nets) { // I think this command can be replaced by the FromTo Unconnected count if (net.IsNet0() == false) { numGuides += net.NumberOfOpens; if (pinsperplane.ContainsKey(net.Name) == false) { nonpapincount += net.Pins.Count; } else { papincount += net.Pins.Count; } }}

Note that each pin connected to a net is counted, so when one pin is connected to one pin, that is one connection (but 2 pins). So to get the number of connections from the number of net connected pins, I subtract the number of nets from the total count.

nonpapincount -= numNets;

This gets to 2066 connects on nets, and 1238 connections to planes for a total of 3304 (out of 3402) connections in my test design.

Connections = nonpapincount + papins;

I think some of the missing connections come from connections to plane shapes (84), leaving 14 connections I cannot identify. I did try to count the number of pins on each part that are not connected to Net0 (meaning not connected), but don’t remember the result. I have also counted bond wires (0), bond pads (0) and conductive mounting holes (0).