#usage "Renumber the parts of a schematic\n" "
"
"
\n" + "Please verify that your corresponding layout file (if already existing) " + "has been loaded with the schematic file.
\n" + "Otherwise back-/forward-annotation will not work afterwards.
\n" + "This version renumbers only devices with package (no supply) " + "sorted by sheets and coordinates (vertical/descending, horizontal/ascending).
\n";
int i, idx; // helpers...
string strPrefix; // helpers...
int descy = 1; // set to 0 sorting ascending
int descx = 0; // set to 1 sorting descending
int iWhat=0; // 0=All sheets, 1=Only components inside rect on layer 95 (Names)
int iStartNumber=1;
string c, cmd; // variables for script generation
string strOldNames=" ", strForbiddenNames=" ";
// elements to rename
// STRUCT {
numeric string oldName[]; // old name
numeric string newName[]; // new name
int x[],y[]; // position in mil
int sh[]; // sheet
// }
int sortidx[]; // sort-index, "pointer-array" to elements
int iCount=0; // number of elements
// start numbers
// STRUCT {
string prefix_name[]; // prefix
int prefix_number[]; // next number to use
// }
int iPrefixCount=0;
void AppendPartToRename(UL_PART p)
{
int i;
// has package?
if (!p.device.package) return;
// propere name with prefix and number?
if (GetNumberIndex(p.name) <= 0) return;
// check if part was already added
for (i=0; i \nThis program can only work in the schematic editor.");
exit(1);
}
///////////////////////////////////////////
// Main Dialog
///////////////////////////////////////////
int iResult = dlgDialog("Renumber schematic")
{
dlgLabel(strInfo);
dlgGroup("Options")
{
dlgRadioButton("All sheets", iWhat);
dlgRadioButton("Only components inside rectangle(s) on layer 95 (Names)", iWhat);
dlgSpacing(5);
dlgHBoxLayout { dlgLabel("Start with number: "); dlgIntEdit(iStartNumber, 1, 99999); }
}
dlgHBoxLayout
{
dlgGroup("Sort X")
{
dlgRadioButton("&Ascending (Left ==> Right)", descx);
dlgRadioButton("&Descending (Right ==> Left)", descx);
}
dlgGroup("Sort Y")
{
dlgRadioButton("A&scending (Bottom ==> Top)", descy);
dlgRadioButton("D&escending (Top ==> Bottom)", descy);
}
}
dlgSpacing(10);
dlgHBoxLayout
{
dlgStretch(1);
dlgPushButton("Start") dlgAccept();
dlgPushButton("Cancel") dlgReject();
dlgStretch(1);
}
};
if (iResult == 0) exit(0);
///////////////////////////////////////////
// Extract Parts
///////////////////////////////////////////
strForbiddenNames = " ";
schematic(SCH)
{
// find elements to rename
SCH.sheets(SH)
{
if (iWhat == 0)
{ // All elements
SH.parts(P)
{
AppendPartToRename(P);
}
}
else if (iWhat == 1)
{ // Only elements inside rectangle(s) on layer 95 (Names)
SH.rectangles(R)
{
if (R.layer == 95)
{
SH.parts(P)
{
if (isPartInRectangle (P, R)) AppendPartToRename(P);
}
}
}
}
}
// find forbidden names
SCH.parts(P)
{
if (strstr(strOldNames, " " + P.name + " ") < 0) strForbiddenNames += P.name + " ";
}
}
//dlgMessageBox (" " + strOldNames + " " + strForbiddenNames);
if (iCount == 0)
{
dlgMessageBox ("There are no parts to rename.");
exit(0);
}
// check if temporary names are available
for (i=0; i This name is needed for temporarly renaming the parts.");
exit (2);
}
}
///////////////////////////////////////////
// Sort Arrays
///////////////////////////////////////////
if (descy) DescendingY(); // change sign of y-coordinate
if (descx) DescendingX(); // change sign of x-coordinate
sort(iCount, sortidx, sh, y, x);
if (descy) DescendingY(); // change sign of y-coordinate
if (descx) DescendingX(); // change sign of x-coordinate
///////////////////////////////////////////
// Determine new names
///////////////////////////////////////////
int iNumber=0;
string strNewName;
for (i=0; i A part with this name already exists and could not be renamed. It's outside the rectangle.");
exit (2);
}
newName[idx] = strNewName;
}
for (i=0; i