-
Notifications
You must be signed in to change notification settings - Fork 18
/
makeLabel.ulp
80 lines (64 loc) · 2.44 KB
/
makeLabel.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
#usage "en: <b>Create a polygon based label using SparkFun's Buzzard system."
"<p>Usage: run makeLabel</p>"
"<p>Author: <author>Nathan Seidle</author><br />"
"Version: <em>1.0</em></p>"
/*
run C:\Dropbox\Projects\Buzzard\makelabel.ulp C:/Dropbox/Projects/Buzzard/text.svg -s 300
*/
string commandToRun;
string s;
//Change any / in a string to \
//Useful for directory structure before calling a cmd
string convertForwardToBackSlashes(string thing)
{
//Convert forward slashes to back slashes so we can run system command
int pos = strrchr(thing, '/');
while (pos >= 0)
{
//thing = strsub(thing, 0, pos) + "\\\\" + strsub(thing, pos + 1, strlen(thing)); //Remove and replace
thing = strsub(thing, 0, pos) + "\\" + strsub(thing, pos + 1, strlen(thing)); //Remove and replace
pos = strrchr(thing, '/'); //Look for the next forward slash
}
return (thing);
}
string getProjectPath()
{
if (board)
board(B) return (filedir(B.name));
if (schematic)
schematic(B) return (filedir(B.name));
}
//add *@C:\Users\natha\Dropbox\Projects\Buzzard\output.lbr
//If there is one item in lib, it will mouse populate
//If there is more than one, a tree will be presented to use
void createLabel()
{
//Convert forward slashes to back slashes so we can run system commands
string localDirectory = convertForwardToBackSlashes(filedir(argv[0]));
string commandToRun = "cmd.exe /C echo Relax. This can take a minute..."; //This is the start of the command. /C = close window
//string commandToRun = "cmd.exe /K echo Relax. This can take a minute..."; //This is the start of the command. /C = close window
commandToRun += " & echo Generating labels";
//Convert the arguments into a single string so we can pass it along to the python script
string argList = "";
for (int x = 1; x < argc; x++)
argList += argv[x] + " ";
sprintf(s, "python \"%sbuzzard.py\" -o lib %s", localDirectory, argList);
commandToRun += " & " + s;
//dlgMessageBox(commandToRun);
if (system(commandToRun) != 0)
{
dlgMessageBox("Error: Command failed.", "OK");
exit(-1);
}
//Python script should create a EAGLE friendly library file. Now run it.
sprintf(s, "ADD '*@%s/output.lbr'", localDirectory);
exit(s);
}
if (board)
{
createLabel();
}
else
{
dlgMessageBox("Run this ULP from a board");
}