1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

SVG - parse_as_dict

Posted by Stu on Sep 23, 2010

parse_as_dict is a feature by Architetto Francesco Fantoni for the svg library, it lets you get a dict of the shapes in an svg, looked up by their ids.
This lets you use them as libraries of shapes.

Heres the original mail explaining the functionality:
http://www.mail-archive.com/shoebot-devel@lists.tinkerhouse.net/msg00418.html

As we don't want to see fragmentation among the libraries it would be good if this could make it upstream back into shoebot.


Patch:

@@ -69,6 +70,18 @@

return paths

+def parse_as_dict(svg, cached=False, _copy=True):
+ paths_dict = {}
+ noid = 0
+ paths = parse(svg)
+ for p in paths:
+ if p.id:
+ paths_dict[p.id] = p
+ else:
+ noid += 1
+ paths_dict["no_id_"+str(noid)] = p
+ return paths_dict
+
def get_attribute(element, attribute, default=0):

""" Returns XML element's attribute, or default if none.


 
Posted by Tom De Smedt on Oct 04, 2010

I'll get this and your other suggestions integrated.
Send me an e-mail with the changes so I don't forget.