Advertisement
Guest User

EnlargePads v0.1a

a guest
Oct 23rd, 2013
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # EnlargePads v0.1a
  5. # A very simple program for enlarging pads in svg as output from Fritzing
  6. # At the moment, not much care is taken to not break stuff, so please check
  7. # the result yourself before etching.
  8. #
  9. # Copyright (c) 2013 Niels Kjoeller Hansen <niels.k.h@gmail.com>
  10. # This work is free. You can redistribute it and/or modify it under the
  11. # terms of the Do What The Fuck You Want To Public License, Version 2,
  12. # as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
  13. #
  14.  
  15. from xml.dom import minidom
  16.  
  17. # Setting up
  18. filename = "test_print.svg"
  19. drill_hole_diameter_mil = 40 #(40 mil =~ 1mm)
  20. pad_diameter_mil = 75
  21.  
  22. # Calculating radius and stroke-width (pixels @ 90ppi)
  23. new_sw = (pad_diameter_mil - drill_hole_diameter_mil)*0.09/2
  24. new_r = (pad_diameter_mil*0.09 - new_sw)/2
  25.  
  26. # Parsing the xml
  27. xmldoc = minidom.parse(filename)
  28.  
  29. # Iterating through elements of type "circle"
  30. for circle in xmldoc.getElementsByTagName('circle'):
  31.     # Checking if attributes has keys (if they have not, something is wrong)
  32.     if 'r' in circle.attributes.keys() and \
  33.        'stroke-width' in circle.attributes.keys():
  34.         # Only enlarging small circles
  35.         if float(str(circle.attributes['r'].value)) < new_r and \
  36.            float(str(circle.attributes['stroke-width'].value)) < new_sw:
  37.             circle.attributes['r'] = str(new_r)
  38.             circle.attributes['stroke-width'] = str(new_sw)
  39.  
  40. # Writing to a new file with "_enlargedpads" appended to the filename
  41. new_filename = ".".join(filename.split('.')[:-1]) + \
  42.                 '_enlargedpads.' + filename.split('.')[-1]
  43. a = open(new_filename,'w')
  44. a.write(xmldoc.toxml())
  45. a.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement