Skip to content

Commit

Permalink
tag svgitem
Browse files Browse the repository at this point in the history
  • Loading branch information
florisvb committed Apr 11, 2018
1 parent 738c304 commit 31c94ae
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
17 changes: 17 additions & 0 deletions inkscape_extensions/tag_svgitem.inx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<_name>tagsvgitem</_name>
<id>org.ekips.filter.tagsvgitem</id>
<dependency type="executable" location="extensions">tag_svgitem.py</dependency>
<dependency type="executable" location="extensions">inkex.py</dependency>
<param name="name" type="string" _gui-text="Tag a group with a name:">svgitem_name</param>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu _name="FigureFirst"/>
</effects-menu>
</effect>
<script>
<command reldir="extensions" interpreter="python">tag_svgitem.py</command>
</script>
</inkscape-extension>
63 changes: 63 additions & 0 deletions inkscape_extensions/tag_svgitem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/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 FigureFirstSVGItemTagEffect(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 svgitem')
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

# 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("svgitem", "figurefirst"))
newElm.attrib[inkex.addNS("name", "figurefirst")] = name
#print inkex.NSS
el.append(newElm)


# Create effect instance and apply it.
effect = FigureFirstSVGItemTagEffect()
effect.affect()

0 comments on commit 31c94ae

Please sign in to comment.