Inkscape.org
Beyond the Basics gcode extension sytax error .
  1. #1
    inkface inkface @inkface

    Hi,  I just wanted to test the gcodetools extension and it fails at the first hurdle.

    File "gcodetools.py", line 102 def bezierslopeatt(((bx0,by0),(bx1,by1),(bx2,by2),(bx3,by3)),t): ^ SyntaxError: invalid syntax

     

    A quick search shows a few other reports of this but  did not find any solutions. Is this a python version issue or what .

     

    Thanks for any advice this tool looks like just what  I need.

     

     

  2. #2
    Martin Owens Martin Owens @doctormo🌹🧀

    This is because your operating system has defaulted to python3 and you are using an older version of Inkscape.

  3. #3
    inkface inkface @inkface
    *

    that is true:

    ls -ail `which python ` 430263 lrwxrwxrwx. 1 root root 9 Dec 15 17:19 /bin/python -> ./python3

    ls -ail /usr/bin/python2 410620 lrwxrwxrwx. 1 root root 9 Oct 21 14:13 /usr/bin/python2 -> python2.7

     

    but

    #! /usr/bin/python2 -s

     

    so having specified the interpreter to use and it points to a valid exec, why is it seeming to run under py3 .

     

    {sorry, not sure what the "code" formatting is going to do, seems odd. apparently it does not work at all. }

     

  4. #4
    inkface inkface @inkface
    *
    doctormo

    This is because your operating system has defaulted to python3

    since python 2 is officially no longer supported by the python development team since the beginning of 2020 , this does not seen a radical , bleeding edge position.

    The very first line of your tutorial says to add the command interpreter as the first line ( as is standard for any script ).

    https://wiki.inkscape.org/wiki/index.php/PythonEffectTutorial

     

    First of all create a file hello_world.py and make it executable with the Python interpreter with the well-known directive:

    #!/usr/bin/env python
    

    The gcodetools script  has a valid py2 executable in first line as shown above.

    Why is this not being used.  As I understand it, python calls a new instance of the interpreter for each process. It seems that inkscape is just calling "python" instead of the specified interpreter.

    doctormo

    you are using an older version of Inkscape.

    I am using the latest version in the distro ( fedora ).

    Your website shows this be the current release.

    https://inkscape.org/release/inkscape-0.92.4/

    Why do you say I'm using and "older" version. In what version is this resolved, where can I down load versions of the extensions which are py3 ready.

    Thanks.

     

  5. #5
    Martin Owens Martin Owens @doctormo🌹🧀

    The latest version of Inkscape is 1.0, it's currently in beta as it's having trouble being born. But it's certainly a much better release.

    You can get it to work by patching the py files so they have `python2` instead of just `python` in their bang lines.

  6. #6
    Maren Hachmann Maren Hachmann @Moini

    Or by using the extensions from the not-yet-released 0.92.5: https://gitlab.com/inkscape/inkscape/blob/0.92.x/share/extensions

    Those have been updated for Python 3, but have not undergone the radical changes that would make some of them incompatible with 0.92.x versions.

  7. #7
    inkface inkface @inkface
    *
    doctormo

    You can get it to work by patching the py files so they have `python2` instead of just `python` in their bang lines

    thanks, so why doesn't it work with /usr/bin/python2 in the bang line as  I posted above.  I'm guessing this was changed in the script bang line by the distro to take account of default python now being py3.  If this is wrong for some reason, I will open bug with the distro, but I don't see why it is not calling py2, it should work.

    Again this does not seem to work.  I reinstalled Inkscape from distro, changed bang line to  /usr/bin/env python2  and get the same errors which indicate it is not using py2 but py3.

    File "gcodetools.py", line 102 def bezierslopeatt(((bx0,by0),(bx1,by1),(bx2,by2),(bx3,by3)),t): ^ SyntaxError: invalid syntax

    [BTW what is wrong with the 'code' tags on the forum here, the above line was three lines, it gets reduced to one and it is not marked as code. ]

     

    Moini

    Or by using the extensions from the not-yet-released 0.92.5: https://gitlab.com/inkscape/inkscape/blob/0.92.x/share/extensions

    Many thanks, that is better than me finding random patch files and hoping they work and are current.

     

    since python two is now abandonned by the python team and support is ended, Inkscape really should have a realease which is py3 compatible. This all looks rather shakey. doctormo tells me I'm using an "older" version but this is the official current release.

     

     

     

     

  8. #8
    inkface inkface @inkface
    *

    I installed from the provide gitlab repository, it gets a little further, but there may still be some issues. I suspect the following error is still py3 issue. Any ideas.

     

    I'll quote the output since code tags seem broken.

     

     

    Orientation points have not been defined! A default set of orientation points has been automatically added.

    Cutting tool has not been defined! A default tool has been automatically added.

    Traceback (most recent call last):
      File "gcodetools.py", line 6751, in <module>
        gcodetools.affect()                    
      File "/usr/share/inkscape/extensions/inkex.py", line 289, in affect
        self.effect()
      File "gcodetools.py", line 6677, in effect
        self.path_to_gcode()        
      File "gcodetools.py", line 4606, in path_to_gcode
        [ self.parse_curve([subpath], layer) for subpath in csp  ]
      File "gcodetools.py", line 4606, in <listcomp>
        [ self.parse_curve([subpath], layer) for subpath in csp  ]
      File "gcodetools.py", line 3750, in parse_curve
        c += biarc(sp1,sp2,0,0) if w==None else biarc(sp1,sp2,-f(w[k][i-1]),-f(w[k][i]))
      File "gcodetools.py", line 2327, in biarc
        TS, TE = TS.unit(), TE.unit()
      File "gcodetools.py", line 1674, in unit
        if h: return self / h
    TypeError: unsupported operand type(s) for /: 'P' and 'float'

     

  9. #9
    Maren Hachmann Maren Hachmann @Moini

    Thanks, can you report that as an issue at https://inkscape.org/report , so it can be fixed before the release of Inkscape 0.92.5, please?

  10. #10
    inkface inkface @inkface
    *

    here's a bug with a couple of fixes. Could you look it over and see whether they are correct. It runs on  flat XY monochrome svg. Needs more testing but potentially fixed.

    https://gitlab.com/inkscape/inbox/issues/1589

  11. #11
    Maren Hachmann Maren Hachmann @Moini

    I won't be able to look into it personally, but I hope someone else will. It would be nice to have that working for 0.92.5.

  12. #12
    Tyler Durden Tyler Durden @TylerDurden
    inkface

    BTW what is wrong with the 'code' tags on the forum here, the above line was three lines, it gets reduced to one and it is not marked as code.

     

    To post strings, use the paragraph format dropdown menu selection "Formatted".

        <linearGradient
           inkscape:collect="always"
           xlink:href="#linearGradient1006"
           id="linearGradient1008"
           x1="91.2074356"
           y1="-210.602737"
           x2="94.4316101"
           y2="-218.888199"
           gradientUnits="userSpaceOnUse"
           gradientTransform="matrix(2.754818,0,0,2.754818,-72.454275,517.64431)" />

     

    Have a nice day.

    TD

  13. #13
    inkface inkface @inkface

    thanks for the workaround, I  bear that in mind in the furture.  maybe someone can fix the "code" tags.

  14. #14
    Oghenevwoke Gordon Oghenevwoke Gordon @vwokeg

    Thank you all for you contribution. my own issue is very similar, it is my inability to save file as gcode, even after adding gcode extension to Inkscape.

    Please, someone should kindly tell me what to do. 

    Thanks.

  15. #15
    brynn brynn @brynn

    Please start a new topic for your problem.  In that message, please tell us which extension you're using.  Also please tell us your Inkscape version and operating system.

  16. #16
    wangine wangine @wangine

    Should work like that"

    def bezierslopeatt(just_change, t):
        ((bx0, by0), (bx1, by1), (bx2, by2), (bx3, by3)) = just_change
        ax, ay, bx, by, cx, cy, x0, y0 = bezmisc.bezierparameterize(((bx0, by0), (bx1, by1), (bx2, by2), (bx3, by3)))
        dx = 3 * ax * (t ** 2) + 2 * bx * t + cx
        dy = 3 * ay * (t ** 2) + 2 * by * t + cy
        if dx == dy == 0:
            dx = 6 * ax * t + 2 * bx
            dy = 6 * ay * t + 2 * by
            if dx == dy == 0:
                dx = 6 * ax
                dy = 6 * ay
                if dx == dy == 0:
                    print_("Slope error x = %s*t^3+%s*t^2+%s*t+%s, y = %s*t^3+%s*t^2+%s*t+%s,  t = %s, dx==dy==0" % (
                        ax, bx, cx, dx, ay, by, cy, dy, t))
                    print_(((bx0, by0), (bx1, by1), (bx2, by2), (bx3, by3)))
                    dx, dy = 1, 1

        return dx, dy

Inkscape Inkscape.org Inkscape Forum Beyond the Basics gcode extension sytax error .