Added fill with circles
This commit is contained in:
parent
4d8feef56a
commit
bd136efd3a
19
extensions/fablabchemnitz_fill_circle.inx
Normal file
19
extensions/fablabchemnitz_fill_circle.inx
Normal 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>
|
82
extensions/fablabchemnitz_fill_circle.py
Normal file
82
extensions/fablabchemnitz_fill_circle.py
Normal 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()
|
@ -56,7 +56,9 @@
|
|||||||
<effect needs-live-preview="true">
|
<effect needs-live-preview="true">
|
||||||
<object-type>image</object-type>
|
<object-type>image</object-type>
|
||||||
<effects-menu>
|
<effects-menu>
|
||||||
<submenu name="FabLab Chemnitz Dev"/>
|
<submenu name="FabLab Chemnitz">
|
||||||
|
<submenu name="Tracing/Edge Detection"/>
|
||||||
|
</submenu>
|
||||||
</effects-menu>
|
</effects-menu>
|
||||||
</effect>
|
</effect>
|
||||||
<script>
|
<script>
|
||||||
|
@ -27,7 +27,7 @@ The entered value for cut length will be adjusted so that an integer number of w
|
|||||||
<object-type>all</object-type>
|
<object-type>all</object-type>
|
||||||
<effects-menu>
|
<effects-menu>
|
||||||
<submenu name="FabLab Chemnitz">
|
<submenu name="FabLab Chemnitz">
|
||||||
<submenu name="Shape/Pattern from existing Object(s)"/>
|
<submenu name="Shape/Pattern from existing Object(s)" />
|
||||||
</submenu>
|
</submenu>
|
||||||
</effects-menu>
|
</effects-menu>
|
||||||
</effect>
|
</effect>
|
||||||
|
Reference in New Issue
Block a user