Skip to content

Instantly share code, notes, and snippets.

@RenaKunisaki
Created May 17, 2019 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RenaKunisaki/83b51ee0c9f7c7f79763c25ccdf9a507 to your computer and use it in GitHub Desktop.
Save RenaKunisaki/83b51ee0c9f7c7f79763c25ccdf9a507 to your computer and use it in GitHub Desktop.
Inkscape extension
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<_name>Split Fill and Stroke</_name>
<id>githubacct.uniqueid.Name_of_your_extension</id>
<dependency type="executable" location="extensions">split-fill-stroke.py</dependency>
<param name="achoice" type="boolean" _gui-text="A boolean value">false</param>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu _name="Objects"/>
</effects-menu>
</effect>
<script>
<command reldir="extensions" interpreter="python">split-fill-stroke.py</command>
</script>
</inkscape-extension>
#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Inkscape extension: Split Fill and Stroke
'''
import inkex # Required
import simplestyle # will be needed here for styles support
import os # here for alternative debug method only - so not usually required
# many other useful ones in extensions folder. E.g. simplepath, cubicsuperpath, ...
from copy import deepcopy
#from math import cos, sin, radians
__version__ = '0.1'
#inkex.localize()
def printf(fmt, *args):
inkex.debug(fmt % args)
def fail(msg):
inkex.errormsg(msg)
exit()
class SplitFillStroke(inkex.Effect):
def __init__(self):
" define how the options are mapped from the inx file "
inkex.Effect.__init__(self) # initialize the super class
self.OptionParser.add_option("-x", "--achoice",
action="store", type="inkbool",
dest="achoice", default=False,
help="command line help")
def effect(self):
if len(self.selected) == 0:
fail(_("No objects selected."))
for id, node in self.selected.items():
printf("Applying to %s", id)
style = simplestyle.parseStyle(node.attrib['style'])
fills, strokes, others = {}, {}, {}
for name, val in style.items():
if name.startswith('stroke'): strokes[name] = val
elif name.startswith('fill'): fills[name] = val
else: others[name] = val
if len(strokes) > 0 and len(fills) > 0:
printf("Go with %s", id)
fillElem = deepcopy(node)
printf("copied")
fillElem.attrib['id'] = node.attrib['id']+'-fill'
printf("set id")
#fillElem.attrib['name'] = node.attrib['name']+'-fill'
fills.update(others)
strokes.update(others)
printf("set styles")
fillElem.attrib['style'] = simplestyle.formatStyle(fills)
node.attrib['style'] = simplestyle.formatStyle(strokes)
printf("applied styles")
node.addnext(fillElem)
printf("appended")
printf("done")
printf("done all")
if __name__ == '__main__':
e = SplitFillStroke()
e.affect()
printf("exiting")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment