LoginSignup
1
1

More than 1 year has passed since last update.

Diskisym - 逆Fanfansym

Last updated at Posted at 2022-05-07

はじめに

KiCad用のSymbol Generator - Fanfansym.pyの逆変換プログラムです。
KiCadからSymbolをExport。これはLISPで読めるS式になってます。
これをDiskisymに通すとFanfansymで読み取り可能なtextを出力します。
似たようなLSIがすでにある時、いったんDisfisymしてテキストエディタで修正して、Fanfansymで変換すれば楽にSymbolを作れます。
例えばファミリーの64QFNがあるのに48QFPは未登録だった場合が該当します。

環境

KiCad 6
Python 3

使い方

  • diskisym.pyをDownLoadしてinput, outputを書き換えます。
  • KiCadでSymbolをExportします。
  • 出力されたファイルをdiskisym.pyで変換します。
  • 適当なText Editorで編集します。
  • fanfansym.pyで変換します。
  • KiCadでimportします。

プログラム

diskisym.py
# diskisym.py: Inverse Fanfansym.py for KiCad6
# Written in Python 3
# Copyright (c) 2022 Fanfan
# Lisence: MIT
input = "fanfan.kicad_sym"
output = "fanfan.pintext"
import sexpdata
LL = []

def parse(s):
    if type(s) == list and len(s) > 0:
        a = sexpdata.car(s)
        d = sexpdata.cdr(s)
        if type(a) == list:
            parse(a)
        else:
            LL.append(a)
        if type(d) == list: 
            parse(d)
        else:
            LL.append(d)
        return

dictword = {
    'pin': 'p',
    'number': 'n',
    'name': 'm',
}

n = ''
m = ''
p = ''

f = open(input,"r")
fo = open(output,"w")
lines = f.read()
s = sexpdata.loads(lines)
parse(s)
fo.write ('#%s' % (LL[6]))
for i in range(2,len(LL)-1):
    if type(LL[i]) == sexpdata.Symbol:
        v = LL[i].value()
        if v in dictword:
            dic = dictword[v]
            if dic == 'n':
                n = LL[i+1]
                fo.write('\n%s\n@%s %s' % (m,n,k))
            elif dic == 'p':
                k = (LL[i+1]).value()
            elif dic == 'm':
                m = LL[i+1]     
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1