Inkscape.org
Beginners' Questions learning to code, or has someone done this already?
  1. #1
    Jenni Jenni @pdukm21941
    *

    Hallo all, I am trying to learn the coding side of things. I ask, just in case someone has already written code for this type of task, or perhaps can tell me it is not possible...

    I work with layers that need to have specific labels and I find labeling each new layer before I start a project incredibly time consuming. Normally I cut & paste label titles from my list elsewhere, because some are long or detailed or in two languages (time and dull, but works slowly)

    Is there a way to write a script that will make different layers with their titles, which can be taken from an already written list?  Or some other solutions maybe. Many thanks in advance, Penn

  2. #2
    Kirstie Kirstie @Kirstie🌷
    *

    Hi Penn,

    I do not know this specific kind of code.
    Is there a specific reason why you shouldn't re-use your old file with all the layers and names?
    Just delete all the objects, but leave the layers where they are. Then save this file with a new name.
    ------------

    You can also save this new file with all the layers in the templates folder.
    In Windows I made a folder templates.
    The folder I created is here:
    C:\Users\Kirstie\AppData\Roaming\inkscape\templates
    I save my own templates there.

    And then I open my own template from menu > file > new from template.

  3. #3
    Jenni Jenni @pdukm21941

    Hi Kirstie, thank you for your reply😊.

    Your suggestion works for those projects with the same or similar layer-titles as a previous project, and I have already made my own templates for these instances.

    However, most of my work requires new and different layer-titles than previous works. Each layer title identifies important objects that correcpond to record-keeping in a separate database, hence me finding the new layer-naming tedious🤯. A new project may need somwhere between 10 to 30 layers.

    I was thinking, mmmmmmm there must be code that says, for example, "Add layer", "add the text to layer x"...maybe I should post this in the other forum section (???)

    Thank you again.

  4. #4
    Kirstie Kirstie @Kirstie🌷

    Hi Penn,

    So yes.. that looks like advanced using of Inkscape, you could post this in the Beyond the basics.
    As an svg file is text-based, it should be possible to write something to connect your data to svg tags and labels.

    I do not write code -although my brother who taught me a lot about computers, would like me to, because it is sooo handy...

  5. #5
    brynn brynn @brynn

    Welcome to the forum!

    I don't know how to write scripts, but I've heard of people scripting things with Inkscape.  And I've heard of it both with and without using Inkscape from the command line (which I don't understand the commandline much either).  You can find info about the commandline in the manual, I guess (Inkscape Help menu).  And there's a reference guide here:  https://inkscape.org/en/doc/inkscape-man.html

    I guess it should also be possible to write an extension for naming a bunch of layers (and yes, equally over my head).  And there's a guide for getting started with extensions too.  https://inkscape.org/develop/extensions/

    Beyond that, I can't really say which would be your best option.  But after you've looked into those things, you'll probably have a better idea what you want to try.

    Hhmm....existing extensions....  I believe there are a couple here and there about layers in general....not creating them, but....  Let's see if I can find.  Ok, so I don't think these are close to what you want.  But because they are about layers, they might be useful for you to study, if you decide to try writing your own extension.

    We could move this to the Creating Extensions board, if you decide that an extension would be your best option.  But you might already know some scripting language, that you don't have to learn first, which would do what you want?  So weigh the options, and let us know.  Also, someone else might have even better ideas for you.  So give it another day or 2, and see what happens.

  6. #6
    Maren Hachmann Maren Hachmann @Moini

    I'm not sure this even requires an extension for it. I think I would make a plain Python or shell script that loads stuff from a CSV file, or even just a file with a layer name per line, and inserts a group for each into the SVG file.

Inkscape Inkscape.org Inkscape Forum Beginners' Questions learning to code, or has someone done this already?