7

is it possible to import code into Inkscape and save it as a .svg file?

i want to important this code and save it as a svg file:

<svg class="defs-only" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">

<symbol id="wave">    
<svg viewBox="0 0 100 50" preserveAspectRatio="none" >
    <g>
    <path d="M100,30 Q70,40 50,30 T0,30 v20 h100Z" 
          style="stroke-linejoin:round; stroke:#f6f6f6" stroke-width="0"/>
    </g>
</svg>
</symbol>
</svg>  
Jack Maessen
  • 1,780
  • 4
  • 19
  • 51
  • Possible duplicate of [inkscape plugin to live edit svg code](https://stackoverflow.com/questions/14542775/inkscape-plugin-to-live-edit-svg-code) – Thomas Beumer Feb 22 '18 at 14:57

2 Answers2

16

In Inkscape there's xml text editor (Edit > XML editor...) panel. There you can follow these steps:

  • Create a new element, call it: svg:path (this will create it with an id)
  • click unindent node to have it as a child from the main node (top one). You may want to keep it under a particular node too.
  • On the right hand side fill the list of attributes, by setting the name on the box next to the set button, and the value in the box below. Once you've enter the values click Set. This may seem obvious, but it took me a while to figure it out.

A picture is worth a thousand words

There's more detailed information about the xml editor on Tavmjong Bah's Guide to a vector drawing program

dvdgc13
  • 782
  • 7
  • 11
  • 1
    Out of interest, in my example I only had a "fill" attribute in the HTML SVG element code. Once I had added the "path" attribute, I found it was then straightforward to drop back to the GUI and add the fills etc. the usual way without having to compose the "style" attribute in this case. – CodingLumis Mar 18 '20 at 15:46
  • 1
    kind of confusing... maybe these steps are for a previous version. – ashleedawg May 30 '21 at 15:57
  • 2
    With Inkscape 1.1 the same applies till the last point, however, instead of getting a dialogue below the node attributes where you need to `set` the values, you can edit them directly on the node attributes section. – dvdgc13 Jun 02 '21 at 14:40
0

is it possible to import code into Inkscape and save it as a .svg file?

Currently unfortunately not by using ctrl + v. One first has to save that SVG code to a file.svg using an external text editor. Then they can open that file in Inkscape, edit, and re-save it.

But it should not be too difficult to implement a script which automates that, for example in Python, using Pyperclip or tkinter, for reading the SVG from the clipboard and subprocess for opening the saved file in Inkscape.

Nils Lindemann
  • 1,146
  • 1
  • 16
  • 26