Access to menus from python extension

Discussion about writing code for Inkscape.
Antony.Marshall
Posts: 9
Joined: Wed May 25, 2016 1:01 pm

Access to menus from python extension

Postby Antony.Marshall » Wed May 25, 2016 1:06 pm

Hi,
I'm writing an extension and I wanted to know if it's possible to call a function from Inkscape's menu from within my python code?
So, if I've just created a text object like so:

Code: Select all

    line_style = {'font-size': str(text_height) + 'px', 'font-style':'normal', 'font-weight': 'normal',
                'fill': '#F6921E', 'font-family': 'sans-serif',
                'text-anchor': 'middle', 'text-align': 'center'}
    line_attribs = {inkex.addNS('label','inkscape'): 'Annotation',
                'style': simplestyle.formatStyle(line_style),
                'x': str(position[0]),
                'y': str((position[1] + text_height) * 1.2)}
    line = inkex.etree.SubElement(parent, inkex.addNS('text','svg'), line_attribs)


is there a way I can run the Path->Object to Path (or Shift+Ctrl+C) tool on that text?
I've had a lot of trial and error finding things I can and cannot do from inside my extension, but lack of an API means I don't even know where to begin with some things, like this.

Thanks for your help,
Antony

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

Re: Access to menus from python extension

Postby Moini » Wed May 25, 2016 9:25 pm

Hi Antony,

look into the output of

inkscape --verb-list

to see a list of all available commands that can be used from inside an extension.

Then look into an extension that actually calls one of those, by using the Inkscape commandline interface with a copy of the file that will overwrite the original file (it starts in a separate process), like https://github.com/Moini/inkscape-exten ... iplecut.py

(there may be better ways to implement this, I'm no expert on pipes etc.)
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)

Antony.Marshall
Posts: 9
Joined: Wed May 25, 2016 1:01 pm

Re: Access to menus from python extension

Postby Antony.Marshall » Mon May 30, 2016 11:26 am

Well, that seems like a really difficult way of doing things.
I've got a separate issue which may need this to solve, but may not be easily solvable anyway, I'll open a new topic about it.

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

Re: Access to menus from python extension

Postby Moini » Tue May 31, 2016 1:52 am

Yes, but it is how it is currently. They are working on implementing C++ extensions, which can do more than the python ones, even add tools.
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)

Antony.Marshall
Posts: 9
Joined: Wed May 25, 2016 1:01 pm

Re: Access to menus from python extension

Postby Antony.Marshall » Wed Jun 01, 2016 4:40 pm

Ok then.
When using the verbs to do actions from the command line, is there any way to pass any other parameters?
I can call --verb EditSelectAllInAllLayers, but what I really want it to do is EditSelectSameObjectType where the object type is a circle (i'm guessing that counts as an 'arc'?).
And can you 'chain' multiple commands together? Could I call:
inkscape --verb EditSelectAllInAllLayers --verb SelectionUnGroup --verb EditSelectSameObjectType <somehow tell it to select arcs) --verb SelectionSimplify --verb FileSave --verb FileQuit
Which would select everything, ungroup it all, then select all the arcs, and simplify them, then save the file.
Is that possible?

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

Re: Access to menus from python extension

Postby Moini » Thu Jun 02, 2016 6:44 am

Antony.Marshall wrote:Ok then.
When using the verbs to do actions from the command line, is there any way to pass any other parameters?


- No, unfortunately not. If you're using things that open a dialog, you can use your preferences.xml file (or a custom one) to pass in the parameters.

Antony.Marshall wrote:And can you 'chain' multiple commands together? Could I call:
inkscape --verb EditSelectAllInAllLayers --verb SelectionUnGroup --verb EditSelectSameObjectType <somehow tell it to select arcs) --verb SelectionSimplify --verb FileSave --verb FileQuit


- Yes. That's how Inkscape works from the command line. Also see line 65++ of the linked file above.
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”