Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # EnlargePads v0.1a
- # A very simple program for enlarging pads in svg as output from Fritzing
- # At the moment, not much care is taken to not break stuff, so please check
- # the result yourself before etching.
- #
- # Copyright (c) 2013 Niels Kjoeller Hansen <niels.k.h@gmail.com>
- # This work is free. You can redistribute it and/or modify it under the
- # terms of the Do What The Fuck You Want To Public License, Version 2,
- # as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
- #
- from xml.dom import minidom
- # Setting up
- filename = "test_print.svg"
- drill_hole_diameter_mil = 40 #(40 mil =~ 1mm)
- pad_diameter_mil = 75
- # Calculating radius and stroke-width (pixels @ 90ppi)
- new_sw = (pad_diameter_mil - drill_hole_diameter_mil)*0.09/2
- new_r = (pad_diameter_mil*0.09 - new_sw)/2
- # Parsing the xml
- xmldoc = minidom.parse(filename)
- # Iterating through elements of type "circle"
- for circle in xmldoc.getElementsByTagName('circle'):
- # Checking if attributes has keys (if they have not, something is wrong)
- if 'r' in circle.attributes.keys() and \
- 'stroke-width' in circle.attributes.keys():
- # Only enlarging small circles
- if float(str(circle.attributes['r'].value)) < new_r and \
- float(str(circle.attributes['stroke-width'].value)) < new_sw:
- circle.attributes['r'] = str(new_r)
- circle.attributes['stroke-width'] = str(new_sw)
- # Writing to a new file with "_enlargedpads" appended to the filename
- new_filename = ".".join(filename.split('.')[:-1]) + \
- '_enlargedpads.' + filename.split('.')[-1]
- a = open(new_filename,'w')
- a.write(xmldoc.toxml())
- a.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement