Code: Select all
#!/usr/bin/env python
import sys, copy
sys.path.append('/Applications/Inkscape.app/Contents/Resources/extensions')
import inkex, simpletransform
from math import sin, cos, pi, pow
class DuplicateMultiple(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
self.OptionParser.add_option('-b', '--begin',
action='store', type='int',
dest='begin', default=0,
help='n starts here')
self.OptionParser.add_option('-e', '--end',
action='store', type='int',
dest='end', default=10,
help='n stops here')
self.OptionParser.add_option('-x', '--horizontal',
action='store', type='string',
dest='horizontal', default='n',
help='Horizontal distance?')
self.OptionParser.add_option('-y', '--vertical',
action='store', type='string',
dest='vertical', default='n^2',
help='Vertical distance?')
self.OptionParser.add_option('-c', '--centerx',
action='store', type='string',
dest='cx', default='0',
help='x coordinate of center')
self.OptionParser.add_option('-d', '--centery',
action='store', type='string',
dest='cy', default='0',
help='y coordinate of center')
self.OptionParser.add_option("-u", "--unit",
action="store", type="string",
dest="unit", default="px",
help="The unit of the measurement")
self.OptionParser.add_option('-s', '--scale',
action='store', type='string',
dest='scale', default="n/2",
help='Scale Factor')
self.OptionParser.add_option('-r', '--rotate',
action='store', type='string',
dest='rotate', default='-90',
help='Degrees rotated CW')
def effect(self):
cx=eval(self.options.cx)
cy=eval(self.options.cy)
if self.selected:
for id, node in self.selected.iteritems():
for n in range(self.options.begin, self.options.end+1):
horiz=eval(self.options.horizontal)
vert=eval(self.options.vertical)
strtranslation = 'translate(' + str(inkex.unittouu(str(horiz) + self.options.unit)) + ', ' + str(inkex.unittouu(str(vert) + self.options.unit)) + ')'
translation = simpletransform.parseTransform(strtranslation)
strtranslation2= 'translate(' + str(inkex.unittouu(str(-1*cx) + self.options.unit)) + ', ' + str(inkex.unittouu(str(-1*cy) + self.options.unit)) + ')'
translation2 = simpletransform.parseTransform(strtranslation2)
strtranslation3= 'translate(' + str(inkex.unittouu(str(cx) + self.options.unit)) + ', ' + str(inkex.unittouu(str(cy) + self.options.unit)) + ')'
translation3 = simpletransform.parseTransform(strtranslation3)
strrotation = 'rotate(' + str(eval(self.options.rotate)) + ')'
rotation = simpletransform.parseTransform(strrotation)
strscaleing = 'scale(' + str(eval(self.options.scale)) + ')'
scaleing = simpletransform.parseTransform(strscaleing)
newNode = copy.deepcopy(node)
simpletransform.applyTransformToNode(translation2, newNode)
simpletransform.applyTransformToNode(rotation, newNode)
simpletransform.applyTransformToNode(scaleing, newNode)
simpletransform.applyTransformToNode(translation3, newNode)
simpletransform.applyTransformToNode(translation, newNode)
self.current_layer.append(newNode)
node = newNode
cx=cx+horiz
cy=cy+vert
effect = DuplicateMultiple()
effect.affect()
is the code I call duplicates.py and
Code: Select all
<inkscape-extension>
<_name>Multiple Copies</_name>
<id>com.curran.filter.duplicates</id>
<dependency type="executable" location="extensions">inkex.py</dependency>
<dependency type="executable" location="extensions">simpletransform.py</dependency>
<param name="begin" type="int" min="-1000" max="1000" _gui-text="For n=">0</param>
<param name="end" type="int" min="-1000" max="1000" _gui-text="to">10</param>
<param name="horizontal" type="string" _gui-text="X translation">n</param>
<param name="vertical" type="string" _gui-text="Y translation">n^2</param>
<param name="centerx" type="string" _gui-text="X coordinate of center">0</param>
<param name="centery" type="string" _gui-text="Y coordinate of center">0</param>
<param name="unit" type="enum" _gui-text="Length Unit: ">
<item value="px">px</item>
<item value="pt">pt</item>
<item value="in">in</item>
<item value="ft">ft</item>
<item value="yd">yd</item>
<item value="mm">mm</item>
<item value="cm">cm</item>
<item value="m">m</item>
<item value="km">km</item>
</param>
<param name="scale" type="string" _gui-text="Scale Factor">n/2</param>
<param name="rot" type="string" _gui-text="Degrees Rotated CW">-90</param>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu _name="Mine" />
</effects-menu>
</effect>
<script>
<command reldir="extensions" interpreter="python">duplicates.py</command>
</script>
</inkscape-extension>
is what I call duplicates.inx.
To use you can put in ~/.config/inkscape/extensions/
It just does a for loop in python, and the parameters to the geometric transformation done to each copy are given by a bit of python code. Note that it is affected by Bug #170049, because it uses the coordinate system that inkscape doesn't show you.
As an example of use you can start with a 3.4 inch square in the lower left corner of the page (A4 size?) and use the parameters:
Code: Select all
X translation: 5.5/2*sin(n*pi/2)*pow(.62,(n-1))+(0.5*5.5-3.4)*cos(n*pi/2)*pow(.62,(n-1))
Y translation: -5.5/2*cos(n*pi/2)*pow(.62,(n-1))+(0.5*5.5-3.4)*sin(n*pi/2)*pow(.62,(n-1))
x coordinate of center: 1.7
y cooridnate of center: 11.69-1.7
inches
scale factor: .62
rotation: 90
To make a golden rectangle. You can see the 11.69 because that is the height of A4 paper I think, so you can see how the aformentioned bug screws things up.