File: find.ulp

package info (click to toggle)
eagle 5.10.0-2
  • links: PTS
  • area: non-free
  • in suites: squeeze
  • size: 88,616 kB
  • ctags: 720
  • sloc: makefile: 33; sh: 24
file content (1180 lines) | stat: -rw-r--r-- 41,892 bytes parent folder | download
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
#usage "en: nobr<b>Find elements in schematic/board and zoom in</b>\n"
       "<p>"
       "Centers the object and zooms into the drawing."
       "<p>"
       "<h3>You can also run this ULP from the command line:</h3><p>"
       "Usage: RUN find [ <i>name</i> [ pin | pad | [value CH new_value] [ count | * ]]"
       "<p>"
       "RUN find<br>"
       "RUN find name<br>"
       "RUN find name [counter]<br>"
       "RUN find [DEV | GATE | PIN | PAD | POLYGON width | DRILL diameter | VIA stack | <i>value</i> [-S|+|-] [counter | *]] <b>**</b><br>"
       "RUN find DRILL diameter [counter | *]<b> **</b><br>"
       "RUN find <i>current-value</i> CH new-value [counter]<br>"
       "RUN find <i>value</i> -S<br>"
       "RUN find <i>value</i> <b>+</b> | <b>-</b> (step option)<br>"
       "</nobr>"
       "Search string is the <b>name</b> of the Device/Package/Net/Bus/Pin/Pad/Signal/Value<p>"
       "<b>counter</b> specifies the number of elements that shall be found before ending the search<br> "
       "<b>*</b> sets the counter to 1000<p>"
       "<b>PIN</b> | <b>PAD</b> | <b>DEV</b> | <b>GATE</b> additionally searches for PIN, PAD, GATE, DEVICE names<br>"
       "<b>GATE</b> without a given name, places the foremost found, unused gate<br>"
       "<b>GATE *</b> lists all unused gates, select one of them to place it<br>"
       "<b>VIA</b> <i>start end</i> searches for blind, buried, and micro vias with a certain length<br>"
       "<i>value</i><b>CH</b><i>value</i> replaces the value of an element with the given new one, if found (CH is case sensitive)<br>"
       "<i>value</i> <b>-S</b> displays all elements with the same value at the same time (highlighted like with SHOW), in BRD only<br>"
       "<i>value</i> <b>-</b> <b>+</b> shows step by step the previous or next found element, in BRD and SCH<br>"
       "<hr> "
       "Searching order:<br>"
       "<table>"
       "<tr><td><u>Schematic</u>:</td> <td><u>Board</u>:</td><td> </td></tr>"
       "<tr><td>1. Part name</td> <td>1. Element</td><td> </td></tr>"
       "<tr><td>2. Net name</td> <td>2. Signal/Wires/Vias</td><td> </td></tr>"
       "<tr><td>3. Bus name</td> <td>3. Pads</td><td> </td></tr>"
       "<tr><td>4. Value</td> <td>4. Value</td><td><nobr>Searching for values is not case sensitive.</nobr></td></tr>"
       "<tr><td>5. Device **</td> <td>5. Polygon width **</td><td></td></tr>"
       "<tr><td>6. Gate **</td> <td>6. Drill</td><td> </td></tr>"
       "<tr><td>7. Pin **</td> <td>7. Via stack</td><td> </td></tr>"
       "<tr><td>8. Pad **</td> <td></td><td> </td></tr>"
       "</table>"
       "** Device name, Gate name, Pin name, Pad name, Polygon width, or Drill diameter will be searched,  if one of the options DEV, GATE, PIN, PAD, POLYGON or DRILL is given.<p>"
       "</nobr>"
       "In symbol editor you can search at PIN name, in package editor you can search at PAD/SMD name<br>"
       "<author>Author: support@cadsoft.de</author>"
       ,
       "de: <nobr>Findet Elemente in Schaltplan und Board</b>"
       "<p>"
       "Zoomt das gefundene Element in die Fenstermitte"
       "<p>"
       "<h3>Sie können das ULP auch aus der Kommandozeile starten mit:</h3><p>"
       "RUN find [ <i>name</i> [ pin | pad | value [CH new_value] [ count | * ]]"
       "<br>"
       "RUN find<br>"
       "RUN find name<br>"
       "RUN find name [Z&auml;hler]<br>"
       "RUN find [DEV | GATE | PIN | PAD | POLYGON width | DRILL diameter | VIA stack | value [-S|+|-] [Z&auml;hler | *]] <b>**</b><br>"
       "RUN find DRILL Durchmesser [Z&auml;hler | *]<b> **</b><br>"
       "RUN find alter-value CH neuer-value [Z&auml;hler]<br>"
       "RUN find <i>value</i> -S<br>"
       "RUN find <i>value</i> <b>+</b> | <b>-</b> (Step-Option)<br>"
       "<br>"
       "Suchbegriff ist der <b>name</b> des Device/Package/Net/Bus/Pin/Pad/Signal/Value<br>"
       "<b>Z&auml;hler</b> legt die Anzahl der gefundenen Elemente fest, nach der die Suche beendet wird<br>"
       "<b>*</b> setzt den Z&auml;hler auf 1000<br>"
       "<b>PIN</b> | <b>PAD</b> | <b>DEV</b> | <b>GATE</b> sucht zus&auml;tzlich nach PIN-, PAD-, GATE-, DEVICE-Namen<br>"
       "<b>GATE</b> ohne Namen, platziert das zuerst gefundene, nicht benutzte Gate.<br>"
       "<b>GATE *</b> listet alle nicht benutzen Gates, das aus der Liste gewählte Gate wird plaziert.<br>"
       "<b>VIA</b> <i>start end</i> sucht Blind- Buried- und Micro-Via einer bestimmten L&aumlnge<br>"
       "<i>value</i> <b>CH</b> <i>value</i> ersetzt den Value des gefundenen Elements (CH beachtet die Gross-/Klein-Schreibung)<br>"
       "<i>value</i> <b>-S</b> zeigt alle Elemente mit gleichen Values gleichzeitig (gehighlightet wie bei SHOW), nur in BRD.<br>"
       "<b>-</b> <b>+</b> zeigt die gefundenen Elemente Schritt für Schritt (+ vor, - zur&uuml;ck), in BRD und SCH<br>"
       " <hr> "
       "Such-Reihenfolge:<br>"
       "<table>"
       "<tr><td><u>Schematic</u>:</td> <td><u>Board</u>:</td><td> </td></tr>"
       "<tr><td>1. Part name</td> <td>1. Element</td><td> </td></tr>"
       "<tr><td>2. Net name</td> <td>2. Signal/Wires/Vias</td><td> </td></tr>"
       "<tr><td>3. Bus name</td> <td>3. Pads</td><td> </td></tr>"
       "<tr><td>4. Value</td> <td>4. Value</td><td><nobr>Keine Unterscheidung der Gro&szlig;-/Kleinschreibung.</nobr></td></tr>"
       "<tr><td>5. Device **</td> <td>5. Polygon width **</td><td></td></tr>"
       "<tr><td>6. Gate **</td> <td>6. Drill</td><td> </td></tr>"
       "<tr><td>7. Pin **</td> <td>7. Via stack</td><td> </td></tr>"
       "<tr><td>8. Pad **</td> <td></td><td> </td></tr>"
       "</table>"
       "** nach Device-, Gate-, Pin-, Pad-Namen, Polygon-Width und Drill-Durchmesser wird gesucht, falls DEV, GATE, PIN, PAD, POLYGON oder DRILL gesetzt ist.<br>"
       "</nobr>"
       "Im Symbol-Editor kann nach Pin-Name, im Package-Editor kann nach Pad/Smd-Name gesucht werden.<p>"
       "<author>Author: support@cadsoft.de</author>";

// THIS PROGRAM IS PROVIDED AS IS AND WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED


// Version 1.1  2005.06.15  - CH : search and replace Value / Suchen und ersetzen das Value alf@cadsoft.de
//                            Zuweisung von vfind berichtigt, es konnten nur Values mit Großschreibung gefunden werden.
//                            durchsuchen von Netz-Namen in Bussen berichtigt.
// Version 1.2  2005.07.19  - Search also in Polygon - contour - wire
//
// Version 1.3  2005.11.14  - Search Part_Name
//
// Version 1.4  2006.04.25  - Show all parts with same Value in Board
//
// Version 1.5  2006.05.08  - Clip zoom coordinate for show to maximum
//
// Version 1.6  2006.09.26  - Find also (Device+)GATE-name
//
// Version 1.7  2006.11.09  - +/- Trace step by step with value
//                            ein neuer Suchbegriff setzt den Trace-counter auf 0
//
// Version 1.8  2007.02.13  - Find Net without Segment-Wire, but with Pinref
//
// Version 1.9  2007.02.23  - Find Polygons with Wire-Width
//                            Zuweisung von vfind als Kommadozeileneingabe berichtigt
//                            In Bus-Namen werden jetzt auch Netze in der Schreibweise "D[0..7],A[0..15]" gefunden
//                            Falls der Layer des gefundenen Element nicht Visible ist wird er eingeschaltet
//
// Version 2.0  2007.04.23  - Find Drills (Pad, Via, Hole - Diameter)
//                            GATE
//                            VIA stack, sucht Vias von Layer bis Layer
//
// Version 2.1  2007.06.27  - Erst die Anzahl der gefundenen Elemente anzeigen, dann mit SHOW markieren,
//                            damit man anschliessend mit WINDOW bzw. Scroll-Rad zoomen kann ohne daß die
//                            Markierung (highlighten) aufgehoben wird.
//                            Abfrage des Zähler argc für die zu suchende Anzahl berichtigt.
//
// Version 2.2  2007.07.05  - Hilfe in #usage  en: de: integriert.
//
// Version 2.3  2007.10.16  - Find PIN in Symbol
//                          - Find PAD/SMD in Package
//
// Version 2.4  2008.06.10  - Window-Befehl für SCH angepasst,
//                            Zoomfenster in SCH über Area berechnet
//                            Zähler für Option PAD/PIN/DEV berichtigt
//                            require 5.0.1
//


#require 5.0001;
string Version = "Version 2.4";
string find;
string vfind;
string NewValue;
string ChangeValue;
int    change_value = 0;
string again;
string fpin;
string fndpin = "Element";
string foundelement = "";

enum                  { sNull, sPin,  sPad,  sDevice, sGate,  sValue };
string SCHfPinPad[] = { "",    "PIN", "PAD", "DEV",   "GATE", "VALUE"};

enum                  { bNull, bPad,  bValue,  bPolygon,  bDrill,  bVia };
string BRDfPinPad[] = { "",    "PAD", "VALUE", "POLYGON", "DRILL", "VIA" };
                     // for "POLYGON", "DRILL", "VIA" see also function  returnfind()  and function  show_B()

string Invoke[] ;           // invoke list of not placed gates

int    Vstart;
int    Vend;

int    fcnt = 0;
int    cntstep = 0;
string stepfile = "";
int    all;
int    cnt;
int    StepMode = 0;        // for trace vorward/backward of elements for show
int    Result;
real   lastZoom = 0;
int    lastSheet = 0;
real   PolyWidth = 0;
real   DrillDiam = 0;

int    optshow   = 0;       // Only board. Option to manually placing 2006.04.25
int    display_layer[];


int test = 0;

string fileName = argv[0];
string scriptfile = filesetext(fileName, "$$$.scr");

int gridunit;
string unit[] = { "Micron", "mm", "Mil", "Inch" };

string repeat = "";

// ### Functions ###
real u2u(int val) {
  switch (gridunit) {
    case GRID_UNIT_MIC  : return u2mic(val);
    case GRID_UNIT_MM   : return u2mm(val);
    case GRID_UNIT_MIL  : return u2mil(val);
    case GRID_UNIT_INCH : return u2inch(val);
  }
}

string dpbacksl(string fs) {
  int l = 0;
  do {
    if (fs[l] == '\\') {
      string fs1 = strsub(fs, 0 , l + 1);
      string fs2 = strsub(fs, l + 1 );
      fs = fs1 + "\\" + fs2;
      l += 2;
      }
    l++;
  } while (fs[l]);
  return fs;
}


