Setting document units in Python doesn't stick

Discussion about writing code for Inkscape.
kiwimew
Posts: 1
Joined: Thu Jun 06, 2013 6:55 am

Setting document units in Python doesn't stick

Postby kiwimew » Fri Nov 22, 2013 6:22 am

I'm working on a Python Inkscape Extension. I would like to set the document's units to, for example, 'mm' rather than 'px', based on the extension settings (and yes, I know about share\templates\default.svg)
This code fragment

Code: Select all

        namedView = self.document.getroot().find(inkex.addNS('namedview', 'sodipodi'))
        if namedView is not None:
          documentUnits = inkex.addNS('document-units', 'inkscape')
          print  >> sys.stderr, namedView.get(documentUnits)
          namedView.set(documentUnits, "mm")
          print  >> sys.stderr, namedView.get(documentUnits)

prints
px
mm
when run. But, Shift-F6 still reports in 'px' and, if I then save the file, I see inkscape:document-units="px" under sodipodi:namedview in the XML.
So my code seems to be changing the units, but the change doesn't stick. Any ideas? Thanks!

Return to “Programming”