Combining operations into extension (aka macros)

Flesh out your ideas for new or improved Inkscape features before submitting a request.
sygi
Posts: 5
Joined: Mon Nov 26, 2018 4:53 am

Combining operations into extension (aka macros)

Postby sygi » Mon Nov 26, 2018 5:23 am

I was looking to implement an extension for adding a kerf for laser cutting. To do that, I needed to perform a couple of existing operations (StrokeToPath, Union, BreakApart, Union) into a single extension.

I was looking how to do this using current extensions / operations, but didn't find anything.
I implemented it similarly to how synfig_prepare.py is implemented: the extension calls inkscape from command line in a subprocess and reads the resulting file. I find it a bit ugly, as:
a) there's probably an overhead for starting a separate inkscape process
b) as it uses --verb it opens inkscape's gui (https://bugs.launchpad.net/inkscape/+bug/843260), which gives further overhead and a weird blinking of the screen
c) live preview doesn't work

1. Is there any way to easily combine inkscape operations into a single one to avoid repetitiously clicking same sequence of operations that I didn't find?
2. If there isn't, would you be interested in factoring out the code that I wrote into a inkscape-supported extension? If the user was to give the --verb names of the operations as the input to the extension, I would be able to extract it without much thinking.
Ideally, one would have the user to click the operations in the sequence and the extension would grab their names and save them to the form, but I'm not sure either how to get the operations' names nor if it's possible for the extension to wait for the user interaction with the GUI.

Thank you!

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

Re: Combining operations into extension (aka macros)

Postby Moini » Mon Nov 26, 2018 10:55 am

1. Yes, you're asking for the --shell option, see inkscape --help.

Devs only recently discussed removing it, but I'm glad I could convince them of not doing so.

Be aware that for the next Inkscape version, the whole extension interface and also the command line arguments are going to change.

2. I'm not sure who or what you're asking, maybe it's too late tonight. If you're looking for an Inkscape developer, this is the wrong place. If you want to follow up on how the extensions interface develops, check out https://gitlab.com/inkscape/extensions , and if you want to follow the command line changes, see http://wiki.inkscape.org/wiki/index.php ... mmand_Line . If you want to talk to devs, try the developer mailing list.

Extensions cannot determine what a user has clicked on. Waiting would be possible, if the extension provides a GUI via tkinter. Inkscape might get a python console, though: https://gitlab.com/inkscape/inkscape/merge_requests/417
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)

sygi
Posts: 5
Joined: Mon Nov 26, 2018 4:53 am

Re: Combining operations into extension (aka macros)

Postby sygi » Tue Nov 27, 2018 3:03 am

Thank you for your answers. I think I didn't express myself clearly enough. What I'd like to be able to do is:
a. open inkscape in the GUI version
b. select some objects
c. perform a sequence of operations on them (e.g. change the color to red, change the width of the line to 0.5mm, Union)
b2. select some new objects
c2. perform the same sequence of opeartions on the new objects.

As far as I understand, one could achieve similar results using --shell/commandline if you know the ids of the objects user selected. Switching from GUI to commandline is not super convenient though, so I wrote an extension which does exactly that (takes selected items and runs some fixed verbs in commandline). This solution seem a little bit hacky though, so I was thinking whether there's a better way (without creating extra processes and calling things (implicitly) through commandline).

2. I wanted to get an opinion if such extension is of interest to inkscape users (if so, I could send a pull request to inkscape). I assume that as the api for extensions is planned to change, it's better to wait for the changes and propose it afterwards.

Thank you for the python console work, it seems relevant to the question (and very useful).

User avatar
brynn
Posts: 10309
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA
Contact:

Re: Combining operations into extension (aka macros)

Postby brynn » Tue Nov 27, 2018 9:28 am

I can't follow much of these messages, but I do know what kerf is, and I remembered seeing this extension: https://github.com/braingram/inkscape_kerf_correction

I've never used it, and don't know if it even works. But might be helpful to see how the author approaches the same problems? Or maybe you could collaborate, or fork it, (depending on the license) or whatever?

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

Re: Combining operations into extension (aka macros)

Postby Moini » Tue Nov 27, 2018 12:09 pm

Yes, steps c and c2 are typical extension tasks. I think what you are thinking of doing would be to allow users to pass command line parameters via extension, to have the most flexibility?

But I guess the python scripting console would be flexible enough for this, too. But it would all need access to 'actions', either by calling Inkscape as an extra process, as it's currently required, so you can use the command line interface, or by some magical python binding that provides the access internally. There are discussions going on about that type of Python binding on the developer mailing list currently.

Can you also post a (short) description of what your script would be doing here:
viewtopic.php?f=22&t=34223 ? I think the developer is mostly interested in the types of action sequences that users use or want to use.
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 “Inkscape Ideas”