string check_layer(void) {
  board(B) {
    B.layers(L) {
      display_layer[L.number] = L.visible;
      string s;
      if (L.number == 21 || L.number == 22 || L.number == 25 || L.number == 26 || L.number == 27 || L.number == 28 || L.number == 51 || L.number == 52 ) {
        if (L.visible) return "DISPLAY NONE 21 -23 25 27 51 22 -24 26 28 52;\n"; // display only Top layer
      }
      else if (L.visible) return "DISPLAY NONE 21 -23 25 27 51 22 -24 26 28 52;\n"; // display only Top layer
    }
  }
  return "";
}


void showrepeat(string text) {
  dlgDialog("FIND.ULP") {
    dlgHBoxLayout dlgSpacing(600);
    dlgHBoxLayout {
      dlgVBoxLayout dlgSpacing(300);
      dlgTextEdit(text);
    }
    dlgHBoxLayout {
      dlgPushButton("+&OK") dlgAccept();
      dlgStretch(1);
    }
  };
  return;
}


string returnfind(void) {
  string rs;
  if (!fpin) fndpin = "Element";

  if (fpin == "POLYGON")    sprintf(rs, "run ulpmessage.ulp '%d %s found!';\n", fcnt, fndpin);
  else if (fpin == "DRILL") sprintf(rs, "run ulpmessage.ulp '%d %s found!';\n", fcnt, fndpin);
  else if (fpin == "VIA")   sprintf(rs, "run ulpmessage.ulp '%d %s found!';\n", fcnt, fndpin);
  else if (StepMode){
    if (StepMode == fcnt) exit(repeat);
    else repeat = "";    // no message while step mode
    return "";
  }
  else sprintf(rs, "run ulpmessage.ulp '%d %s(s) <b>%s</b> found!' '%s';\n", fcnt, fndpin, find, foundelement); // 2007.03.23 alf

  if (find) {
    if (cntstep) {
      if (cntstep > fcnt) {
          output(stepfile, "wt") printf("%d\n%s\n%d", fcnt, vfind, cntstep);  // write actual counter in file
      }
      else return "";  // for Trace step by step disply no message
    }
  }
  return dpbacksl(rs);
}


void check(string repeat) {
  if (optshow) {
    if (test) showrepeat(repeat);
    if (fcnt) {
      exit(repeat);
    }
    return;
  }
  repeat = returnfind() + repeat;
  if (test) showrepeat(repeat);
  exit (repeat); // first messagebox than show 2007.06.27 alf
}


void helpULP(void) {
  dlgDialog("find.ulp")  {
    dlgHBoxLayout dlgSpacing(550);
    dlgLabel(usage);
    dlgHBoxLayout {
      dlgStretch(1);
      dlgPushButton("+OK") dlgAccept();
      dlgStretch(1);
    }
  };
  return;
}


string getfind() {
  real Dmin = 0.0, Dmax = u2u(13100);
  string f;
  all = 0;
  int sel_m = 0;
  int findpoly = 0;
  Result = dlgDialog("Find Element"){
    dlgHBoxLayout {
      dlgVBoxLayout {
        dlgHBoxLayout {
          dlgLabel("&Name ");
          dlgStringEdit(f);
          dlgLabel(" (Value) ");
          dlgSpacing(30);
          dlgStretch(1);
          dlgPushButton("&Help") helpULP();
        }
        dlgHBoxLayout {
          dlgLabel("&Counts");
          dlgIntEdit(all, 0, 10000);
          dlgSpacing(200);
          dlgStretch(1);
          dlgLabel(Version);
          dlgSpacing(12);
        }
        dlgHBoxLayout {
          if (schematic) {
            dlgGroup("Find options") {
              dlgRadioButton("&...", sel_m) fpin = "";
              dlgRadioButton("P&IN", sel_m)  { fpin = "PIN"; }
              dlgRadioButton("P&AD", sel_m)  { fpin = "PAD"; }
              dlgRadioButton("&DEV", sel_m)  { fpin = "DEV"; }
              dlgRadioButton("&GATE", sel_m) { fpin = "GATE"; }
              dlgHBoxLayout {
                dlgRadioButton("&VALUE", sel_m) fpin = "";
                dlgSpacing(22);
                dlgCheckBox(" &change to ", change_value);
                dlgLabel(" Val&ue ");
                dlgStringEdit(NewValue);
                dlgStretch(1);
              }
            }
          }
          if (board) {
            dlgGroup("Find options") {
              dlgRadioButton("&...", sel_m) fpin = "";
              dlgRadioButton("P&AD", sel_m)  fpin = "PAD";
              dlgHBoxLayout {
                dlgRadioButton("&VALUE", sel_m) fpin = "";
                dlgSpacing(12);
                dlgCheckBox(" &change to", change_value) if (change_value) optshow = 0;
                dlgLabel("Val&ue ");
                dlgStringEdit(NewValue);
                dlgSpacing(32);
                dlgCheckBox("Sh&ow all ", optshow) if (optshow) change_value = 0;
              }
              dlgHBoxLayout {
                dlgRadioButton("POL&YGON", sel_m)  fpin = "PPOLYGON";
                dlgSpacing(65);
                dlgLabel(" &Width ");
                dlgRealEdit(PolyWidth, 0, 10000);
                dlgSpacing(90);
                dlgStretch(1);
              }
              dlgHBoxLayout {
                dlgRadioButton("&DRILL", sel_m)  fpin = "DRILL";
                dlgSpacing(73);
                dlgLabel(" Diamete&r ");
                dlgRealEdit(DrillDiam, Dmin, Dmax);
                dlgSpacing(90);
                dlgStretch(1);
              }
              dlgHBoxLayout {
                dlgRadioButton("V&IA  layer stack", sel_m)  fpin = "VIA";
                dlgSpacing(50);
                dlgLabel(" &Start ");
                dlgIntEdit(Vstart, 0, 16);
                dlgSpacing(12);
                dlgLabel(" &End ");
                dlgIntEdit(Vend, 0, 16);
                dlgSpacing(90);
                dlgStretch(1);
              }
            }
            dlgStretch(1);
          }
        }
        dlgStretch(0);
        dlgHBoxLayout {
          dlgPushButton("+&Find") {
            dlgAccept();
            all--;
          }
          dlgStretch(1);
          dlgPushButton("-Cancel") { dlgReject(); exit(-1); }
        }
        dlgStretch(1);
      }
    }
  };
  if (!f && fpin == "GATE") f = "0";
  return f;
}


real clip_zoom(real v) {  // clip value to max. coordinate 2006.05.08
  switch (gridunit) {
    case GRID_UNIT_MIC  : if (v >  838200) return  838200;
                          if (v < -838200) return -838200;
                          break;
    case GRID_UNIT_MM   : if (v >  838.2)  return  838.2;
                          if (v < -838.2)  return -838.2;
                          break;
    case GRID_UNIT_MIL  : if (v >  33000.0)  return  33000;
                          if (v < -33000.0)  return -33000;
                          break;
    case GRID_UNIT_INCH : if (v >  33.0)  return  33;
                          if (v < -33.0)  return -33;
                          break;
  }
  return v;
}


// #### make script line for show in board ####
string show_B(real x, real y, real zoom1, real zoom2, string findb, int fist, int layer) {
  fcnt++;
  string cmd = "";
  string cmd_show;
//  sprintf(cmd_show, "SHOW '%s';\n", findb);
  sprintf(cmd_show, ";SHOW '%s' ", findb); // 2007.06.27 alf
  if (fpin == "PAD") cmd_show = "";  // can not show pads
  if (fpin == "POLYGON") sprintf(cmd_show, ";SHOW (%.4f %.4f);\n", x, y);  // do not show polygons
  // ### can not show drills ###
  if (fpin == "DRILL")   cmd_show = "";     // do not change this line
  // ### can not show vias, only complete signal ###
  if (fpin == "VIA") { cmd_show = ""; layer = 0; }  // do not change this line

  if (optshow) {
    sprintf(cmd, "%s", cmd_show);
  }
  else {
    if (lastZoom) {
      if (StepMode) {
        sprintf(cmd, "\n;WINDOW (%.6f %.6f) ;\n%s",
                     x, y,
                     cmd_show
               );
      }
      else {
        sprintf(cmd, "\n;WINDOW (%.6f %.6f) (%.6f %.6f) (%.6f %.6f);\n%s;\n",
                     x, y,
                     x, y,
                     x, y,
                     cmd_show
               );
      }
    }
    else {
      if (StepMode) {
        sprintf(cmd,
                    ";\nWINDOW (%.6f %.6f);\n%s",
                    x, y,
                    cmd_show
               );
      }
      else {
        sprintf(cmd, ";WINDOW FIT;\n"
                     ";WINDOW (%.6f %.6f) (%.6f %.6f) (%.6f %.6f);\n%s",
                     x, y,
                     clip_zoom(x + zoom1), y,
                     clip_zoom(x + zoom2), y,
                     cmd_show
               );
        lastZoom = zoom2;
      }
    }
    if (ChangeValue == "CH") {
      string chval;
      sprintf(chval, "VALUE %s '%s';\n", findb, NewValue);
      cmd += chval;
    }
  }
  if (!display_layer[layer] && layer != 0) {
    sprintf(cmd_show, "DISPLAY %d;\n%s", layer, cmd);
    cmd += cmd_show;
  }
  if (fpin == "VIA") {
    sprintf(cmd_show, "DISPLAY %d %d 18;\n", Vstart, Vend);
    cmd += cmd_show;
  }
  return cmd;
}


// #### make script line for show in schematic ####
string show_S(int s, real x1area, real y1area, real x2area, real y2area, string finds) {
  fcnt++;
  string cmd_show;
  sprintf(cmd_show, ";SHOW '%s' ", finds); // 2007.06.27 alf
  string cmd = "";
  if (s != lastSheet) {
    lastSheet = s;
    if (StepMode) {
      sprintf(cmd, ";\nEDIT .s%d;\nWINDOW (%.6f %.6f) (%.6f %.6f);\n%s", s,
                   x1area, y1area,
                   x2area, y2area,
                   cmd_show
             );
    }
    else {
      sprintf(cmd, ";\nEDIT .s%d;\nWINDOW (%.6f %.6f) (%.6f %.6f);\n%s", s,
                   x1area, y1area,
                   x2area, y2area,
                   cmd_show
             );
    }
  }
  else {
    if (StepMode) {
      sprintf(cmd, ";\nWINDOW (%.6f %.6f) (%.6f %.6f);\n%s", s,
                   x1area, y1area,
                   x2area, y2area,
                   cmd_show
             );
    }
    else {
      sprintf(cmd, ";\nEDIT .s%d;\nWINDOW (%.6f %.6f) (%.6f %.6f);\n%s", s,
                   x1area, y1area,
                   x2area, y2area,
                   cmd_show
             );
    }
  }
  if (ChangeValue == "CH") {
    string chval;
    sprintf(chval, "VALUE %s '%s';\n", finds, NewValue);
    cmd += chval;
  }

  if (StepMode) {
    if (cntstep != fcnt) cmd = "";
  }
  return cmd;
}


real zfactor(real x1, real y1, real x2, real y2) {
  return sqrt( pow(x2 - x1, 2) + pow(y2 - y1, 2) );
}



// *** split bus-name from net-name ***
int findBus(string name, string sfind) {
  string bn[];
  int b;
  b = strsplit(bn, name, ':');
  string nn[];
  if (b == 2) {
    b = strsplit(nn, bn[1], ',');
  }
  else {
    b = strsplit(nn, name, ',');
  }
  for (int x = 0; x < b; x++) {
    if(nn[x] == sfind) return 1;
  }
  // *** search for name[n..n] ***
  string nm;
  for (x = 0; x < b; x++) {
    int pos1 = strchr(nn[x], '[');
    int pos2 = strchr(nn[x], '.');
    int pos3 = strchr(nn[x], ']');
    string Pref = strsub(nn[x], 0 , pos1);
    string n1 = strsub(nn[x], pos1+1, pos2-pos1-1);
    string n2 = strsub(nn[x], pos2+2, pos3-pos2-2);
    for (int n = strtol(n1); n <= strtol(n2); n++) {
      sprintf(nm, "%s%d", Pref, n);
      if (nm == sfind) return 1;
    }
  }
  return 0;
}



// *** trace elemete step by step ***
string get_step(int step) {
  StepMode = 1;
  cntstep = 0;
  string s = "";
  string lastvalue;
  stepfile = filesetext(argv[0], ".stp");
  string sf[];
  int isfile = fileglob(sf, stepfile);
  if (isfile) {
    string t[];
    int ct = fileread(t, stepfile);
    cntstep = strtod(t[0]);
    if (vfind != t[1]) cntstep = 0;
  }
  cntstep += step;
  if (cntstep < 1) {
    cntstep = 1;
    dlgMessageBox("!This is the first Element", "OK");
  }
  output(stepfile, "wt") printf("%d\n%s", cntstep, vfind);  // write actual counter in file
  sprintf(s, "%d", cntstep);
  return s;
}


string get_invoke(void) {
  int sel;
  int Result = dlgDialog("Invoke unused gates") {
    dlgListView("Gates to Invoke", Invoke, sel) { dlgAccept(); return Invoke[sel]; }
    dlgHBoxLayout {
      dlgPushButton("OK") dlgAccept();
      dlgPushButton("-Cancel") dlgReject();
      dlgStretch(1);
    }
  };
  if (Result) return Invoke[sel];
  return "";
}



// ****** Main ******

vfind = argv[1];
if (argc > 2) again = strupr(argv[argc-1]);  // 2007.06.27 alf
if (argv[2] == "+") { again = get_step(1);  StepMode = strtod(again); }
if (argv[2] == "-") { again = get_step(-1); StepMode = strtod(again); }

if (symbol) symbol(S) {  // 2007.10.16
  vfind = strupr(argv[1]);
  if (!vfind) {
    dlgMessageBox(usage + "<br>" + Version);
    exit(0);
  }
  library(L) gridunit = (L.grid.unit);
  S.pins(P) {
    if (P.name == vfind) {
      sprintf(vfind, "WIN (%.4f %.4f);", u2u(P.x), u2u(P.y) );
      exit(vfind);
    }
  }
  exit("run ulpmessage.ulp '" + vfind + " not found!';\n");
}

else if (package) package(P) {  // 2007.10.16
  vfind = strupr(argv[1]);
  if (!vfind) {
    dlgMessageBox(usage + "<br>" + Version);
    exit(0);
  }
  library(L) gridunit = (L.grid.unit);
  P.contacts(C) {
    if (C.name == vfind) {
      sprintf(vfind, "WIN (%.4f %.4f);", u2u(C.x), u2u(C.y) );
      exit(vfind);
    }
  }
  exit("run ulpmessage.ulp '" + vfind + " not found!';\n");
}

else if (schematic) {
  if      ( strupr(argv[1]) == SCHfPinPad[1]) { fpin = SCHfPinPad[1]; vfind = argv[2]; } // "PIN"
  else if ( strupr(argv[1]) == SCHfPinPad[2]) { fpin = SCHfPinPad[2]; vfind = argv[2]; } // "PAD"
  else if ( strupr(argv[1]) == SCHfPinPad[3]) { fpin = SCHfPinPad[3]; vfind = argv[2]; } // "DEV"
  else if ( strupr(argv[1]) == SCHfPinPad[4]) {         // "GATE"
    fpin = SCHfPinPad[4];
    vfind = argv[2];
    if (!vfind) {     // found Gates are not placed in schematic
      vfind = "0";
    }
  }
  else if ( strupr(argv[1]) == SCHfPinPad[5]) { fpin = SCHfPinPad[5]; vfind = argv[2]; } // "VALUE"
  if (argc > 2) again =  strupr(argv[argc-1]);
  else again = "";
}

else if (board) {
  if      ( strupr(argv[1]) == BRDfPinPad[bPad])   { fpin = BRDfPinPad[bPad]; vfind = argv[2];   } // "PAD"
  else if ( strupr(argv[1]) == BRDfPinPad[bValue]) { fpin = BRDfPinPad[bValue]; vfind = argv[2]; } // "VALUE"
  else if ( strupr(argv[1]) == BRDfPinPad[bPolygon]) {  // "POLYGON"
    fpin = BRDfPinPad[bPolygon];
    find = BRDfPinPad[bPolygon];
    PolyWidth = strtod(argv[2]);
    if (argc > 3) again =  strupr(argv[argc-1]);
    else again = "";
  }
  else if ( strupr(argv[1]) == BRDfPinPad[bDrill]) {    // "DRILL"
    fpin = BRDfPinPad[bDrill];
    find = BRDfPinPad[bDrill];
    DrillDiam = strtod(argv[2]);
    if (argc > 3) again =  strupr(argv[argc-1]);
    else again = "";
  }
  else if ( strupr(argv[1]) == BRDfPinPad[bVia]) {      // "VIA"
    fpin = BRDfPinPad[bVia];
    find = BRDfPinPad[bVia];
    Vstart = strtod(argv[2]);
    Vend   = strtod(argv[3]);
    if (argc > 4) again =  strupr(argv[argc-1]);
    else again = "";
  }
}

else {
  if (language() == "de") dlgMessageBox("Starten Sie dieses ULP in einem Schaltplan, Board, Symbol oder Package Editor", "OK");
  else  dlgMessageBox("Start this ULP in Schematic, Board, Symbol or Package Editor", "OK");
  exit(0);
}

if (argv[3] == "CH") {
  ChangeValue = argv[2];
  change_value = 1;
  NewValue = argv[4];
}


if (again == "*")    all = 1000;
else  all = strtol(again) - 1;

if (!vfind) {
  vfind = getfind();
}
find = strupr(vfind);
if (!find && change_value) exit (0);
cnt = all + 1;

if (!fpin && !find) {
  dlgMessageBox("Missing options", "OK");
  exit(-1);
}


