Aaron via inkscape-user-admin@lists.sourceforge.net wrote on 14/09/2005 11:00:42 AM:
Sorry there isn't any documentation. But I'd be happy to answer any questions you have. The format you are working with very simply mimics the structure of path data in SVG. Each list for each command is in the form [command, parameters]. So for a moveto it would be like ['M',[x,y]]. And for curveto like ['C',[x1,y1,x2,y2,x,y]]. But for a saw
tooth wave I would expect you to use a lineto not curveto. Linetos would
be in the form ['L',[x,y]].
It works! WOOT!
I tried to comment the plugin correctly so it might help other people. It's probably too simple to be of much use.
-kt
(apologies in advance if you don't like me posting there here, but it's fairly short really)
SAWTOOTH.INX
<inkscape-extension> <name>Sawtooth Line</name> <id>org.ekips.filter.sawtooth</id> <dependency type="executable" location="extensions">sawtooth.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> <param name="wavelengths" type="int" min="0" max="1000" gui-text="Wavelengths">4</param> <effect> <object-type>rect</object-type> </effect> <script> <command reldir="extensions" interpreter="python">sawtooth.py</command> </script> </inkscape-extension>
SAWTOOTH.PY
#! /usr/bin/env python
### ### Sawtooth Line, you know like VVVVVVVVVV ### kingsley@...1070... ### Release under a Creative Commons (CC) ### Non-commercial/Attribution/Share-Alike ### Licence ### ### Takes a given rectangle, and draws a sawtooth ### set of lines inside it. ### ### Based on code by Aaron Spike, aaron@...476... ###
### Stuff for inkscape import inkex, simplepath, simplestyle
class Sawtooth(inkex.Effect): ### Only get one option from the user, that is the ### integer number of wavelengths that should be rendered. def __init__(self): inkex.Effect.__init__(self) self.OptionParser.add_option("-w", "--wavelengths", action="store", type="int", dest="wavelengths", default=4, help="Integer number of wavelengths")
### ### Grab our bounding rectangle, copying it's dimensions to encapsulate ### the new path, and then also copy out it's style for the new line; ### Also copies the transformation - if any. ### ### Once our boundaries are defined, make the call to render the new ### line into the box. ### def effect(self): for id, node in self.selected.iteritems(): if (node.tagName == 'rect'): new = self.document.createElement('svg:path') x = float(node.attributes.getNamedItem('x').value) y = float(node.attributes.getNamedItem('y').value) w = float(node.attributes.getNamedItem('width').value) h = float(node.attributes.getNamedItem('height').value)
### Copy the style s = node.attributes.getNamedItem('style').value new.setAttribute('style', s)
### If we have a transformation, copy it too try: t = node.attributes.getNamedItem('transform').value new.setAttribute('transform', t) except AttributeError: pass
### Render it now!
new.setAttribute('d',simplepath.formatPath(self.draw(self.options.wavelengths,w,h,x,y)))
### Add the line into the drawing node.parentNode.appendChild(new) ### Remove the original rectangle node.parentNode.removeChild(node)
### ### Given a number of wavelengths, and a rectangle ### Draw a sawtooth pattern inside the rectangle ### made of <wavelengths> 'M's. Note that we're ### cheating a bit here, we should only be using 4 ### points, not coming down to the final stroke of ### the M-shape, just stopping after the 'N' part. ### But it makes the looping simpler, and it's more ### useful for the truss-like shapes I was drawing ### ### Returns a list that mimics SVG path data ### def draw(self, wavelengths,width,height,left,top): bottom = top+height period = width / float(wavelengths) quarter_period = period / 4.0 half_period = period / 2.0 three_quarter_period = 3 * period / 4.0
strokes = [] strokes.append(['M',[left,bottom]]) ### (M)ove-to the corner for i in range(wavelengths): cursor = left + (i * period) ### Using (L)ineto's, draw up-down-up-down strokes.append(['L',[cursor+quarter_period,top]]) strokes.append(['L',[cursor+half_period,bottom]]) strokes.append(['L',[cursor+three_quarter_period,top]]) strokes.append(['L',[cursor+period,bottom]])
return strokes
### B E G I N e = Sawtooth() e.affect()
-----8><----------------------------------------------------
Please consider our environment before printing this email.
WARNING - This email and any attachments may be confidential. If received in error, please delete and inform us by return email. Because emails and attachments may be interfered with, may contain computer viruses or other defects and may not be successfully replicated on other systems, you must be cautious. Westpac cannot guarantee that what you receive is what we sent. If you have any doubts about the authenticity of an email by Westpac, please contact us immediately.
It is also important to check for viruses and defects before opening or using attachments. Westpac's liability is limited to resupplying any affected attachments.
This email and its attachments are not intended to constitute any form of financial advice or recommendation of, or an offer to buy or offer to sell, any security or other financial product. We recommend that you seek your own independent legal or financial advice before proceeding with any investment decision.
Westpac Institutional Bank is a division of Westpac Banking Corporation, a company registered in New South Wales in Australia under the Corporations Act 2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the Financial Services Authority and is registered at Cardiff in the United Kingdom as Branch No. BR 106. Westpac operates in the United States of America as a federally chartered branch, regulated by the Office of the Comptroller of the Currency.
Westpac Banking Corporation ABN 33 007 457 141.