Author Topic: Loading extensions from custom directory  (Read 1784 times)

March 18, 2018, 12:17:15 PM
Read 1784 times

Eneroth3

  • Sr. Newbie

  • Offline
  • **

  • 6
Hello

I've used Inkscape scarcely for several years and have just made my first extensions. This is the first code I ever write in Python so forgive me if this is a very basic question.

I have written the plugin code directly in the extension folder in appdata, where Inkscape loads extensions from. I'd like to develop my code in another location, with all extensions in their own directory so I can use GIT, but still want it to be loaded directly into Inkscape so I can test it while I am coding. In SketchUp, which uses Ruby, I can place the following file in the program's plugin folder to achieve this goal.

    pattern = "D:/Sketchup Plugins/Working Dir/*/src/"

    Dir.glob(pattern).each do |dir|
      $LOAD_PATH << dir
      Dir.glob("#{dir}/*.rb").each { |p| require p }
    end


What would the corresponding code in Python be?
  • 0.9.1
  • Win 7

March 18, 2018, 02:06:25 PM
Reply #1

Moini

  • IC Mentor

  • Offline
  • ******

  • 1,568
    • VektorRascheln
1. Are you still using Inkscape 0.91, as it says in your signature? If so, please update before writing any extensions, or you may run against some walls later. Inkscape 0.92.3 will be released within the next couple of days.

2. The correct folder to put user-generated extensions into can be looked up in Inkscape: Edit > Preferences > System: User extensions.

3. Move your extensions out of the other folder before you uninstall Inkscape for installing the new Inkscape version, else they will probably be deleted.

4. Put them into a separate folder somewhere on your hard disk where you want to have your git repositories.

5. Use symlinks that you put into the folder mentioned in 2) for the .py and the .inx file.

6. Sorry, can't help with Ruby -> Python.

7. You could also use Ruby for your Inkscape extensions. This means, though, that you cannot use the functionality provided by inkex.py, but must create your own equivalent to it.

March 18, 2018, 02:58:56 PM
Reply #2

Eneroth3

  • Sr. Newbie

  • Offline
  • **

  • 6
1. So far I am but I'll keep my eyes on the new release.

Regarding the other points my goal is not load extensions from a path with a wildcard in it. I'm on Windows and don't have symlinks, and even if I had it would be a bit tedious to manually link every file separately. What I want to do is loading files from "D:/Source/InkscapeExtensions/*/" where * is the project name for each individual extension, just as if the files were all placed in an extension directory.
  • 0.9.1
  • Win 7

March 19, 2018, 11:25:39 AM
Reply #3

Moini

  • IC Mentor

  • Offline
  • ******

  • 1,568
    • VektorRascheln
Inkscape will not look into subdirectories. Either use a symlink (Windows does support them: https://www.howtogeek.com/howto/16226/complete-guide-to-symbolic-links-symlinks-on-windows-or-linux/) or copy everything into your user extensions directory.

Hint: symlinks could potentially also be created automatically with a script.

March 20, 2018, 03:27:52 PM
Reply #4

Eneroth3

  • Sr. Newbie

  • Offline
  • **

  • 6
I didn't know Windows supported symlinks :O . You learn something new every day! Link Shell Extension did the trick. For now I'm just creating the links manually, but if I develop more Inkscape extensions (this one was just to help in another project I'm working on) I'll consider scripting it.

The project is hosted on GitHub if anyone is interested: https://github.com/Eneroth3/inkscape-purge-short-lines

Thanks for the help!
  • 0.9.1
  • Win 7

March 21, 2018, 06:08:25 AM
Reply #5

Moini

  • IC Mentor

  • Offline
  • ******

  • 1,568
    • VektorRascheln
Lol, yeah, with me being a Linux-only user since 2004, it may seem surprising that I know about it - but it was kind of a joke, to the Linux world, when we learned that Windows finally supports symlinks and even - gasp - multiple desktops! So that stuck ;-)

Glad it works :)

If you're interested in sharing your extensions with a wider audience, you can also put them up at inkscape.org, to end up in the Extensions gallery:
https://inkscape.org/en/gallery/=extension/

Instructions available at https://inkscape.org/en/develop/extensions/#sharing-your-extension

April 08, 2018, 03:36:05 AM
Reply #6

Eneroth3

  • Sr. Newbie

  • Offline
  • **

  • 6
I have now added the extension to Inkscape.org, after trying it in the new Inkscape version: https://inkscape.org/en/~eneroth3/%E2%98%85purge-short-lines

Thanks again for the help!
  • 0.9.1
  • Win 7

April 08, 2018, 05:30:25 AM
Reply #7

Moini

  • IC Mentor

  • Offline
  • ******

  • 1,568
    • VektorRascheln
Cool :-D Thank you, I think this is a really good addition to the extensions available on the site!