// *** Board coord. ***
if (board) {
  int mx, my;  // 2008.06.10 alf
  if (argv[2] == "-S") optshow   = 1;       // Show option 2006.04.25
  board(B) {
    gridunit = (B.grid.unit);
    if (optshow) {
      all = 10000;
      repeat = check_layer();
      repeat += ";SHOW;\nWIN;\nSHOW "; // refresh window clear showed elements // 2007.06.27 alf
    }

    mx = B.area.x2 + (B.area.x1 * -1);
    my = B.area.y2 + (B.area.y1 * -1);
    if (!fpin && find) {
      B.elements(E) {
        if (E.name == find) {
          fndpin = "Element";
          repeat += show_B(u2u(E.x), u2u(E.y), 2, 5, find, all, E.mirror);
          sprintf(foundelement, "Element %s on (%.4f %.4f)", E.name, u2u(E.x), u2u(E.y) );
          check(repeat);
        }
      }
      B.signals(S) {
        if (S.name == find) {
          fndpin = "Signal";
          S.contactrefs(C) {
            repeat += show_B(u2u(C.contact.x), u2u(C.contact.y), 2, 5, find, all, 0); // 0 = dummy for Layer
            if (all <= 0) check(repeat);
            all--;
          }
        }
      }
      B.signals(S) {
        if (S.name == find ) {
          S.wires(W) {
            fndpin = "Wire";
            real z = zfactor(u2u(W.x1), u2u(W.y1), u2u(W.x2), u2u(W.y2) );
            repeat += show_B( u2u((W.x1 + W.x2)/2), u2u((W.y1 + W.y2)/2), z/(z/2) , z/(z/5), find, all, W.layer);
            if (all <= 0) check(repeat);
            all--;
          }
        }
      }
      B.signals(S) {
        if (S.name == find ) {
          S.polygons(P) {
            fndpin = "Polygon";
            P.contours(W) {
              real z = zfactor(u2u(W.x1), u2u(W.y1), u2u(W.x2), u2u(W.y2) );
              repeat += show_B( u2u((W.x1 + W.x2)/2), u2u((W.y1 + W.y2)/2), z/(z/2) , z/(z/5), find, all, W.layer);
              if (all <= 0) check(repeat);
              all--;
              break;
            }
          }
        }
      }
      B.signals(S) {
        if (S.name == find ) {
          S.vias(V) {
            fndpin = "Via";
            repeat += show_B(u2u(V.x), u2u(V.y), 1, 5, find, all, 18);  // 18 dummy layer for via
            sprintf(foundelement, "Element on (%.4f %.4f) %s<br><b>VIA</b><br><table><tr><td>Layer</td><td>Diameter</td><td>Restring</td></tr><tr><td>Top</td><td>%.4f</td><td>%.4f</td></tr><tr><td>Inner</td><td>%.4f</td><td>%.4f</td></tr><tr><td>Bottom</td><td>%.4f</td><td>%.4f</td></tr><tr><td>Drill</td><td>%.4f</td></tr></table>",
                                                    u2u(V.x), u2u(V.y),
                                                    unit[gridunit],
                                                    u2u(V.diameter[1]),
                                                    u2u( (V.diameter[1] - V.drill) / 2),
                                                    u2u(V.diameter[2]),
                                                    u2u( (V.diameter[2] - V.drill) / 2),
                                                    u2u(V.diameter[16]),
                                                    u2u( (V.diameter[16] - V.drill) / 2),
                                                    u2u(V.drill) );
            if (all <= 0) check(repeat);
            all--;
          }
        }
      }
      B.elements(E) {
        if (E.value == vfind || E.value == find) {
          fndpin = "Value";
          if (StepMode && all > 0) {
            ; // do nothing
          }
          else {
            repeat += show_B(u2u(E.x), u2u(E.y), 2, 5, E.name, all, E.mirror);
            sprintf(foundelement, "Element %s on (%.4f %.4f)", E.name ,u2u(E.x), u2u(E.y) );
          }
          if (all <= 0) check(repeat);
          all--;
        }
      }
    }
    B.elements(E) {
      if (fpin == BRDfPinPad[bPad]) { // "PAD"
        E.package.contacts(C) {
          if (C.pad) {
            if (C.pad.name == find) {
              fndpin = "Pad/Smd";
              repeat += show_B(u2u(C.pad.x), u2u(C.pad.y), 2, 5, E.name, all, E.mirror);
              sprintf(foundelement, "<br>PAD <b>%s</b> on (%.4f %.4f) %s [Element %s]<br><table><tr><td>Layer</td><td>Diameter</td><td>Restring</td></tr><tr><td>Top</td><td>%.4f</td><td>%.4f</td></tr><tr><td>Inner</td><td>%.4f</td><td>%.4f</td></tr><tr><td>Bottom</td><td>%.4f</td><td>%.4f</td></tr><tr><td>Drill</td><td>%.4f</td></tr></table>",
                                     C.pad.name,
                                     u2u(C.pad.x), u2u(C.pad.y),
                                     unit[gridunit],
                                     E.name,
                                     u2u(C.pad.diameter[1]),
                                     u2u( (C.pad.diameter[1] - C.pad.drill) / 2),
                                     u2u(C.pad.diameter[2]),
                                     u2u( (C.pad.diameter[2] - C.pad.drill) / 2),
                                     u2u(C.pad.diameter[16]),
                                     u2u( (C.pad.diameter[16] - C.pad.drill) / 2),
                                     u2u(C.pad.drill) );
              if (all <= 0) check(repeat);
              all--;
            }
          }
          if (C.smd) {
            if (C.smd.name == find) {
              fndpin = "Pad/Smd";
              repeat += show_B(u2u(C.smd.x), u2u(C.smd.y), 2, 5, E.name, all, E.mirror);
              sprintf(foundelement, "<br>SMD <b>%s</b> on  (%.4f %.4f)  %s [Element %s]",
                                    C.smd.name,
                                    u2u(C.smd.x), u2u(C.smd.y),
                                    unit[gridunit],
                                    E.name );
              if (all <= 0) check(repeat);
              all--;
            }
          }
        }
      }
    }

    if (fpin == BRDfPinPad[bPolygon]) {  // "POLYGON"
      B.signals(S) S.polygons(P) {
        if (PolyWidth == u2u(P.width)) {
          fndpin = "Polygon";
          P.contours(W) {
            sprintf(fndpin, " Polygon with WIRE-Width %.4f", PolyWidth);
            repeat += show_B(u2u(W.x1), u2u(W.y1), 2, 5, S.name, all, P.layer);
            sprintf(foundelement, "<br>POLYGON in Layer %d on  (%.4f %.4f)  %s",
                                   P.layer,
                                   u2u(W.x1), u2u(W.y1),
                                   unit[gridunit] );
            break;
          }
          if (all <= 0) check(repeat);
          all--;
        }
      }
      B.polygons(P) {
        if (PolyWidth == u2u(P.width)) {
          fndpin = "Polygon";
          P.contours(W) {
            sprintf(fndpin, " Polygon with WIRE-Width %.4f", PolyWidth);
            repeat += show_B(u2u(W.x1), u2u(W.y1), 2, 5, "POLYGON", all, P.layer);
            sprintf(foundelement, "<br>POLYGON in Layer %d on  (%.4f %.4f)  %s",
                                   P.layer,
                                   u2u(W.x1), u2u(W.y1),
                                   unit[gridunit] );
            break;
          }
          if (all <= 0) check(repeat);
          all--;
        }
      }
    }
    if (fpin == BRDfPinPad[bDrill]) {  // "DRILL"
      B.elements(E) {
        E.package.contacts(C) {
          if (C.pad) {
            if (u2u(C.pad.drill) == DrillDiam) {
              sprintf(fndpin, " Drill %.4f", DrillDiam);
              repeat += show_B(u2u(C.x), u2u(C.y), 1, u2u(B.area.x2 - B.area.x1)/DrillDiam/10, "DRILL", all, 17);
              sprintf(foundelement, "<br>Drill %.4f on (%.4f %.4f) %s",
                                     DrillDiam, u2u(C.x), u2u(C.y), unit[gridunit]);
              if (all <= 0) check(repeat);
              all--;
            }
          }
        }
        E.package.holes(H) {
          if (u2u(H.drill) == DrillDiam) {
            sprintf(fndpin, " Drill %.4f", DrillDiam);
            repeat += show_B(u2u(H.x), u2u(H.y), 1, u2u(B.area.x2 - B.area.x1)/DrillDiam/10, "DRILL", all, 45);
            sprintf(foundelement, "<br>Hole %.4f on (%.4f %.4f) %s",
                                     DrillDiam, u2u(H.x), u2u(H.y), unit[gridunit]);
            if (all <= 0) check(repeat);
            all--;
          }
        }
      }
      B.signals(S) {
        S.vias(V) {
          if (u2u(V.drill) == DrillDiam) {
            sprintf(fndpin, " Drill %.4f", DrillDiam);
            repeat += show_B(u2u(V.x), u2u(V.y), 1, u2u(B.area.x2 - B.area.x1)/DrillDiam/10, "DRILL", all, 18);
            sprintf(foundelement, "<br>Dril %.4f in Via on (%.4f %.4f) %s",
                                     DrillDiam, u2u(V.x), u2u(V.y), unit[gridunit]);
            if (all <= 0) check(repeat);
            all--;
          }
        }
      }
      B.holes(H) {
        if (u2u(H.drill) == DrillDiam) {
          sprintf(fndpin, " Drill %.4f", DrillDiam);
          repeat += show_B(u2u(H.x), u2u(H.y), 1, u2u(B.area.x2 - B.area.x1)/DrillDiam/10, "DRILL", all, 45);
          sprintf(foundelement, "<br>Hole %.4f on  (%.4f %.4f) %s",
                                   DrillDiam, u2u(H.x), u2u(H.y), unit[gridunit]);
          if (all <= 0) check(repeat);
          all--;
        }
      }
    }
    if (fpin == BRDfPinPad[bVia]) {  // "VIA"
      B.signals(S) {
        sprintf(fndpin, "<b>VIA</b> stack %d-%d", Vstart, Vend);
        S.vias(V) {
          if (V.start == Vstart && V.end == Vend) {
            repeat += show_B(u2u(V.x), u2u(V.y), 2, 5, find, all, 0);
            if (all <= 0) check(repeat);
            all--;
          }
        }
      }
    }
  }
  if (repeat) check(repeat);
  string StepFound = "</b> not found!</nobr>";
  if (fpin == "VIA") sprintf(StepFound, "</b> %d-%d not found!", Vstart, Vend);
  if (StepMode) {
    get_step(-1);   // do not count upper while not found
    StepFound = "</b> no more found!</nobr>";
  }
  dlgMessageBox("<nobr><b>" + dpbacksl(find) + StepFound, "OK");
  exit (0);
}


// *** search and find in Schematic ***
if (schematic) {
  lastSheet = 0;
  schematic(S) {
    gridunit = (S.grid.unit);
    if (fpin == "GATE" && find == "0" || fpin == "GATE" && find == "*") {  // 2007.04.03 find not placed GATEs
      S.parts(PA) {
        PA.instances(I) {
          if (!I.sheet) {
            if (find == "0") {
              sprintf(repeat, "INVOKE %s %s\n", PA.name, I.gate.name);
              exit(repeat);
            }
            else {
              sprintf(Invoke[fcnt], "INVOKE %s %s\n", PA.name, I.gate.name);
              fcnt++;
            }
          }
        }
      }
      exit(get_invoke());
    }

    S.sheets(SH) {
      SH.parts(PA) {
        if (fpin == "DEV") {
          if (PA.device.name == find) {  // 2005.11.14 alf@cadsoft.de
            PA.instances(IN) {
              IN.gate.symbol.pins(P) {
                fndpin = "Dev";
                sprintf(foundelement, "DEVice %s : sheet %d on (%.4f %.4f)", IN.name , IN.sheet, u2u(IN.x), u2u(IN.y) );
                repeat += show_S(IN.sheet,
                                 u2u(IN.gate.symbol.area.x1), u2u(IN.gate.symbol.area.y1),
                                 u2u(IN.gate.symbol.area.x2), u2u(IN.gate.symbol.area.y2),
                                 PA.name
                                );
                if (all <= 0) check(repeat);
                all--;
                break;
              }
              break;
            }
          }
        }
        else if (fpin == "GATE") {
          PA.instances(IN) {
            if (PA.name+IN.gate.name == find || IN.gate.name == find) {
              fndpin = "Gate";
              sprintf(foundelement, "GATE %s : sheet %d on (%.4f %.4f)", IN.gate.name , IN.sheet, u2u(IN.x), u2u(IN.y) );
              repeat += show_S(IN.sheet,
                               u2u(IN.gate.symbol.area.x1), u2u(IN.gate.symbol.area.y1),
                               u2u(IN.gate.symbol.area.x2), u2u(IN.gate.symbol.area.y2),
                               PA.name
                              );
              if (all <= 0) check(repeat);
              all--;
              break;
            }
          }
        }
        else if (fpin == "PIN") {
          PA.instances(IN) {
            status("Pin:"+PA.name);
            IN.gate.symbol.pins(P) {  // Pin
              if (P.name == find) {
                fndpin = "Pin";
                sprintf(foundelement, "PIN %s : sheet %d on (%.4f %.4f)", P.name , IN.sheet, u2u(P.x), u2u(P.y) );
                repeat += show_S(IN.sheet,
                                 u2u(P.x)-u2u(50000), u2u(P.y)-u2u(50000),
                                 u2u(P.x)+u2u(50000), u2u(P.y)+u2u(50000),
                                 PA.name
                                );
                if (all <= 0) check(repeat);
                all--;
                break;
              }
            }
          }
        }
        else if (fpin == "PAD") {
          status("Pad:"+PA.name);
          PA.instances(IN) {
            IN.gate.symbol.pins(P) {
              if (P.contact) {
                if (P.contact.name == find) {
                   fndpin = "Pad";
                  sprintf(foundelement, "PAD %s (PIN %s) : sheet %d on (%.4f %.4f)", PA.name, P.name , IN.sheet, u2u(IN.x), u2u(IN.y) );
                  repeat += show_S(IN.sheet,
                                   u2u(P.x)-u2u(100000), u2u(P.y)-u2u(100000),
                                   u2u(P.x)+u2u(100000), u2u(P.y)+u2u(100000),
                                   PA.name
                                  );
                  if (all <= 0) check(repeat);
                  all--;
                  break;
                }
              }
            }
          }
        }
      }
      SH.nets(N) {
        status("Net:"+N.name);
        if (N.name == find) {
          fndpin = "Net";
          N.segments(SEG) {
            SEG.wires(W) {
              real ox, oy;             // 2008.06.10 alf neue Berechnung des Zoomausschnitt
              if (W.x1 < W.x2) {
                ox = -0.1 * (u2u(W.x1 + W.x2) / 2);
              }
              else {
                ox =  0.1 * (u2u(W.x1 + W.x2) / 2);
              }
              if (W.y1 < W.y2) {
                oy = -0.1 * (u2u(W.y1 + W.y2) / 2);
              }
              else {
                oy =  0.1 * (u2u(W.y1 + W.y2) / 2);
              }
              repeat += show_S(SH.number,
                               u2u(W.x1) - ox, u2u(W.y1) - oy,
                               u2u(W.x2) + ox, u2u(W.y2) + oy,
                               find
                              );
              if (all <= 0) check(repeat);
              all--;
            }
          }
        }
      }
    }
    S.sheets(SH) {
      SH.parts(PA) {
        status("Part:"+PA.name);
        if (PA.name == find) {
          PA.instances(IN) {  // Gate
            if (IN.sheet) {
              fndpin = "Part";
              sprintf(foundelement, "Device %s : sheet %d on (%.4f %.4f)", PA.name , IN.sheet, u2u(IN.x), u2u(IN.y) );
              repeat += show_S(IN.sheet,
                               u2u(IN.gate.symbol.area.x1), u2u(IN.gate.symbol.area.y1),
                               u2u(IN.gate.symbol.area.x2), u2u(IN.gate.symbol.area.y2),
                               PA.name
                              );
              if (all <= 0) check(repeat);
              all--;
            }
          }
        }
      }
      SH.busses(B) {
        status("Bus:"+B.name);
        if (findBus(B.name, find)) {
          fndpin = "Bus";
          B.segments(SEG) {
            SEG.wires(W) {
              real ox, oy;             // 2008.06.10 alf neue Berechnung des Zoomausschnitt
              if (W.x1 < W.x2) {
                ox = -0.1 * (u2u(W.x1 + W.x2) / 2);
              }
              else {
                ox =  0.1 * (u2u(W.x1 + W.x2) / 2);
              }
              if (W.y1 < W.y2) {
                oy = -0.1 * (u2u(W.y1 + W.y2) / 2);
              }
              else {
                oy =  0.1 * (u2u(W.y1 + W.y2) / 2);
              }
              repeat += show_S(SH.number,
                               u2u(W.x1) - ox, u2u(W.y1) - oy,
                               u2u(W.x2) + ox, u2u(W.y2) + oy,
                               find
                              );
              if (all <= 0) check(repeat);
              all--;
            }
          }
        }
      }
      SH.parts(PA) {
        status("Value:" + PA.name);
        PA.instances(IN) {             // Gate
          if (PA.value == vfind) {
            fndpin = "Value";
            sprintf(foundelement, "Value %s | %s : sheet %d on (%.4f %.4f)", PA.value, PA.name , IN.sheet, u2u(IN.x), u2u(IN.y) );
            repeat += show_S(IN.sheet,
                             u2u(IN.gate.symbol.area.x1), u2u(IN.gate.symbol.area.y1),
                             u2u(IN.gate.symbol.area.x2), u2u(IN.gate.symbol.area.y2),
                             PA.name
                            );
            if (all <= 0) check(repeat);
            all--;
          }
        }
      }
    }
  }
  check(repeat);
}
else {
  dlgMessageBox("Start this ULP from schematic or board!", "OK");
  exit (0);
}