I would like to change all my part numbers(Designator Name) one by one, but Eagle does not allow to change a component name with a name that already exists. So what is the fastest way to change all parts name? (I already know about renumber ULP function but it does not let you pick your own name)
Electronic – Eagle Change all part names (Designator)
eagle
Related Solutions
I hate answering my own question, but here I go. I hope I don't get get points for answering, that would be weird, only for accepting an answer? (BTW, I did not get any response on the Element14 forum.)
The solution is to use the DRAW command, not ROUTE. DRAW will place a wire segment, exactly where you specify (unlike ROUTE, which tries to connect to an unrouted airwire. ROUTE is essentially useless in a script.). The next issue is via's: I can't (or don't want to) distinguish between a manual via and an autorouted via, so I keep all via's that connect two (or more) manual wire segments. Other via's are deleted.
So what my final script does is:
prepare a ripup command
for all copper segments that are not 0.01 wide (the width I use for autorouting)
check both endpoints for a via at that location
prepare the via to be resurrected when it is visited the 2nd time
prepare a command that resurrects the copper segment
execute the prepared commands
Note that it will probably not work for more than two layers, nor for other things than wire segments at the copper layer.
IMHO the whole concept of the eagle ULP and command languages is troublesome. An ULP runs in a read-only environment, the only way it can affect the circuit, board or library is by creating a list of commands. This eliminates some useful programming techniques, but worse is that the commands were not designed to be easily created from an ULP. You need all kinds of transformations (in this case: coordinates, shape names) to translate from the ULP world to the CMD world.
(edit) Before you run this ULP, set the 'wire bend' selection to allow arbitrary angles, otherwise eagle will try to adapt the resurrected wires to the allowed angles, which can result in a bloody mess. IMHO this is another example of the problem with ULP/SCR.
This is the ULP code:
// gather the commands that must be run on exit
string RunOnExit = "";
void cmd( string s ) { RunOnExit += s + "\n"; }
// return an x or y position in the form that can be used in a command
real f( int x ){
board( B ) switch( B.grid.unit ) {
case 0: return u2mic(x);
case 1: return u2mm(x);
case 2: return u2mil(x);
case 3: return u2inch(x);
}
}
// return the string form of the a via's shape
string sn( int x ){
if( x == VIA_SHAPE_SQUARE ) return "square";
if( x == VIA_SHAPE_ROUND ) return "round";
if( x == VIA_SHAPE_OCTAGON ) return "octagon";
if( x == VIA_SHAPE_ANNULUS ) return "annulus";
if( x == VIA_SHAPE_THERMAL ) return "thermal";
return "unknown-via-shape";
}
// count the number of times x occurs in s
int n_ocurrences( string s, string x ){
int i, n = 0;
while( 1 ){
i = strstr( s, x );
if( i == -1 ) return n;
s = strsub( s, i + strlen( x ));
n++;
}
}
// add a via, but only when it is visited the second time
string via_list = "";
void add_via( int a, int b ){
// for all via's
board( B ) B.signals( S ) S.vias( V ){
// if the via is at the current location
if(( V.x == a ) && ( V.y == b )){
string s, coo;
// the coordinates of the via are used as its identification
sprintf( coo, "(%.6f %.6f)", f( V.x ), f( V.y ));
// if this is the second visit to this via
via_list += coo;
if( n_ocurrences( via_list, coo ) == 2 ){
// resurrect this via
sprintf( s, "VIA '%s' %f %s %s;",
S.name, f( V.drill ), sn( V.shape[ 1 ] ), coo );
cmd( s );
}
}
}
}
if( !board ){
dlgMessageBox("start this ULP in Board", "OK");
exit( 0 );
}
board( B ){
// first delete all coper segments,
// later we will resurrect what we want to keep
cmd( "RIPUP;" );
// for all wire segments in the top and bottom copper layers
B.signals(S) S.wires(W) {
if( ( W.layer == 1 ) || ( W.layer == 16 ) ){
// that are not 0.01 width (that is what the autorouter uses)
if( f( W.width ) != 0.01 ){
string s;
// resurrect via's adjacent to this wire segment
add_via( W.x1, W.y1 );
add_via( W.x2, W.y2 );
sprintf( s, "CHANGE LAYER %d;", W.layer );
cmd( s );
// resurrect this wire segment
sprintf(
s, "WIRE '%s' %f (%.6f %.6f) (%.6f %.6f);",
S.name, f( W.width),
f(W.x1), f(W.y1), f(W.x2), f(W.y2));
cmd( s );
}
}
}
// dlgMessageBox( RunOnExit, "OK");
exit( RunOnExit );
}
There is a ULP script called renumber-sheet.ulp provided in the default Eagle installation for renaming parts; however it renames each prefix starting with 1 (e.g. R1, R2..., C1, C2...) which is not what you want.
There is a script called renumber_by_page.ulp at this location (bottom of the page). It works a little differently, as it renumbers it keeps the part numbers for all parts in sequence regardless of prefix, so it will renumber parts R101, R102, C103, C104 etc. More like what you want but not quite.
But wait, there's more.
Instead of renumbering the parts automatically, it creates a script called rename.scr which looks something like this:
EDIT .s1;
NAME 'BAT1' 'old_BAT1';
NAME 'C1' 'old_C1';
NAME 'C2' 'old_C2';
NAME 'D1' 'old_D1';
NAME 'D2' 'old_D2';
etc.
EDIT .s1;
NAME 'old_BAT1' 'BAT100';
NAME 'old_C1' 'C101';
NAME 'old_C2' 'C102';
NAME 'old_D1' 'D103';
NAME 'old_D2' 'D104';
etc.
So before running it, if you edited the prefixes in the second group, e.g. 'C to 'G$, 'D to G$ you would have what you want I think (if I understand your question correctly). This could either be done manually with a text editor, or via a script written in AWK or Python etc.
Related Topic
- How to add components using loop in Eagle PCB script
- Electronic – EAGLE change name of wire label in all similar label
- Electronic – Eagle: Selecting a group by signal name
- Electronic – Eagle PCB change drill size of all vias of a specific size
- Electronic – One particular part number not showing up on Eagle board layout
- Electronic – How to copy attributes between package variants in eagle library editor
- Electronic – Eagle PCB : Is there a pcb equivalent to the schematic net label that I can put on the silk
- Electrical – EAGLE Names not showing up on board after footprint update
Best Answer
There isn't a direct way to do this, but there is a ULP which is helpful in this regard called:
swap.ulp
With this you can simply enter commands in eagle such as:
That would swap the names of R1 and R10 (R1 becomes R10, and R10 becomes R1).
If you have lots to do, you can use a text editor to make a list of the swaps required to map all of the part names into the desired ordering. You can then convert your list into
run swap a b
commands and run all of them.