Accessing built-in functionality from an extension?

Discussion about writing code for Inkscape.
gmaker
Posts: 2
Joined: Tue Sep 18, 2012 11:39 pm

Accessing built-in functionality from an extension?

Postby gmaker » Wed Sep 19, 2012 12:02 am

First post!

I need to write an extension that will perform the following operations on the selected objects:

(1) take a length as a parameter

(2) for each selected object
(3) Object to Path
(4) Set fill color to none (transparent) and stroke color to black
(5) Set stroke width to the passed parameter
(6) Stroke to Path
(7) Break Apart
(8) Set stroke size to 0.001in ("hairline")

(and some more stuff that I know how to do from an extension)

Steps labeled (3) through (8) I know how to do from menus, but I haven't been able to find how to do backcalls into inkscape from my python code in the extension. It would be really silly to have to re-implement the functionality in python on my own when the code is just sitting in the binary. I suppose I could execute inkscape several times *from* the python script, passing it command-line arguments and temporary files, but there *has* to be a better way, such a callback API, or SWIGed functions, or something.

(What I'm trying to do is have a design that I want to cut on a laser cutter for both figure and ground in contrasting colors, and automatically adjust for kerf).

Help?

Thanks


-

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Accessing built-in functionality from an extension?

Postby ~suv » Wed Sep 19, 2012 5:03 am

gmaker wrote:(…) I haven't been able to find how to do backcalls into inkscape from my python code in the extension.
There is no way for script-based extensions to access Inkscape's internal functions (the current extension system was not designed this way).

Inkscape 0.48: Take a look at the extensions which ship with Inkscape - some do call inkscape from the command line for certain operations (Restack, Dimensions, …). There are also several python modules shipping with Inkscape which provide various helper and utility functions for handling paths, transforms and CSS styles in python-based extension scripts.

Roadmap/trunk: The next major release (0.49) will likely include the new dbus-based scripting API (GSoC project from 2009) which will allow access to internal functions and all verbs.

v1nce
Posts: 696
Joined: Wed Jan 13, 2010 4:36 am

Re: Accessing built-in functionality from an extension?

Postby v1nce » Wed Sep 19, 2012 7:08 am

~suv wrote:
gmaker wrote:(…) I haven't been able to find how to do backcalls into inkscape from my python code in the extension.
There is no way for script-based extensions to access Inkscape's internal functions (the current extension system was not designed this way).


I suppose the same answer applies to viewtopic.php?f=34&t=12756 ?

gmaker
Posts: 2
Joined: Tue Sep 18, 2012 11:39 pm

Re: Accessing built-in functionality from an extension?

Postby gmaker » Thu Sep 20, 2012 5:17 am

Thanks. I ended up executing inkscape several times from my python script (which is fine). However, because of because of https://bugs.launchpad.net/inkscape/+bug/843260 each invocation takes a while and opens transient windows.

It's still better than doing things by hand!


Return to “Programming”