Added dots 2 path points
This commit is contained in:
parent
a282b316b6
commit
9dae115c5d
35
extensions/fablabchemnitz_dots2pathpoints.inx
Normal file
35
extensions/fablabchemnitz_dots2pathpoints.inx
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||||
|
<name>Dots 2 Path Points</name>
|
||||||
|
<id>fablabchemnitz.de.dots2pathpoints</id>
|
||||||
|
<param name="tab" type="notebook">
|
||||||
|
<page name="points" gui-text="Select Points">
|
||||||
|
<param type="bool" name="endpoints" gui-text="End Points">true</param>
|
||||||
|
<param type="bool" name="controlpoints" gui-text="Control Points">false</param>
|
||||||
|
</page>
|
||||||
|
<page name="usage" gui-text="Usage">
|
||||||
|
<label xml:space="preserve">
|
||||||
|
This extension places an arbitrary object at the points
|
||||||
|
of a path.
|
||||||
|
|
||||||
|
Select two Objects:
|
||||||
|
|
||||||
|
1. an object representing the path
|
||||||
|
2. an object representing the dot
|
||||||
|
|
||||||
|
The extension uses the SVG <use>-element which are
|
||||||
|
linked to the second object. Changes of the shape of the
|
||||||
|
source object changes the linked objects.
|
||||||
|
</label>
|
||||||
|
</page>
|
||||||
|
</param>
|
||||||
|
<effect>
|
||||||
|
<object-type>all</object-type>
|
||||||
|
<effects-menu>
|
||||||
|
<submenu _name="Render" />
|
||||||
|
</effects-menu>
|
||||||
|
</effect>
|
||||||
|
<script>
|
||||||
|
<command location="inx" interpreter="python">fablabchemnitz_dots2pathpoints.py</command>
|
||||||
|
</script>
|
||||||
|
</inkscape-extension>
|
76
extensions/fablabchemnitz_dots2pathpoints.py
Normal file
76
extensions/fablabchemnitz_dots2pathpoints.py
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#! /usr/bin/env python3
|
||||||
|
'''
|
||||||
|
Copyright (C) 2020 Christian Hoffmann christian@lehrer-hoffmann.de
|
||||||
|
|
||||||
|
##This extension allows you to draw a Cartesian grid in Inkscape.
|
||||||
|
##There is a wide range of options including subdivision, subsubdivions
|
||||||
|
## and logarithmic scales. Custom line widths are also possible.
|
||||||
|
##All elements are grouped with similar elements (eg all x-subdivs)
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Fraanklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
'''
|
||||||
|
|
||||||
|
import inkex
|
||||||
|
|
||||||
|
class Pathpoints2Dots(inkex.Effect):
|
||||||
|
def __init__(self):
|
||||||
|
inkex.Effect.__init__(self)
|
||||||
|
self.arg_parser.add_argument("--tab")
|
||||||
|
self.arg_parser.add_argument("--endpoints", type=inkex.Boolean, default=True)
|
||||||
|
self.arg_parser.add_argument("--controlpoints", type=inkex.Boolean, default=False)
|
||||||
|
|
||||||
|
def effect(self):
|
||||||
|
if len(self.svg.selected) != 2:
|
||||||
|
errormsg(_("Please select exact two objects:\n1. object representing path,\n2. object representing dots."))
|
||||||
|
return
|
||||||
|
|
||||||
|
dot = self.svg.selected[0]
|
||||||
|
iddot = dot.get('id')
|
||||||
|
path = self.svg.selected[1]
|
||||||
|
idpath = path.get('id')
|
||||||
|
|
||||||
|
self.svg.selected.popitem()
|
||||||
|
self.svg.selected.popitem()
|
||||||
|
|
||||||
|
bb = dot.bounding_box()
|
||||||
|
parent = path.find('..')
|
||||||
|
group = inkex.Group()
|
||||||
|
parent.add(group)
|
||||||
|
|
||||||
|
end_points = list(path.path.end_points)
|
||||||
|
control_points = []
|
||||||
|
for cp in path.path.control_points:
|
||||||
|
is_endpoint = False
|
||||||
|
for ep in end_points:
|
||||||
|
if cp.x == ep.x and cp.y == ep.y:
|
||||||
|
is_endpoint = True
|
||||||
|
break
|
||||||
|
if not is_endpoint:
|
||||||
|
control_points.append(cp)
|
||||||
|
|
||||||
|
pointlist = []
|
||||||
|
if self.options.endpoints:
|
||||||
|
pointlist += end_points
|
||||||
|
if self.options.controlpoints:
|
||||||
|
pointlist += control_points
|
||||||
|
for point in pointlist:
|
||||||
|
clone = inkex.Use()
|
||||||
|
clone.set('xlink:href','#'+iddot)
|
||||||
|
clone.set('x',point.x-bb.center.x)
|
||||||
|
clone.set('y',point.y-bb.center.y)
|
||||||
|
group.add(clone)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
Pathpoints2Dots().run()
|
Reference in New Issue
Block a user