You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.3 KiB

import os
import glob
def getFootprinLibrarys(pathTofootprints):
cwd = os.getcwd()
os.chdir(footprintPath)
footprintList = []
files = os.listdir()
# append all .pretty folders
for f in files:
if f.endswith(".pretty"):
footprintList.append(f)
os.chdir(cwd)
return footprintList
def getSymbolsLibrarys(pathToSymbols):
search_pattern = os.path.join(pathToSymbols, "*.kicad_sym")
return glob.glob(search_pattern)
pathToProjectFolder = input("enter path to KiCad project folder:")
# move one directory back into the main KicED library folder
# https://stackoverflow.com/questions/12280143/how-to-move-to-one-folder-back-in-python
os.path.normpath(os.getcwd() + os.sep + os.pardir)
cwd = os.getcwd()
print(pathToProjectFolder)
print(cwd)
# find common path
commonPath = os.path.commonprefix([cwd, pathToProjectFolder])
# KicED library paths
footprintPath = os.path.join(cwd, "footprints")
symbolsPath = os.path.join(cwd, "symbols")
# create relative path from KiCad project and the KicED library
relative_path = os.path.relpath(cwd, pathToProjectFolder)
print(relative_path)
baseRelativeBasePath = os.path.join("${KIPRJMOD}", relative_path)
print(baseRelativeBasePath)
fps = getFootprinLibrarys(footprintPath)
sps = getSymbolsLibrarys(symbolsPath)
temp = []
for f in fps:
pth = os.path.join(baseRelativeBasePath, "symbols")
temp.append(os.path.join(pth, f))
fps = temp
temp = []
for f in sps:
pth = os.path.relpath(f,cwd)
pth = os.path.join(baseRelativeBasePath,pth)
temp.append(pth)
sps = temp
if 1:
for f in fps:
print(f)
for f in sps:
print(f)
os.chdir(pathToProjectFolder)
print(pathToProjectFolder)
try:
with open("sym-lib-table",'w') as file:
file.write("(fp_lib_table\n (version 7)\n")
if 1:
for p in sps:
# example
# (lib (name "000_SDM_Resistor")(type "KiCad")(uri "${KIPRJMOD}/test_lib/footprints/000_SDM_Resistor.pretty")(options "")(descr ""))
file.write(" (lib (name \"")
file.write(os.path.basename(p))
file.write("\"(type \"KiCad\")(uri \"")
file.write(p)
file.write("\")(options \"\")(descr \"\"))\n")
file.write(")")
os.chdir(cwd)
except FileNotFoundError:
print("fail")
os.chdir(cwd)