Inkscape Laser Engraver Bug

If you’ve tried to use the modified Inkscape laser engraver plugin mentioned in this blog post about building an engraver, you may have run into an error trying to do the export. It’s something like “AttributeError: ‘module’ object has no attribute ‘unittouu’” or “unittouu not part of inkex module“. Here’s the fix.

The bug is on line 3080 of laserengraver.py and broke due to an Inkscape change. Old line:

doc_height = inkex.unittouu(self.document.getroot().get('height'))

New line:

doc_height = self.unittouu(self.document.getroot().xpath('@height', namespaces=inkex.NSS)[0])

Be sure to have the exact same number of spaces/tabs on this line. In Python, whitespace is important, so you can’t mix and match spaces and tabs, and all code blocks must have the same whitespace alignment.

Problem solved!

24 thoughts on “Inkscape Laser Engraver Bug”

  1. Thank you so much,finally the nice plugin is working in ver. 0.91.
    I knew there was an error in the mentioned line, but had no clue how to fix it!

    Thanx again 🙂

    Tom

  2. In exporting a Inkscape drawing to Tikz I get

    Traceback (most recent call last):
    File “tikz_export.py”, line 1419, in
    main_inkscape()
    File “tikz_export.py”, line 1407, in main_inkscape
    effect.affect()
    File “C:\Program Files\Inkscape\share\extensions\inkex.py”, line 268, in affect
    self.effect()
    File “tikz_export.py”, line 1314, in effect
    s = self._output_group(nodes, graphics_state)
    File “tikz_export.py”, line 1295, in _output_group
    goptions, transformation = self.convert_svgstate_to_tikz(graphics_state, accumulated_state, node)
    File “tikz_export.py”, line 920, in convert_svgstate_to_tikz
    options.append(‘%s=%.3fpt’ % (tikzname, inkex.unittouu(value) * 0.80)),
    AttributeError: ‘module’ object has no attribute ‘unittouu’

    apparently line 920 of tikz_export.py has a similar bug.
    How can that be corrected?
    TIA.

    1. It’s hard to say without running it (I don’t have that plugin installed) or seeing the entire block of code, but I would try replacing “inkex.unittouu” with “self.unittouu”. If that doesn’t fix it, send me a pastebin link to the full file and I’ll see if I can spot a quick-fix.

  3. When converting complex images there was an error:

    Traceback (most recent call last):
    File “laser.py”, line 3173, in
    e.affect()
    File “C:\Program Files\Inkscape\share\extensions\inkex.py”, line 268, in affect
    self.effect()
    File “laser.py”, line 3154, in effect
    self.get_info()
    File “laser.py”, line 2884, in get_info
    recursive_search(self.document.getroot(),self.document.getroot())
    File “laser.py”, line 2865, in recursive_search
    recursive_search(i,i)
    File “laser.py”, line 2867, in recursive_search
    points = self.get_orientation_points(i)
    File “laser.py”, line 2907, in get_orientation_points
    r = re.match(r'(?i)\s*\(\s*(-?\s*\d*(?:,|\.)*\d*)\s*;\s*(-?\s*\d*(?:,|\.)*\d*)\s*;\s*(-?\s*\d*(?:,|\.)*\d*)\s*\)\s*’,node.text)
    File “C:\Program Files\Inkscape\python\Lib\re.py”, line 137, in match
    return _compile(pattern, flags).match(string)
    TypeError: expected string or buffer

  4. I need your help i have the error:
    Traceback (most recent call last):
    File “laser.py”, line 3173, in
    e.affect()
    File “/usr/share/inkscape/extensions/inkex.py”, line 215, in affect
    self.effect()
    File “laser.py”, line 3157, in effect
    self.orientation( self.layers[min(0,len(self.layers)-1)] )
    File “laser.py”, line 3086, in orientation
    doc_height = self.unittouu(self.document.getroot().xpath(‘@height’, namespaces=inkex.NSS)[0])
    AttributeError: laser_gcode instance has no attribute ‘unittouu’
    at ubuntu 14.04 LTS

  5. Help
    Ubuntu 14.04
    Inkscape 0.48

    Traceback (most recent call last):
    File “boxmaker.py”, line 489, in
    effect.affect()
    File “/usr/share/inkscape/extensions/inkex.py”, line 215, in affect
    self.effect()
    File “boxmaker.py”, line 243, in effect
    widthDoc = self.unittouu(svg.get(‘width’))
    AttributeError: BoxMaker instance has no attribute ‘unittouu’

  6. Some help would be much appreciated, this is the error I get using the laser extension from Github compiler “ringok2”.
    https://github.com/ringo2k/laserengraverInkscapeplugin

    Traceback (most recent call last):
    File “laserengraver.py”, line 3211, in
    e.affect()
    File “C:\Program Files\Inkscape\share\extensions\inkex.py”, line 268, in affect
    self.effect()
    File “laserengraver.py”, line 3176, in effect
    self.orientation( self.layers[min(0,len(self.layers)-1)] )
    File “laserengraver.py”, line 3100, in orientation
    doc_height = inkex.unittouu(self.document.getroot().get(‘height’))
    AttributeError: ‘module’ object has no attribute ‘unittouu’

  7. Another extension through “FlexiLee” comes up with…
    after the original was already replaced.

    Original:

    doc_height = inkex.unittouu(self.document.getroot().get(‘height’))

    Replacement:

    doc_height = self.unittouu(self.document.getroot().xpath(‘@height’, namespaces=inkex.NSS)[0])

    Issue after replacement:

    File “laserengraver.py”, line 3082
    doc_height = self.unittouu(self.document.getroot().xpath(‘@height’, namespaces=inkex.NSS)[0])
    ^
    IndentationError: unexpected indent

    1. I followed the GitHub link in your next comment but line 3082 doesn’t seem to match. Did you make any modifications to the file? Is there a newline, double-space, or tab at that location?

      1. In this link the first locked comment had an example line about the Inkscape extention.

        http://www.instructables.com/id/Pocket-laser-engraver/step7/Getting-the-software-ready/

        Slighty Modified:

        3079 # doc height in pixels (38 mm == 134.64566px)
        3080 doc_height = self.unittouu(self.document.getroot().xpath(‘@height’, namespaces=inkex.NSS)[0])
        3081 “”” Replaced with above doc_height = inkex.unittouu(self.document.getroot().get(‘height’))”””
        3082 if self.document.getroot().get(‘height’) == “100%” :
        3083 doc_height = 1052.3622047

        Original Flexilee laserengraver code:

        3079 # doc height in pixels (38 mm == 134.64566px)
        3080 doc_height = inkex.unittouu(self.document.getroot().get(‘height’))
        3081
        3082 if self.document.getroot().get(‘height’) == “100%” :
        3083 doc_height = 1052.3622047

        1. Assuming your line numbers are correct, it doesn’t appear to be an incorrect newline. Have you ensured that you’re not mixing tabs and spaces on that line and in the file? I think Python best practices is to use spaces and never tabs, so all the leading space on that line should be in spaces not tabs (assuming all other lines are like that). And ensure there is no whitespace at the end of the line.

          Does that help?

          1. Yup, went through the margins, and sure enough I had it tabbed. Laid down some space bar and all is well.

            Thank you, very much!

Leave a Reply

Your email address will not be published. Required fields are marked *