LoginSignup
1
2

More than 5 years have passed since last update.

PythonによるEAGLEの.brdファイルの操作

Posted at

はじめに

Eagleの.brdファイルの配線をちょっと変えたときに,部品の位置も変わっているとメタルマスクが再利用できなくなります.これはできるだけ避けたいですが,配線の変更を行った際に気づかないうちに武人の位置が少しずれてることがあります.これを避けるため,人の目ではわからないような部品の移動の変化をチェックできるプログラムをPythonで作成してみたので,そのメモです.

条件

変更前および変更後の部品の"name"は同じである.

コード

Eagleの.brdファイルがxmlファイルであることを利用しています.
まず,変更前のファイルの"element"要素と変更後のファイルの"element"要素内で同じ"name"のattributeをもつ要素を見つけます.
その後,もしxまたはy座標が違った場合には,その部品の名前と変更前,変更後の(x,y)座標を表示し,もし問題がない場合には"No error"を表示します.

# -*- coding: utf-8 -*-
from xml.etree.ElementTree import *

def check(file1, file2):
    c = 1
    tree1 = parse(file1)
    elem1 = tree1.getroot()
    tree2 = parse(file2)
    elem2 = tree2.getroot()

    for e1 in elem1.getiterator("element"):
        for e2 in elem2.getiterator("element"):
            if e1.get("name", ) == e2.get("name", ):
                if e1.get("x") != e2.get("x") or e1.get("y") != e2.get("y"):
                    print "Error"
                    print "Parts Name = " + e1.get("name")
                    print ("x1=" + e1.get("x")) * (e1.get("x") != e2.get("x"))
                    print ("x2=" + e2.get("x")) * (e1.get("x") != e2.get("x"))
                    print ("y1=" + e1.get("y")) * (e1.get("y") != e2.get("y"))
                    print ("y2=" + e2.get("y")) * (e1.get("y") != e2.get("y"))
                    c = 0
    return c

if __name__ == "__main__":
    file1 = raw_input() #変更前のファイルのpathを入力
    file2 = raw_input() #変更後のファイルのpathを入力
    print "No error" * check(file1, file2)

メリット

Linuxの"diff"コマンドと違い,"element"の順番が違っても適用可能.

参考URL

参考:http://hikm.hatenablog.com/entry/20090206/1233950923

1
2
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
2