forked from robertstarr/ulp_user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group-set-value.ulp
200 lines (167 loc) · 4.41 KB
/
group-set-value.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#usage "<b>Change value for all parts selected by group command in a schematic</b><p>"
"<author>http://www.bobstarr.net</author>";
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2010, Robert E. Starr (http://www.bobstarr.net)
//
// REVISION HISTORY:
//
// v1.00 - 09/22/2010 Initial Development
//
//////////////////////////////////////////////////////////////////////////////
//
// THIS PROGRAM IS PROVIDED AS IS AND WITHOUT WARRANTY OF ANY KIND,
// EXPRESSED OR IMPLIED. IF YOU DON'T LIKE IT, DON'T USE IT!
//
//////////////////////////////////////////////////////////////////////////////
string Version = "1.01";
string fileName;
string strNewValue;
string strCmd; // script command text
string strValue;
string strRVal[];
int nSelValue = 0;
//////////////////////////////////////////////////////////////////////////////
// Get count of items selected
int GetSelCount(UL_SCHEMATIC sch)
{
int cnt = 0;
sch.parts(P)
{
P.instances(I)
{
if (ingroup(I))
{
// make sure it has a package and name
if (P.device.package && P.name)
++cnt;
}
}
}
return cnt;
}
void CalcRVals()
{
string t;
int A=0,C=0,ndx=0;
real a,b,e,f=10;
do
{
e = C;
do
{
a = A;
b = (((round((exp(log(10)*(a/96)))*100))/100)*(pow(f,e)));
if (C == 0){
sprintf(t,"%1.2f", b);
}
if (C == 1){
sprintf(t,"%2.1f", b);
}
if (C == 2){
sprintf(t,"%3.0f", b);
}
if (C == 3){
b = b/1000;
sprintf(t,"%1.2fk", b);
}
if (C == 4){
b = b/1000;
sprintf(t,"%2.1fk", b);
}
if (C == 5){
b = b/1000;
sprintf(t,"%3.0fk", b);
}
if (C == 6){
b = b/1000000;
sprintf(t,"%1.2fM", b);
}
if (C == 7){
b = b/1000000;
sprintf(t,"%2.1fM", b);
}
A++;
strRVal[ndx++] = t;
} while (A < 96);
A=0;
a=0;
++C;
} while (C < 7);
a = 96;
e = C;
b = (((round((exp(log(10)*(a/96)))*100))/1000)*(pow(f,e)));
b = b/1000000;
sprintf(t,"%2.1fM", b);
strRVal[ndx++] = t;
}
void OnComboChangeValue()
{
strNewValue = strRVal[nSelValue];
}
//////////////////////////////////////////////////////////////////////////////
// Script Entry Point
if (schematic)
{
schematic(SCH)
{
fileName = filesetext(SCH.name, "_ChangeValues.scr");
string title = "Group Set Value - v" + Version;
if (GetSelCount(SCH) == 0)
{
dlgMessageBox("No group selected!");
exit(0);
}
CalcRVals();
int Result = dlgDialog(title)
{
dlgHBoxLayout
{
dlgGroup("Attribute")
{
dlgGridLayout
{
dlgCell(1,0) dlgLabel("Part Value");
dlgCell(1,1) dlgStringEdit(strNewValue);
dlgCell(2,0) dlgLabel("Resistor Values");
dlgCell(2,1) dlgComboBox(strRVal, nSelValue) OnComboChangeValue();
}
}
}
dlgHBoxLayout
{
dlgPushButton("OK") dlgAccept();
dlgPushButton("-Cancel") dlgReject();
}
};
if (!Result)
exit(0);
int cnt = 0;
strCmd = "";
SCH.parts(P)
{
P.instances(I)
{
if (ingroup(I))
{
// make sure it has a package and name
if (P.device.package && P.name)
{
string tmp;
sprintf(tmp, "VALUE %s '%s';\n", P.name, strNewValue);
strCmd += tmp;
++cnt;
}
}
}
}
if (!cnt)
dlgMessageBox("No items selected!");
exit(strCmd);
}
}
else
{
dlgMessageBox("Start this ULP in Schematic!", "OK");
}
// End-Of-File