Git Product home page Git Product logo

Comments (7)

haschdl avatar haschdl commented on August 15, 2024

hello @abey79 I found this issue while trying to find a way to run basic vpype commands from Inkspace.
It shouldn't be too hard, but if possible, I wish I wouldn't start from scratch. Have you given the idea a try?

from vpype.

abey79 avatar abey79 commented on August 15, 2024

@haschdl no I haven't.

I did recently add an API function wrapper to vpype's core that would come in handy: https://vpype.readthedocs.io/en/stable/api/vpype_cli.html#vpype_cli.execute

The way I think things should be going is as follows:

import vpype as vp
from vpype_cli import execute

doc = vp.Document()
doc.add(....)  # populate document with Inkscape vectors

doc = vp.execute("linesort linemerge linesimplify", doc)  # pipeline should come from UI

for layer_id in doc:
    for line in doc[layer_id]:
        ... # put line back into inkscape

The main complexity is that vpype accepts only polylines, so all curved elements will have to be sampled (ideally with a selectable accuracy). In vpype, this is actually done in svgelements, a project to which I contributed parallelised discretisation functions (these are in the various shapes' npoint() methods, eg QuadraticBezier.npoint().

If you want to give this a shot, I'll happily make myself available if you have questions or need help. If you haven't already, I suggest joining the drawingbots.net's discord server.

from vpype.

haschdl avatar haschdl commented on August 15, 2024

It might be relevant to mention that I only use a limited set of vpype’s features, namely the optimization and layouting features. I do not use the drawing features. Most of the time, I generate my SVG in Processing, and sometimes do clean-ups in Illustrator, in Inkscape or using vpype. Axidraw plot optimization has let me down many times, so I want to incorporate vpype to my workflow.

With that said, l just put together some spaghetti code in which I experimented with a Inkscape extension calling vpype client - I wasn’t aware of the API! it’s basically and xml describing the extension, and an accompanying bash script to call vpype.

Calling the cli worked after a few attempts. It was a simple use case calling linesort, and it worked!
The extension framework for Inkscape works so that it passes a path to a temp file to the extension.

With this in mind, do you still think the API via Python should the way to go? It sounds more robust and testable! Could the API simply handle the input as a file, in similar way as the client? I didn’t get why I would need to create a vp.Document

Inkscape runs your script (optionally with an interpreter, more info here: Extension Interpreters), passing it any number of parameters in long GNU style. The final argument is the name of the temporary SVG file your script should read. After processing, the script should return the modified SVG file to Inkscape on STDOUT.

from vpype.

abey79 avatar abey79 commented on August 15, 2024

It might be relevant to mention that I only use a limited set of vpype’s features, namely the optimization and layouting features. I do not use the drawing features

Do you plan to have a detailed GUI or just a text field where the user would type commands? A mix of both would make it easy to run the usual optimisation commands (your use case sounds rather typical) and a text field would enable more specific scenarios.

The extension framework for Inkscape works so that it passes a path to a temp file to the extension. With this in mind, do you still think the API via Python should the way to go? It sounds more robust and testable! Could the API simply handle the input as a file, in similar way as the client? I didn’t get why I would need to create a vp.Document.

I didn't know that Inkscape API worked that way. It sounds rather inefficient to me be it certainly makes our life easier. For the execute() API, you have two choices that are nearly 100% equivalent:

# option A
doc = vp.read_multilayer_svg(temp_file_path, quantization=0.1)
doc = vp.execute("linemerge ...", doc)

# option B
doc = vp.execute(f"read {temp_file_path} linemerge ...")

Full docs for both approaches:
https://vpype.readthedocs.io/en/stable/api/vpype.html#vpype.read_multilayer_svg
https://vpype.readthedocs.io/en/stable/reference.html#read

from vpype.

haschdl avatar haschdl commented on August 15, 2024

from vpype.

abey79 avatar abey79 commented on August 15, 2024

I will share something here once I’m have a working example!

Nice. I can't recommend enough joining the discord server I mentioned. I know there are plenty of people would will be interested in this.

from vpype.

vmario89 avatar vmario89 commented on August 15, 2024

Hey there,
i did my best coding last days to implement vpype into InkScape. It's not complete but a lot of things are already working. Happy to get your feedback and maybe some more code :-)

code: https://gitea.fablabchemnitz.de/MarioVoigt/mightyscape-1.X/src/branch/master/extensions/fablabchemnitz/vpypetools
docs: https://stadtfabrikanten.org/display/IFM/vpypetools and sub-pages

regards, Mario

from vpype.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.