forked from robertstarr/ulp_user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
change-part-values.ulp
171 lines (143 loc) · 4.32 KB
/
change-part-values.ulp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#usage "<b>Global Search/Replace Part Values</b> - v1.00 (02/28/2010)<p>"
"This ULP generates a script to replaces all part values that match "
"a given search value with a new user specified part value."
"<p>"
"<author>http://www.bobstarr.net</author>";
//////////////////////////////////////////////////////////////////////////////
//
// GLOBAL SEARCH/REPLACE PART VALUE(S)
//
// Copyright (C) 2009-2010, Robert E. Starr (http://www.bobstarr.net)
//
// REVISION HISTORY:
//
// v1.00 - 05/14/2009 (RES) - Initial Release
//
//////////////////////////////////////////////////////////////////////////////
//
// THIS PROGRAM IS PROVIDED AS IS AND WITHOUT WARRANTY OF ANY KIND,
// EXPRESSED OR IMPLIED.
//
//////////////////////////////////////////////////////////////////////////////
string Version = "1.00";
string fileName;
int fScriptExec = 0; // execute script automatically after generating
string strOldValue = "(TBD)";
string strNewValue = "(TBD)";
//////////////////////////////////////////////////////////////////////////////
// trim all spaces from a string
string trimSpaces(string source)
{
if (!source)
return source;
string result;
int i;
int cnt=0;
for (i=0; source[i]; i++) {
if (isspace(source[i]))
continue;
result[cnt] = source[i];
cnt++;
}
return result;
}
// trim spaces on left and on right of string
string trimString(string source) {
if(!source) return source;
string result;
int i, head = 0;
for (i = 0; source[i]; i++) {
if (!isspace(source[i])) {
head = i;
break;
}
}
int send = strlen(source);
int len = send;
if (len) {
for (i = len-1; i >= 0; i--) {
if (!isspace(source[i])) {
send = i+1;
break;
}
}
}
return strsub(source, head, send-head);
}
//////////////////////////////////////////////////////////////////////////////
// Normalize Upper Case - force all other VALUE fields to upper case
int doReplaceValue(UL_PART part)
{
string strValue = trimString(part.value);
string strNewVal = trimString(strNewValue);
if (strValue == strOldValue)
{
printf("# replace '%s' from '%s' to '%s'\n", part.name, strValue, strNewVal);
printf("VALUE %s '%s';\n\n", part.name, strNewVal);
return 1;
}
return 0;
}
//////////////////////////////////////////////////////////////////////////////
// Script Entry Point
if (schematic)
{
schematic(SCH)
{
fileName = filesetext(SCH.name, "_ChangePartValue~~~.scr");
string title = "Search/Replace Part Values v" + Version;
int Result = dlgDialog(title)
{
dlgHBoxLayout
{
dlgGroup("Global Search/Replace Value")
{
dlgGridLayout
{
dlgCell(1,0) dlgLabel("Find all part(s) with value:");
dlgCell(1,1) dlgStringEdit(strOldValue);
dlgCell(2,0) dlgLabel("Repace with new value:");
dlgCell(2,1) dlgStringEdit(strNewValue);
}
}
}
dlgHBoxLayout
{
dlgPushButton("OK") dlgAccept();
dlgPushButton("-Cancel") dlgReject();
dlgCheckBox("&Execute Script", fScriptExec);
}
};
if (!Result)
exit(0);
output(fileName, "wtD")
{
printf("# 'generated by change-part-values.ulp v%s, exported from;\n", Version);
printf("# '%s at %s;\n", SCH.name, t2string(time()));
printf("# '%s;\n\n", EAGLE_SIGNATURE);
SCH.sheets(S)
{
printf("#\n# SHEET %d - NORMALIZE PART VALUES\n#\n", S.number);
printf("EDIT .s%d\n", S.number);
S.parts(P)
{
if (P.device.package && P.name)
{
// Otherwise force all value text to upper case
doReplaceValue(P);
}
}
}
printf("EDIT .s1\n");
}
if (fScriptExec)
exit ("SCRIPT '" + fileName + "';");
else
exit(0);
}
}
else
{
dlgMessageBox("Start this ULP in Schematic!", "OK");
}
// End-Of-File