forked from xtoolbox/pcad2kicad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcad2kicad.lua
68 lines (65 loc) · 2.33 KB
/
pcad2kicad.lua
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
#!/bin/lua
-- lua command line tool to convert PCAD ASCII symbol/footprint library to KiCad
require("pcad_lib")
require("util")
local function usage()
print("usage:")
print(" Signle file mode:")
print(" lua pcad2kicad.lua <inName> [outName] [outPath] [fpLib]")
print(" inName - Input PCAD library file name")
print(" outName - Output KiCad symbol/footprint library file name, optional")
print(" outPath - Output KiCad symbol/footprint library folder location, optional")
print(" fpLib - footprint library name for symbol, optional")
print(" Multiple file mode:")
print(" lua pcad2kicad.lua --batch <inPath> [outPath] [fpLib] [prefix] [O1=N1[ O2=N2...]]")
print(" inPath - Input PCAD library folder location")
print(" outPath - Output KiCad symbol/footprint library folder location, optional")
print(" fpLib - footprint library name for symbol, optional")
print(" prefix - output library name prefix, optional")
print(" Ox=Nx - replace library name Ox with Nx, optional")
os.exit(-1)
end
if #arg < 1 then
usage()
end
local function log_info(...)
local r = "\n"
for k,v in pairs({...}) do
r = r .. " " .. tostring(v)
end
print(r)
end
local function progress(cur,total)
io.write("\r","Current/Total:", string.format("%8d/%8d",cur,total));
end
if arg[1] == "--batch" then
if #arg < 2 then
usage()
end
local inPath = arg[2]
local outPath = arg[3] or inPath
local symbolLib = arg[4]
local libPrefix = arg[5]
local i = 6
local reName = {}
while arg[i] do
string.gsub(arg[i], "([^=]+)=([^=]+)", function(orgName, newName)
reName[orgName] = newName
end)
i = i + 1
end
local files = get_file_names(inPath, "*.lia")
print("Batch process "..#files.. " files")
for i=1,#files do
local libName = files[i]
local fname = libName .. ".lia"
if reName[libName] then
libName = reName[libName]
elseif libPrefix and libPrefix ~= "" then
libName = libPrefix .. "_" .. libName
end
parse_pcad_lib(inPath.."/"..fname, libName, outPath, progress, log_info, symbolLib)
end
else
parse_pcad_lib(arg[1], arg[2] or "", arg[3] or "", progress, log_info, arg[4])
end