-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tag figure with optional template extension
- Loading branch information
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> | ||
<_name>tagfigure</_name> | ||
<id>org.ekips.filter.tagfigure</id> | ||
<dependency type="executable" location="extensions">tag_figure.py</dependency> | ||
<dependency type="executable" location="extensions">inkex.py</dependency> | ||
<param name="name" type="string" _gui-text="Tag figure/layer name:">figure_name</param> | ||
<param name="template" type="string" _gui-text="(Optional) use template:"></param> | ||
<effect> | ||
<object-type>all</object-type> | ||
<effects-menu> | ||
<submenu _name="FigureFirst"/> | ||
</effects-menu> | ||
</effect> | ||
<script> | ||
<command reldir="extensions" interpreter="python">tag_figure.py</command> | ||
</script> | ||
</inkscape-extension> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env python | ||
import sys | ||
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary | ||
sys.path.append('/Applications/Inkscape.app/Contents/Resources/extensions') | ||
sys.path.append('C:\Program Files\Inkscape\share\extensions') | ||
#import xml.etree.ElementTree as ET | ||
#ET.register_namespace('figurefirst', 'http://www.figurefirst.com') | ||
|
||
# We will use the inkex module with the predefined Effect base class. | ||
import inkex | ||
# The simplestyle module provides functions for style parsing. | ||
from simplestyle import * | ||
|
||
class FigureFirstFigureTagEffect(inkex.Effect): | ||
""" | ||
Modified from example Inkscape effect extension. Tags object with axis tag. | ||
""" | ||
def __init__(self): | ||
""" | ||
Constructor. | ||
Defines the "--name" option of a script. | ||
""" | ||
# Call the base class constructor. | ||
inkex.Effect.__init__(self) | ||
#import matplotlib | ||
#Define string option "--name" with "-n" shortcut and default value "World". | ||
self.OptionParser.add_option('-n', '--name', action = 'store', | ||
type = 'string', dest = 'name', default = 'none', | ||
help = 'Name figure') | ||
self.OptionParser.add_option('-t', '--template', action = 'store', | ||
type = 'string', dest = 'template', default = 'none', | ||
help = 'Name template (optional)') | ||
inkex.NSS[u"figurefirst"] = u"http://flyranch.github.io/figurefirst/" | ||
try: | ||
inkex.etree.register_namespace("figurefirst","http://flyranch.github.io/figurefirst/") | ||
except AttributeError: | ||
#inkex.etree._NamespaceRegistry.update(inkex.addNS("name", "figurefirst")) | ||
#This happens on windows version of inkscape - it might be good to check | ||
#and see if the namespace has been correctly added to the document | ||
pass | ||
|
||
def effect(self): | ||
""" | ||
Effect behaviour. | ||
Overrides base class' method and inserts "Hello World" text into SVG document. | ||
""" | ||
# Get script's "--what" option value. | ||
name = self.options.name | ||
template = self.options.template | ||
|
||
# Get access to main SVG document element and get its dimensions. | ||
svg = self.document.getroot() | ||
# or alternatively | ||
# Create text element | ||
if len(self.selected.values())>1: | ||
raise Exception('too many items') | ||
else: | ||
el = self.selected.values()[0] | ||
|
||
newElm = inkex.etree.Element(inkex.addNS("figure", "figurefirst")) | ||
newElm.attrib[inkex.addNS("name", "figurefirst")] = name | ||
if template != 'none': | ||
newElm.attrib[inkex.addNS("template", "figurefirst")] = template | ||
#print inkex.NSS | ||
el.append(newElm) | ||
|
||
|
||
# Create effect instance and apply it. | ||
effect = FigureFirstFigureTagEffect() | ||
effect.affect() |