I would like to Rename all Nets in a DxDesigner Design no matter if the net already has a name or not. For this, I have gone the way as mostly described here but it does not work reliably and does not rename empty nets.
The way I am trying to do this is:
- Get every Part using a query:
- ViewDraw.IVdObjs part = dxdApp.Query(ViewDraw.VdObjectTypeMask.VDM_COMP, ViewDraw.VdAllOrSelected.VD_ALL);
- Get each component out of the query:
for (int i = 1; i <= part.Count; i++)
{
comp = part.Item(i);
- Get Reference Designator from part and compare it with the part I am looking the net up
if (comp.Refdes == netArrayEntries.refDes)
{
- Get connections
conn = comp.GetConnections();
- Compare pin number from every connection with the pin number I am looking for:
for (int j = 1; j <= conn.Count; j++)
{
if (conn.Item(j).CompPin.Number == netArrayEntries.cmpPin) // Compare component pin number with looked up pin number
{
- Get Net from the connection item
net = conn.Item(j).Net;
- Set new net for the first segment of the net
for (int k = 1;k < 2; k++)
{
segment = net.GetSegments().Item(k);
- Set
net.GetLabel(segment).Selected = true;
net.GetLabel(segment).Visible = ViewDraw.VdLabelVisibility.VDLABELVISIBLE;
netLabel = net.GetConnectedLabel(segment);
netLabel.TextString = netArrayEntries.newNetName;
As mentioned already, it does rename some nets, it doesn't on other. It works fairly slow and throws an exception on empty net names. It does not seem right to me, that I am getting dozens of segments, but renaming one does the job. Honestly, I assume there must be an easier way to accomplish what I've been looking for.
As you may figure, this is written in C#, glad though for any examples in VB/VBS or hints that may lead to a proper solution.
Please see the complete source code of the rename method below:
private void alterNetnameWithComponentInput(netStruct netArrayEntries) { IVdComp comp; IVdObjs conn; IVdNet net; IVdSegment segment; IVdLabel netLabel; if ((netArrayEntries.newNetName == null) || (netArrayEntries.cmpPin == null) || (netArrayEntries.refDes == null)) { return; } ViewDraw.IVdObjs part = dxdApp.Query(ViewDraw.VdObjectTypeMask.VDM_COMP, ViewDraw.VdAllOrSelected.VD_ALL); //Query all Components for (int i = 1; i <= part.Count; i++) { comp = part.Item(i); if (comp.Refdes == netArrayEntries.refDes) { //Console.WriteLine("Komponente " + comp.Refdes); AppendTextBox("Component " + comp.Refdes + "\n"); outputFileNets.WriteLine("Component " + comp.Refdes + "\n"); conn = comp.GetConnections(); // Get connections associated with component for (int j = 1; j <= conn.Count; j++) { if (conn.Item(j).CompPin.Number == netArrayEntries.cmpPin) // Compare component pin number with looked up pin number { //Console.WriteLine("Pin Nummer " + conn.Item(j).CompPin.Number); AppendTextBox("Pin " + conn.Item(j).CompPin.Number + "\n"); outputFileNets.WriteLine("Pin " + conn.Item(j).CompPin.Number + "\n"); net = conn.Item(j).Net; //for (int k = 1; k < net.GetSegments().Count; k++) for (int k = 1;k < 2; k++) { segment = net.GetSegments().Item(k); try { AppendTextBox("Segment " + net.GetLabel(segment).TextString + "\n"); outputFileNets.WriteLine("Segment " + net.GetLabel(segment).TextString + "\n"); } catch (Exception ex) { AppendTextBox("Empty Netsegment" + "\n"); outputFileNets.WriteLine("Empty Netsegment" + "\n"); } try { //Console.WriteLine("Segment " + net.GetLabel(segment).TextString); //net.GetLabel(segment).TextString = "NAME=" + netArrayEntries.newNetName; //if (net.GetLabel(segment) == null) -------CHANGED //if (net.GetConnectedLabel(segment) == null) //{ //net.AddLabel(segment, "Name=" + netArrayEntries.newNetName, 100, 100); //net.AddAttribute(segment, "Name", 100, 100, VdVisibilityFlag.VDINVISIBLE); //net.GetLabel(segment).TextString = netArrayEntries.newNetName; //} //else //{ //Alternate Version AppendTextBox("Renaming ID" + net.Id.ToString() + " from " + net.GetLabel(segment).TextString + " to " + netArrayEntries.newNetName + "\n"); net.GetLabel(segment).Selected = true; net.GetLabel(segment).Visible = ViewDraw.VdLabelVisibility.VDLABELVISIBLE; netLabel = net.GetConnectedLabel(segment); netLabel.TextString = netArrayEntries.newNetName; //net.GetLabel(segment).TextString = netArrayEntries.newNetName; net.GetLabel(segment).Visible = ViewDraw.VdLabelVisibility.VDLABELINVISIBLE; //} AppendTextBox("Replacing Net with " + netArrayEntries.newNetName + "\n"); outputFileNets.WriteLine("Replacing Net with " + netArrayEntries.newNetName + "\n"); // Netz muss bereits Name haben, dann klappt es } catch (Exception ex) { Console.WriteLine(ex.ToString()); AppendTextBox("Error Replacing Net Segment name" + "\n"); outputFileNets.WriteLine("Error Replacing Net Segment name" + "\n"); } AppendTextBox("DONE-------------------------------------" + "\n"); outputFileNets.WriteLine("DONE-------------------------------------" + "\n"); } } } } } }
Thanks
Martin