#usage "Rename a net \n

" "From a context menu for a net wire, this ULP simplifies the renaming of a net.

" "

" "Requires Eagle version 6.0.0 or later.

" "Usage:
" "On first usage, in the schematic, run the ULP using the mouse or type into the command line the following:" "

" "Once the context menu has been created, use the ULP as follows:

" "

" "Author: Warren Brayshaw" string version = "v1.0"; real rad,cx,cy,px,py; string result,MyParam,usrret,ctxcmd,RunUlp,cmd,ClickXY,netname,ULPname,PinDisplayList[],PinNames[],PinNamesNotSeg[]; numeric string NetList[]; string ctxdesc = "Rename Net", NewName = "default", NewNameLab= "New Name:"; int x,MenuCnt=1,NetCnt,PinCnt,PinCntNotSeg,SelWireCnt,ContextExists,NetsInGroupCnt,DisPinNameCnt; string header = "By renaming a net segment, you can
" "  •  disconnect it electrically from other segments
" "  •  reconnect it to another net (by giving it that net's name)
" "  •  give the whole net a unique and descriptive name

" "


"; //**********USER OPTIONS********************************************************************************* //CHANGE THE "1" IN THE FOLLOWING LINE TO A "0" IF YOU DON'T WANT 'RepositionMouseCursorAfterContextMenu' string ReposMouse = "1"; //****************************************************************************************************** void Explain(string reason) { string UseExplanation = ":" + reason + "

This ULP requires that you launch it from the context menu of a net wire.

" "The context menu item 'Rename Net' has been created for you by this ULP.

" "Usage:" "

"; dlgMessageBox(UseExplanation); } //***************************** void CheckNetCnt(int netcnt,int SelWireCnt) { switch (netcnt) { case 0:Explain("No net was selected.");exit(0); case 1:switch (SelWireCnt){ case 1:return; default:Explain("Multiple wires were selected."); exit(0); } default:Explain("Multiple nets were selected."); exit(0); } } //***************************** string UnusedN() { string Nnet; numeric string Ns[]; int n,next; for(int x=0; x•  disconnect it electrically from other segments" "
•  reconnect it to another net (by giving it that net's name)
" "
•  give the whole net a unique and descriptive name
" "
" "
New Name: field
Enter the new name for the net into the 'New name:' field.
" "The contents of this field is used to rename your net.
" "
A net name can be overlined by preceding the name with a '!'.
" "See Eagle Help > Editor Commands > Text > Overlined text for more details.
" "
'Unused N$x' button
" "
Used to place the first unused name in Eagle's default N$xx format into the 'New name' field.
" "
All Nets: field
The drop down of this field shows all the nets in your design. If you select another net in the list it is copied into the 'New name:' field.
" "
" "If there are pins connected to the selected net segment and they have their names visible, there will be an additional section displayed related to these visible pin names.

" "This is useful when the desired net name is the same or similar to the pin name.

" "

Pin Name: field
" "
A list of visible pin names, connected to your net, is made available here.
Use the dropdown to select from the list.
" "
Use the radio buttons to select between displaying the visible pin names of the selected net segment or of all segments of that net.
" "
'Use pin name' button
" "
Used to place the selected pin name into the 'New name' field where it can be edited.
" "
" "
'Rename' button
" "
This will rename the net to the text in the 'New name' field and return you to the schematic.
" "
'Cancel'button
" "
This will return you to the schematic, making no change to the net name.
"; dlgDialog("Information"){ dlgHBoxLayout{ dlgSpacing(350);} dlgLabel(info); dlgHBoxLayout{ dlgLabel(version); dlgStretch(1); dlgPushButton("+OK") dlgReject(); } }; } //***************************** void swaparray(int seg, int Acnt) //0 = This seg, 1 = All segs, Acnt = size of source array { int x,n,m,trim; int TrimCnt = DisPinNameCnt; if(Acnt < DisPinNameCnt) trim = 1; if(seg==1){// source array == All Segs DisPinNameCnt = 0; for(x=0; x1){ //remove dups from PinNames list sort(DisPinNameCnt,PinDisplayList); do{ if(PinDisplayList[n] == PinDisplayList[n+1]){ for(m=n; mNew Name:"; } //***************************** string GUI(string CurrentName) { int x,Sel=2,SelNet,PinDisplay; NewName = CurrentName; for(x=0; x" + netname); dlgCell(4,0,4,0) dlgLabel(NewNameLab,1); dlgCell(4,1,4,3) dlgStringEdit(NewName); dlgCell(4,4,4,4) dlgPushButton("Unused N$x"){NewName = UnusedN(); UpdateNewLab();} dlgCell(5,0,5,0) dlgLabel("All Nets"); dlgCell(5,1,5,3) dlgComboBox(NetList, SelNet){NewName = NetList[SelNet]; UpdateNewLab();} } } if(PinCnt){ dlgGroup("Visible Pin Names on Selected Net:"){ dlgGridLayout{ dlgCell(0,0,0,0) dlgLabel("Pin Name:"); dlgCell(0,1,0,3) dlgComboBox(PinDisplayList, Sel)UpdateNewLab(); dlgCell(0,4,0,4) dlgPushButton("Use pin name"){NewName = PinDisplayList[Sel];UpdateNewLab();} dlgCell(1,0,1,1) dlgRadioButton("This net segment only",PinDisplay) swaparray(0,PinCnt); dlgCell(2,0,2,1) dlgRadioButton("All segments of this net",PinDisplay) swaparray(1,PinCntNotSeg); } } } dlgSpacing(30); dlgHBoxLayout { dlgPushButton("Help") {info();} dlgStretch(1); dlgPushButton("+Rename") {if(CheckForChars(NewName)) dlgAccept();} dlgPushButton("-Cancel") {dlgReject(); exit(0);} } }; return NewName; } //***************************** //************main************* #require 6.0000 if(!schematic){ dlgMessageBox("Start this ULP from a schematic"); exit(0);} ULPname = filename(argv[0]); sprintf(ctxcmd,"'%s' = 'run %s'",ctxdesc,ULPname); //This sets up for and exit and set context. while (MyParam != "SomeParam"){ sprintf(usrret,"EAGLE:Sch.MenuContext.Wire.%u",MenuCnt); MyParam = cfgget(usrret,"SomeParam"); if(MyParam != "SomeParam"){ if(strstr(MyParam,ctxcmd)!= -1){ ContextExists = 1; break; } } else break; MenuCnt++; } if(!ContextExists) { RunUlp = "'Rename Net' = 'run " + ULPname + "'"; cfgset(usrret,RunUlp); //set the context with a cfgset() exit("Group;\nrun " + argv[0]); //Clears group so upon re-entry no items are found in group and hence info is displayed. } if(cfgget("EAGLE:Option.RepositionMouseCursorAfterContextMenu")=="0"&& ReposMouse=="1"){ cfgset("EAGLE:Option.RepositionMouseCursorAfterContextMenu","1"); } if(cfgget("EAGLE:Option.RepositionMouseCursorAfterContextMenu")=="1"&& ReposMouse=="0"){ cfgset("EAGLE:Option.RepositionMouseCursorAfterContextMenu","0"); } schematic(S){ S.sheets(SH){ SH.nets(N){ NetList[NetCnt] = N.name; NetCnt++; if(ingroup(N)){ netname = N.name; //This is our net name or another if multiple nets were selected. NetsInGroupCnt++; N.segments(SG){ if(ingroup(SG)){ //Segment ingroup. SG.wires(W){ if(ingroup(W)){ //A selected net wire. SelWireCnt++; if(W.arc){ cx=u2mm(W.arc.xc); cy=u2mm(W.arc.yc); px=u2mm(W.arc.x1); py=u2mm(W.arc.y1); rad=((W.arc.angle2 - W.arc.angle1)/2)*PI/180; sprintf(ClickXY,"(%f %f)",cx +(px-cx)*cos(rad) + (cy-py)*sin(rad),cy+(py-cy)*cos(rad)+(px-cx)*sin(rad)); } else { sprintf(ClickXY,"(%f %f)",u2mm((W.x1+W.x2)/2),u2mm((W.y1+W.y2)/2)); } } } SG.pinrefs(PR){ //correct segment, now get pins this segment connects to if(PR.pin.visible >= 2) { //add to array of possible pin names for net names PinNames[PinCnt] = PR.pin.name; PinCnt++; } } } } } } } S.sheets(SH){ //get all visible pin names of our net SH.nets(N){ if(netname == N.name){ //This is our net name N.segments(SG){ SG.pinrefs(PR){ //all segments from net in group, get pins this segment connects to if(PR.pin.visible >= 2) { //add to array of possible pin names for net names PinNamesNotSeg[PinCntNotSeg] = PR.pin.name; PinCntNotSeg++; } } } } } } } CheckNetCnt(NetsInGroupCnt,SelWireCnt); //Check that only one net wire segment is in the group. if(NetCnt >1) RemNetDups(); swaparray(0,PinCnt); NewName = GUI(netname); cmd = "GRID MM;\n"; cmd += "NAME " + NewName + " " + ClickXY + ";\n"; cmd += "GRID LAST;\n"; //dlgMessageBox(cmd); exit(cmd);