Skip to content

Inkex get() fails to parse SVGs with comments

Summary:

Calling the get() function on a selection fails if the SVG has embedded comments.

Steps to reproduce:

  • open Inkscape
  • Select the group in test-out.svg (attached)
  • Run the attached Sandbox extension, which just calls .get() on the selection

What happened?

Exits with the error

Traceback (most recent call last):
  File "sandbox.py", line 83, in <module>
    ScalePlots().run()
  File "C:\Program Files\Inkscape\share\inkscape\extensions\inkex\base.py", line 140, in run
    self.save_raw(self.effect())
  File "sandbox.py", line 58, in effect
    sel = self.svg.selection.get();                     # an ElementList      
  File "C:\Program Files\Inkscape\share\inkscape\extensions\inkex\elements\_selected.py", line 136, in get
    return ElementList(self.svg, [r for e in self.values() for r in _recurse(e)])
  File "C:\Program Files\Inkscape\share\inkscape\extensions\inkex\elements\_selected.py", line 40, in __init__
    self.set(*list(_iter))
  File "C:\Program Files\Inkscape\share\inkscape\extensions\inkex\elements\_selected.py", line 101, in set
    self.add(*ids)
  File "C:\Program Files\Inkscape\share\inkscape\extensions\inkex\elements\_selected.py", line 116, in add
    self[elem] = elem # This doesn't matter
  File "C:\Program Files\Inkscape\share\inkscape\extensions\inkex\elements\_selected.py", line 66, in __setitem__
    raise ValueError("Unknown element type: {}".format(kind))
ValueError: Unknown element type: _Comment

What should have happened?

Nothing

Sample attachments:

test-out.svg sandbox.py sandbox.inx

Version Info:

- Inkscape Version: 1.0.2-2 (e86c870879, 2021-01-15)
- Operating System: Windows 10 Enterprise
- Operating System version: 1909
Edited by Nathan Lee
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information