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!
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
Worked great, thanks!
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.
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.
# Use numeric value
oc_height = 3200
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
My engraver is in storage for a few months, so I can’t be much help right now. Sorry!
Did you ever get this issue fixed?
I love you a lot.
This was the perfect fix. Thank you so much!
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
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’
Tanks
I update Inkscape for 0.91
Many thanks, problem solved 🙂
Thank you, you save my day!
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’
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
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?
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
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?
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!
Link for post up above.
https://github.com/FlexiLee/laserengraver
It’ll be good to remember that “tab” rule.
File “laserengraver.py”, line 3080
doc_height = self.unittouu(self.document.getroot().xpath(‘@height’, namespaces=inkex.NSS)[0])
^
IndentationError: unindent does not match any outer indentation level
Hi devin, thanks for the comment.
Whitespace is meaningful in Python, meaning that in Python the whitespace confers code structure. Be sure to consistently use either tabs or spaces depending on what the rest of the file uses, and that the level of indentation matches the surrounding lines.
So if the rest of the file is using tabs, be sure that line is indented with tabs the same amount as the surrounding lines.
Hope this helps.
thanks a ton – for the fix. It works great…!
Im having a problem saving the gcode file using the MI GRBL Z AXIS Servo Controller. I try to create the external file… it fails with this message.
File “servo.py”, line 3087
doc_height = 1052.3622047
^
IndentationError: unexpected indent
Hi Ric, thanks for the comment.
This is basically the same problem devin ran into. Something happened when that file was saved for you and the whitespace on that line got messed up. Whitespace is meaningful in Python, meaning that in Python the whitespace conveys code structure.
Open the file in a text editor and see if the surrounding lines (before and after 3087) use tabs or individual spaces. Then make sure 3087 uses the same, and make sure it’s indented to the right level (that is, the same amount of white-space as the surrounding lines).
Hope this helps.
works for me in inkscape 0.92
thank you!!!!