Inkscape.org
Creating New Extensions Updating the Generator extension for Inkscape 1.0/Python 3
  1. #1
    jgalak jgalak @jgalak

    Greetings!  I've been using Inkscape for a while, but this is my first foray into extensions.  Looking to automate some tasks, I found the Generator extension here: https://github.com/galou/inkscape_generator (which appears to be an update of an earlier extension found here: http://wiki.colivre.net/Aurium/InkscapeGenerator).  Unfortunately, it doesn't seem to be working with Inkscape 1.0/Pyton 3 - not surprising since it looks like it's not been updated since 2015. 

    I tried to update it myself, as much as I could, by following the update guide and the error messages.  In its current form, my generator.py file looks like this: https://pastebin.com/h4bXpaKi

    Unfortunately, it keeps throwing an error that I can't figure out:
     

    Traceback (most recent call last):
      File "generator.py", line 320, in <module>
        e = Generator()
      File "generator.py", line 82, in __init__
        self.arg_parser.add_argument('-o', '--output',
      File "C:\Program Files\Inkscape\lib\python3.8\argparse.py", line 1386, in add_argument
        return self._add_action(action)
      File "C:\Program Files\Inkscape\lib\python3.8\argparse.py", line 1749, in _add_action
        self._optionals._add_action(action)
      File "C:\Program Files\Inkscape\lib\python3.8\argparse.py", line 1590, in _add_action
        action = super(_ArgumentGroup, self)._add_action(action)
      File "C:\Program Files\Inkscape\lib\python3.8\argparse.py", line 1400, in _add_action
        self._check_conflict(action)
      File "C:\Program Files\Inkscape\lib\python3.8\argparse.py", line 1539, in _check_conflict
        conflict_handler(action, confl_optionals)
      File "C:\Program Files\Inkscape\lib\python3.8\argparse.py", line 1548, in _handle_conflict_error
        raise ArgumentError(action, message % conflict_string)
    argparse.ArgumentError: argument -o/--output: conflicting option string: --output
    

    It may be something really simple, but I'm not really familiar with the Inkscape extension API, and not really a Python expert, either.  It's clear the argument is conflicting with something, but I can't figure out what....

    Any help would be appreciated, as I'd really like to get this extension working.

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

    Your code is a bit old fashioned, it can be updated with the new internal inkex.GenerateExtension which should do a lot of the heavy lifting for you.

    I wish we had more documentation though.

  3. #3
    Juliean Galak Juliean Galak @jgalakc30cc7bb942d44cf

    It's not my code.  Found the abandoned extension, hoping to make it work.

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

    Don't worry, if it's open source, then it's your code 😅

    If you make it work, let us know.

  5. #5
    chinnam chan chinnam chan @chancn88

    would like to know how this generator read the csv file

  6. #6
    inklinea inklinea @inklinea⛰️

    I tried the original version :

    http://wiki.colivre.net/Aurium/InkscapeGenerator

    a few days ago on Lubuntu 20.04 / Inkscape 1.0.1

    https://inkscape.org/forums/beyond/merge-data-csvexcel-file/

    Seems to work ?

     

     

  7. #7
    jgalak jgalak @jgalak

    I'm on 1.0 (4035a4fb49, 2020-05-01) on Windows, neither the original nor update worked.  Will try to update Inkscape and try again, though I think the problem, at least in part, is Python 2 vs. 3.  Do you have both installed on your system?  I only have Python 3 installed, which I believe Inkscape 1.x uses, and the errors I got when running both versions as published looked like version errors between 2 and 3.

  8. #8
    jgalak jgalak @jgalak
    *

    Updated to 1.0.1, downloaded the extension directly from Aurium, got this error:

    ETA: Tried both by column position and by column name, same error.

     

    Traceback (most recent call last):
      File "generator.py", line 320, in <module>
        e = Generator()
      File "generator.py", line 82, in __init__
        self.arg_parser.add_argument('-o', '--output',
      File "C:\Program Files\Inkscape\lib\python3.8\argparse.py", line 1386, in add_argument
        return self._add_action(action)
      File "C:\Program Files\Inkscape\lib\python3.8\argparse.py", line 1749, in _add_action
        self._optionals._add_action(action)
      File "C:\Program Files\Inkscape\lib\python3.8\argparse.py", line 1590, in _add_action
        action = super(_ArgumentGroup, self)._add_action(action)
      File "C:\Program Files\Inkscape\lib\python3.8\argparse.py", line 1400, in _add_action
        self._check_conflict(action)
      File "C:\Program Files\Inkscape\lib\python3.8\argparse.py", line 1539, in _check_conflict
        conflict_handler(action, confl_optionals)
      File "C:\Program Files\Inkscape\lib\python3.8\argparse.py", line 1548, in _handle_conflict_error
        raise ArgumentError(action, message % conflict_string)
    argparse.ArgumentError: argument -o/--output: conflicting option string: --output

     

    ETA: I

  9. #9
    inklinea inklinea @inklinea⛰️

    It seems that the Linux version I was using, does not use Python at all.

    It's a .sh shell script and a inkscape .inx file.

    I too was unable to get the python version from github working on windows.

    Traceback (most recent call last):
      File "generator.py", line 47, in <module>
        import StringIO
    ModuleNotFoundError: No module named 'StringIO'

  10. #10
    jgalak jgalak @jgalak

    Well crud.  I don't think I have any Linux installs right now that gave guis enabled - they are all CLI only headless machines.  Hmm, wonder if it'd work under WSL....

     

  11. #11
    jgalak jgalak @jgalak
    *

    [EDIT] Never mind.  The problem was the .csv file was saved with Windows carriage returns.   running it through dos2unix fixed the problem

     

     

    So I installed Ubuntu under WSL, and got the sh version of the extension to work... mostly.

    It's rendering the files correctly, but it's mangling the output file names.

    For example, the data file is just a column of numbers, and I currently have the output pattern set as: `$HOME/output/%VAR_1%`, which should just get me something like `135.png`.  Instead, it's inserting a bunch of extra characters, so instead, on the linux side, I get `'100'$'\r''.png`  Complete with single quotes.  When I copy the files to Windows, it renders some of that as unprintable and some programs refuse to open the file (though Windows itself does fine).  I don't know shell scripts (or the embedded sed commands) well enough to diagnose it...

Inkscape Inkscape.org Inkscape Forum Creating New Extensions Updating the Generator extension for Inkscape 1.0/Python 3