Manipulating EAGLE .brd files with Python

Introduction

When I change the wiring of Eagle's .brd file a little, the metal mask cannot be reused if the position of the part is also changed. I want to avoid this as much as possible, but I do not notice it when I change the wiring In order to avoid this, I wrote a program in Python that can check changes in the movement of parts that are invisible to the human eye, so this is a memo.

conditions

The "name" of the part before and after the change is the same.

code

We are taking advantage of Eagle's .brd file being an xml file. First, find the element with the same "name" attribute in the "element" element of the unmodified file and the "element" element of the modified file. After that, if the x or y coordinates are different, the name of the part and the (x, y) coordinates before and after the change are displayed, and if there is no problem, "No error" is displayed. ..

# -*- 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() #Enter the path of the file before the change
    file2 = raw_input() #Enter the path of the modified file
    print "No error" * check(file1, file2)

merit

Unlike the Linux "diff" command, it can be applied even if the order of "element" is different.

Reference URL

Reference: http://hikm.hatenablog.com/entry/20090206/1233950923

Recommended Posts

Manipulating EAGLE .brd files with Python
Sorting image files with Python (2)
Sort huge files with python
Sorting image files with Python (3)
Sorting image files with Python
Integrate PDF files with Python
Reading .txt files with Python
Recursively unzip zip files with python
[Python] POST wav files with requests [POST]
Decrypt files encrypted with OpenSSL with Python 3
Handle Excel CSV files with Python
Read files in parallel with Python
[AWS] Using ini files with Lambda [Python]
Play audio files from Python with interrupts
Manipulating Cisco IOS-XE ACLs with RESTCONF (Python)
Decrypt files encrypted with openssl from python with openssl
Automate jobs by manipulating files in Python
Reading and writing JSON files with Python
Download files on the web with Python
[Easy Python] Reading Excel files with openpyxl
Convert HEIC files to PNG files with Python
[Easy Python] Reading Excel files with pandas
FizzBuzz with Python3
Scraping with Python
Statistics with python
Scraping with Python
Python with Go
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
with syntax (Python)
Bingo with python
Zundokokiyoshi with python
Excel with Python
Microcomputer with Python
Cast with python
[Python] Get the files in a folder with Python
Handle zip files with Japanese filenames in Python 3
Drag and drop local files with Selenium (Python)
Character encoding when dealing with files in Python 3
Download and import files with Splunk external python
Upload files to Google Drive with Lambda (Python)
Reading and writing fits files with Python (memo)
Convert multiple proto files at once with python
Read wav files with only Python standard packages
Serial communication with Python
Zip, unzip with python
Primality test with Python
Python with eclipse + PyDev.
Socket communication with Python
Data analysis with python 2
Upload files with Django
Scraping with Python (preparation)
Try scraping with Python.
Extract the table of image files with OneDrive & Python
Sequential search with Python
"Object-oriented" learning with python
Run Python with VBA