compositiongrid.py
Code: Select all
#!/usr/bin/env python
#- bug: only works fine on new documents (templates)
#- drawing lines on wrong places when changing orientation and custom size (document properties)
import inkex,simplestyle,math
class anotherclass(inkex.Effect):
def __init__(self):inkex.Effect.__init__(self)
def effect(self):
svg=self.document.getroot()
xsize=inkex.unittouu(svg.get('width'))
ysize=inkex.unittouu(svg.get('height'))
#- x4 and x3 modules (blue)
for i in range(1,4,1):
new=inkex.etree.Element(inkex.addNS("path","svg"))
new.set("style",simplestyle.formatStyle({"stroke":"#0000FF","fill":"none","opacity":"1"}))
new.set("d","M "+str((xsize*i)/4)+",0 L "+str((xsize*i)/4)+","+str(ysize)+" z")
self.current_layer.append(new)
new=inkex.etree.Element(inkex.addNS("path","svg"))
new.set("style",simplestyle.formatStyle({"stroke":"#0000FF","fill":"none","opacity":"1"}))
new.set("d","M 0,"+str((ysize*i)/4)+" L "+str(xsize)+","+str((ysize*i)/4)+" z")
self.current_layer.append(new)
for i in range(1,3,1):
new=inkex.etree.Element(inkex.addNS("path","svg"))
new.set("style",simplestyle.formatStyle({"stroke":"#0000FF","fill":"none","opacity":"1"}))
new.set("d","M "+str((xsize*i)/3)+",0 L "+str((xsize*i)/3)+","+str(ysize)+" z")
self.current_layer.append(new)
new=inkex.etree.Element(inkex.addNS("path","svg"))
new.set("style",simplestyle.formatStyle({"stroke":"#0000FF","fill":"none","opacity":"1"}))
new.set("d","M 0,"+str((ysize*i)/3)+" L "+str(xsize)+","+str((ysize*i)/3)+" z")
self.current_layer.append(new)
#- rectangle rabatment (green)
if xsize>ysize:
new=inkex.etree.Element(inkex.addNS("path","svg"))
new.set("style",simplestyle.formatStyle({"stroke":"#00FF00","fill":"none","opacity":"1"}))
new.set("d","M "+str(ysize)+",0 L "+str(ysize)+","+str(ysize)+" z")
self.current_layer.append(new)
new=inkex.etree.Element(inkex.addNS("path","svg"))
new.set("style",simplestyle.formatStyle({"stroke":"#00FF00","fill":"none","opacity":"1"}))
new.set("d","M 0,0 L "+str(ysize)+","+str(ysize)+" z")
self.current_layer.append(new)
new=inkex.etree.Element(inkex.addNS("path","svg"))
new.set("style",simplestyle.formatStyle({"stroke":"#00FF00","fill":"none","opacity":"1"}))
new.set("d","M 0,"+str(ysize)+" L "+str(ysize)+",0 z")
self.current_layer.append(new)
new=inkex.etree.Element(inkex.addNS("path","svg"))
new.set("style",simplestyle.formatStyle({"stroke":"#00FF00","fill":"none","opacity":"1"}))
new.set("d","M "+str(xsize-ysize)+",0 L "+str(xsize-ysize)+","+str(ysize)+" z")
self.current_layer.append(new)
new=inkex.etree.Element(inkex.addNS("path","svg"))
new.set("style",simplestyle.formatStyle({"stroke":"#00FF00","fill":"none","opacity":"1"}))
new.set("d","M "+str(xsize-ysize)+",0 L "+str(xsize)+","+str(ysize)+" z")
self.current_layer.append(new)
new=inkex.etree.Element(inkex.addNS("path","svg"))
new.set("style",simplestyle.formatStyle({"stroke":"#00FF00","fill":"none","opacity":"1"}))
new.set("d","M "+str(xsize-ysize)+","+str(ysize)+" L "+str(xsize)+",0 z")
self.current_layer.append(new)
if xsize<ysize:
new=inkex.etree.Element(inkex.addNS("path","svg"))
new.set("style",simplestyle.formatStyle({"stroke":"#00FF00","fill":"none","opacity":"1"}))
new.set("d","M 0,"+str(xsize)+" L "+str(xsize)+","+str(xsize)+" z")
self.current_layer.append(new)
new=inkex.etree.Element(inkex.addNS("path","svg"))
new.set("style",simplestyle.formatStyle({"stroke":"#00FF00","fill":"none","opacity":"1"}))
new.set("d","M 0,0 L "+str(xsize)+","+str(xsize)+" z")
self.current_layer.append(new)
new=inkex.etree.Element(inkex.addNS("path","svg"))
new.set("style",simplestyle.formatStyle({"stroke":"#00FF00","fill":"none","opacity":"1"}))
new.set("d","M "+str(xsize)+",0 L 0,"+str(xsize)+" z")
self.current_layer.append(new)
new=inkex.etree.Element(inkex.addNS("path","svg"))
new.set("style",simplestyle.formatStyle({"stroke":"#00FF00","fill":"none","opacity":"1"}))
new.set("d","M 0,"+str(ysize-xsize)+" L "+str(xsize)+","+str(ysize-xsize)+" z")
self.current_layer.append(new)
new=inkex.etree.Element(inkex.addNS("path","svg"))
new.set("style",simplestyle.formatStyle({"stroke":"#00FF00","fill":"none","opacity":"1"}))
new.set("d","M 0,"+str(ysize-xsize)+" L "+str(xsize)+","+str(ysize)+" z")
self.current_layer.append(new)
new=inkex.etree.Element(inkex.addNS("path","svg"))
new.set("style",simplestyle.formatStyle({"stroke":"#00FF00","fill":"none","opacity":"1"}))
new.set("d","M "+str(xsize)+","+str(ysize-xsize)+" L 0,"+str(ysize)+" z")
self.current_layer.append(new)
#- golden ratio (red)
new=inkex.etree.Element(inkex.addNS("path","svg"))
new.set("style",simplestyle.formatStyle({"stroke":"#FF0000","fill":"none","opacity":"1"}))
new.set("d","M "+str(xsize*0.381966011)+",0 L "+str(xsize*0.381966011)+","+str(ysize)+" z")
self.current_layer.append(new)
new=inkex.etree.Element(inkex.addNS("path","svg"))
new.set("style",simplestyle.formatStyle({"stroke":"#FF0000","fill":"none","opacity":"1"}))
new.set("d","M "+str(xsize*0.618033989)+",0 L "+str(xsize*0.618033989)+","+str(ysize)+" z")
self.current_layer.append(new)
new=inkex.etree.Element(inkex.addNS("path","svg"))
new.set("style",simplestyle.formatStyle({"stroke":"#FF0000","fill":"none","opacity":"1"}))
new.set("d","M 0,"+str(ysize*0.381966011)+" L "+str(xsize)+","+str(ysize*0.381966011)+" z")
self.current_layer.append(new)
new=inkex.etree.Element(inkex.addNS("path","svg"))
new.set("style",simplestyle.formatStyle({"stroke":"#FF0000","fill":"none","opacity":"1"}))
new.set("d","M 0,"+str(ysize*0.618033989)+" L "+str(xsize)+","+str(ysize*0.618033989)+" z")
self.current_layer.append(new)
if __name__=='__main__':e=anotherclass();e.affect()
compositiongrid.inx
Code: Select all
<inkscape-extension>
<_name>Composition Grid</_name>
<id>org.ekips.filter.compositiongrid</id>
<dependency type="executable" location="extensions">compositiongrid.py</dependency>
<dependency type="executable" location="extensions">inkex.py</dependency>
<effect><object-type>all</object-type><effects-menu><submenu _name="Render"/></effects-menu></effect>
<script><command reldir="extensions" interpreter="python">compositiongrid.py</command></script>
</inkscape-extension>