Advertisement
Guest User

DTRRendoggle

a guest
Aug 8th, 2008
668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.04 KB | None | 0 0
  1. '''draws lines between the vertices of two selected paths'''
  2.  
  3. #!/usr/bin/env python
  4. '''
  5. Copyright (C) 2007
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  20. '''
  21. import sys, os
  22. sys.path.append(os.path.dirname(sys.argv[0]))  #?
  23.  
  24. import inkex, simplepath, sys
  25.  
  26. class StringBoard(inkex.Effect):
  27.     def __init__(self):
  28.         inkex.Effect.__init__(self)
  29.     def setAttr(self, node, name, value):
  30.         attr = node.ownerDocument.createAttribute(name)
  31.         attr.value = value
  32.         node.attributes.setNamedItem(attr)
  33.  
  34.     def effect(self):
  35.         paths = []
  36.         for id, node in self.selected.iteritems():
  37.             if node.tag == 'path':
  38.                 paths.append(node)
  39.                 if len(paths) == 2:
  40.                     break
  41.         sys.stderr.write('Found 2\n')
  42.         if len(paths) == 2:
  43.             pts = [simplepath.parsePath(paths[i].attributes.getNamedItem('d').value)
  44.                    for i in (0,1)]
  45.             line = []
  46.             for i in range(0, min(map(len, pts))):
  47.                 line += [('M', pts[0][i][1][-2:])]
  48.                 line += [('L', pts[1][i][1][-2:])]
  49.             ele = paths[0].ownerDocument.createElement('path')
  50.             paths[0].parentNode.appendChild(ele)
  51.             self.setAttr(ele, 'd', simplepath.formatPath(line))
  52.             self.setAttr(ele, 'style', 'fill:none;stroke:#000000;stroke-opacity:1;stroke-width:1;')
  53.  
  54. e = StringBoard()
  55. e.affect()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement