Added fill with circles

This commit is contained in:
Mario Voigt 2020-08-19 12:16:00 +02:00
parent 4d8feef56a
commit bd136efd3a
4 changed files with 132 additions and 29 deletions

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Fill Rectangle With Circles</name>
<id>fablabchemnitz.fill_circle</id>
<param name="radius" type="float" min="0.01" max="10000" gui-text="Radius to enter">3.0</param>
<param name="margin" type="float" min="0.01" max="10000" gui-text="Margin between the edge of the rectangles and the circles">10.0</param>
<param name="space" type="float" min="0.01" max="10000" gui-text="Spacing between circles">30.0</param>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu name="FabLab Chemnitz">
<submenu name="Shape/Pattern from existing Object(s)" />
</submenu>
</effects-menu>
</effect>
<script>
<command location="inx" interpreter="python">fablabchemnitz_fill_circle.py</command>
</script>
</inkscape-extension>

View File

@ -0,0 +1,82 @@
#!/usr/bin/env python3
# Program allowing the addition of small grey dots in rectangles created using Inkscape.
# Thomas Guzik, thomas.guzik@laposte.net
# Leo 130 contact@avilab.fr
# Corentin Bettiol - corentin-bettiol@hotmail.fr
# -Creative Commons License
# -This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
# -http://creativecommons.org/licenses/by-nc-sa/4.0/
import inkex
from lxml import etree
def recup(selection,attrib):
l = []
for i in selection:
selec = i
valr = selec.get(attrib)
l.append(valr)
return l
def generCircle(y,x,r):
circle = etree.Element('{http://www.w3.org/2000/svg}circle')
circle.set('cy',str(y))
circle.set('cx',str(x))
circle.set('r',str(r))
circle.set('fill','#000000')
circle.set('stroke','#000000')
circle.set('stroke-width','0')
return circle
def toFloat(l):
for i in range(len(l)):
l[i] = float(l[i])
return l
class Circle(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
self.arg_parser.add_argument('--radius', type = float, default = 3.0, help = 'Radius to enter')
self.arg_parser.add_argument('--margin', type = float, default = 10.0, help = 'Margin between the edge of the rectangles and the circles')
self.arg_parser.add_argument('--space', type = float, default = 30.0, help = 'Spacing between circles')
def effect(self):
# svg = self.svg.document.getroot()
# layer = etree.SubElement(svg, 'g')
# layer.set(inkex.addNS('label', 'inkscape'), 'Layer')
# layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer')
# Should we add the circles on a different layer sheet?
radius = self.options.radius
margin = self.options.margin
space = self.options.space
if str(list(self.svg.selected.values())[0]) == 'rect':
selection = (self.svg.selected).values()
y,x,height,width = [], [], [], []
if (len(selection))>0:
y = toFloat(recup(selection,'y'))
x = toFloat(recup(selection,'x'))
height = toFloat(recup(selection,'height'))
width = toFloat(recup(selection,'width'))
for i in range(len(selection)):
xC = x[i] + margin
yC = y[i] + margin
while xC < (x[i] + width[i] - margin):
while yC < (y[i] + height[i] - margin):
self.svg.get_current_layer().append(generCircle(yC,xC,radius))
yC += (space + radius)
xC += space + radius
yC = y[i] + margin
else:
inkex.utils.debug("No rectangle(s) have been selected.")
Circle().run()

View File

@ -55,9 +55,11 @@
<label>License: GNU GPL v3</label>
<effect needs-live-preview="true">
<object-type>image</object-type>
<effects-menu>
<submenu name="FabLab Chemnitz Dev"/>
</effects-menu>
<effects-menu>
<submenu name="FabLab Chemnitz">
<submenu name="Tracing/Edge Detection"/>
</submenu>
</effects-menu>
</effect>
<script>
<command location="inx" interpreter="python">./fablabchemnitz_imagetracerjs/fablabchemnitz_imagetracerjs.py</command>

View File

@ -1,21 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Living Hinge</name>
<id>fablabchemnitz.de.living_hinge</id>
<param name="direction" gui-text="Direction" type="optiongroup" appearance="combo">
<option value="y">vertical cuts</option>
<option value="x">horizontal cuts</option>
</param>
<param name="unit" gui-text="Unit" type="optiongroup" appearance="combo">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="in">in</option>
<option value="px">px</option>
</param>
<param name="cut_length" type="float" precision="2" gui-text="cut length (y)" min="1" max="1000">19.0</param>
<param name="gap_length" type="float" precision="2" gui-text="gap length (y)" min="1" max="1000">3.0</param>
<param name="sep_distance" type="float" precision="2" gui-text="separation distance (x)" min="1" max="1000">1.5</param>
<param name="help_text" type="description">This extension renders the lines to make the cuts for a living hinge. The cuts run in the choosen direction.
<name>Living Hinge</name>
<id>fablabchemnitz.de.living_hinge</id>
<param name="direction" gui-text="Direction" type="optiongroup" appearance="combo">
<option value="y">vertical cuts</option>
<option value="x">horizontal cuts</option>
</param>
<param name="unit" gui-text="Unit" type="optiongroup" appearance="combo">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="in">in</option>
<option value="px">px</option>
</param>
<param name="cut_length" type="float" precision="2" gui-text="cut length (y)" min="1" max="1000">19.0</param>
<param name="gap_length" type="float" precision="2" gui-text="gap length (y)" min="1" max="1000">3.0</param>
<param name="sep_distance" type="float" precision="2" gui-text="separation distance (x)" min="1" max="1000">1.5</param>
<param name="help_text" type="description">This extension renders the lines to make the cuts for a living hinge. The cuts run in the choosen direction.
- direction: choose the direction of the cuts.
- cut length: the length of each cut.
@ -23,15 +23,15 @@
- separation distance: the separation distance between adjacent sets of cut lines.
The entered value for cut length will be adjusted so that an integer number of whole cut lines lies in the rectangle. The entered value for separation distance will be adjusted so that in integer number of cut lines lies in rectangle.</param>
<effect>
<object-type>all</object-type>
<effects-menu>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu name="FabLab Chemnitz">
<submenu name="Shape/Pattern from existing Object(s)"/>
</submenu>
</effects-menu>
</effect>
<script>
<command location="inx" interpreter="python">fablabchemnitz_living_hinge.py</command>
</script>
<submenu name="Shape/Pattern from existing Object(s)" />
</submenu>
</effects-menu>
</effect>
<script>
<command location="inx" interpreter="python">fablabchemnitz_living_hinge.py</command>
</script>
</inkscape-extension>