extension: save as SVG

Discussion about writing code for Inkscape.
caseygadd
Posts: 4
Joined: Thu Mar 15, 2018 2:33 pm

extension: save as SVG

Postby caseygadd » Thu Mar 15, 2018 2:39 pm

I am trying to write an extension that will save the selected as an SVG. I have been trying to find an example of scripting a "save as" call. I have had little luck. does anyone have an example of doing a save as svg with python?

User avatar
prkos
Posts: 1625
Joined: Tue Nov 06, 2007 8:45 am
Location: Croatia

Re: extension: save as SVG

Postby prkos » Fri Mar 16, 2018 2:49 am

There is some documentation on the website, and you can email the developers mailing list or come chat on IRC for help. Forum users aren't usually developers so I don't know har far you can get here with this.
just hand over the chocolate and nobody gets hurt

Inkscape Manual on Floss
Inkscape FAQ
very comprehensive Inkscape guide
Inkscape 0.48 Illustrator's Cookbook - 109 recipes to learn and explore Inkscape - with SVG examples to download

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: extension: save as SVG

Postby Moini » Fri Mar 16, 2018 4:42 am

You can export to plain SVG ( -l, --export-plain-svg=FILENAME, see https://inkscape.org/en/doc/inkscape-man.html), or use the development version that supports saving as Inkscape SVG also (see http://wiki.inkscape.org/wiki/index.php ... mmand_Line).
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: extension: save as SVG

Postby Moini » Fri Mar 16, 2018 4:43 am

Or you can use Xverbs in current Inkscape: http://wiki.inkscape.org/wiki/index.php/Using_xverbs
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

caseygadd
Posts: 4
Joined: Thu Mar 15, 2018 2:33 pm

Re: extension: save as SVG

Postby caseygadd » Fri Mar 16, 2018 5:48 am

I want to do the save while the file is open. is that possible with xverb? I thought it was a command line utility. this is what I have so far but it does not create a working svg file.

Code: Select all

#! /usr/bin/env python
# -*- coding: utf-8 -*-

import inkex       # Required

class MyExtensionName(inkex.Effect):
    def __init__(self):
        inkex.Effect.__init__(self)
        self.OptionParser.add_option('-x', '--something', action='store', type='string', dest='optionName',
                                     default='defaultvalue', help='Helper text for this option')

    def effect(self):
        option = self.options.optionName
        self._main_function(option)

    def _main_function(self, option):
      svg = self.document.getroot()
      f=open("C:\Users\casey\export.svg","w+")
      f.write(str(svg))

if __name__ == '__main__':
    MyExtension = MyExtensionName()
    MyExtension.affect()

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: extension: save as SVG

Postby Moini » Fri Mar 16, 2018 11:57 pm

Via extensions, it's possible to call a second Inkscape instance that works on the open file. You can do anything with it that you can do with Inkscape command line.

See for example https://gitlab.com/su-v/inx-pathops/blo ... ps.py#L178 .
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)


Return to “Programming”